Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1283278

Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry

From Johannes Weiner <hannes@cmpxchg.org>
Newsgroups linux.kernel
Subject Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry
Date 2015-12-03 20:30 +0100
Message-ID <qBHJM-QO-21@gated-at.bofh.it> (permalink)
References <qBCTN-6fn-13@gated-at.bofh.it> <qBEVA-7vN-15@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, Dec 03, 2015 at 05:27:18PM +0100, Michal Hocko wrote:
> On Thu 03-12-15 22:16:55, Geliang Tang wrote:
> > To make the intention clearer, use list_{first,next}_entry instead
> > of list_entry.
> 
> Does this really help readability? This function simply uncharges the
> given list of pages. Why cannot we simply use list_for_each_entry
> instead...

You asked the same thing when reviewing the patch for the first
time. :-) I think it's time to add a comment.

From e8ba3f31bb43ed4091b997b6ee8857dc8bbcd349 Mon Sep 17 00:00:00 2001
From: Johannes Weiner <hannes@cmpxchg.org>
Date: Thu, 3 Dec 2015 14:21:45 -0500
Subject: [PATCH] mm: memcontrol: clarify the uncharge_list() loop

uncharge_list() does an unusual list walk because the function can
take regular lists with dedicated list_heads as well as singleton
lists where a single page is passed via its page->lru list node.

This can sometimes lead to confusion, as well as suggestions to
replace the loop with a list_for_each_entry(), which wouldn't work.

Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---
 mm/memcontrol.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 9acfb16..f7ee1c0 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5422,6 +5422,10 @@ static void uncharge_list(struct list_head *page_list)
 	struct list_head *next;
 	struct page *page;
 
+	/*
+	 * Note that the list can be a single page->lru; hence the
+	 * do-while loop instead of a simple list_for_each_entry().
+	 */
 	next = page_list->next;
 	do {
 		unsigned int nr_pages = 1;
-- 
2.6.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] mm/memcontrol.c: use list_{first,next}_entry Geliang Tang <geliangtang@163.com> - 2015-12-03 15:20 +0100
  Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry Michal Hocko <mhocko@kernel.org> - 2015-12-03 17:30 +0100
    Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry Johannes Weiner <hannes@cmpxchg.org> - 2015-12-03 20:30 +0100
      Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry Michal Hocko <mhocko@kernel.org> - 2015-12-04 09:50 +0100
    Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry Geliang Tang <geliangtang@163.com> - 2015-12-05 04:00 +0100
      Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry Johannes Weiner <hannes@cmpxchg.org> - 2015-12-05 17:30 +0100
      Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry Michal Hocko <mhocko@kernel.org> - 2015-12-07 17:30 +0100

csiph-web