All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/memcontrol.c: use list_{first,next}_entry
@ 2015-12-03 14:16 ` Geliang Tang
  0 siblings, 0 replies; 18+ messages in thread
From: Geliang Tang @ 2015-12-03 14:16 UTC (permalink / raw)
  To: Johannes Weiner, Michal Hocko
  Cc: Geliang Tang, cgroups, linux-mm, linux-kernel

To make the intention clearer, use list_{first,next}_entry instead
of list_entry.

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 mm/memcontrol.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 79a29d5..a6301ea 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5395,16 +5395,12 @@ static void uncharge_list(struct list_head *page_list)
 	unsigned long nr_file = 0;
 	unsigned long nr_huge = 0;
 	unsigned long pgpgout = 0;
-	struct list_head *next;
 	struct page *page;
 
-	next = page_list->next;
+	page = list_first_entry(page_list, struct page, lru);
 	do {
 		unsigned int nr_pages = 1;
 
-		page = list_entry(next, struct page, lru);
-		next = page->lru.next;
-
 		VM_BUG_ON_PAGE(PageLRU(page), page);
 		VM_BUG_ON_PAGE(page_count(page), page);
 
@@ -5440,7 +5436,8 @@ static void uncharge_list(struct list_head *page_list)
 		page->mem_cgroup = NULL;
 
 		pgpgout++;
-	} while (next != page_list);
+	} while (!list_is_last(&page->lru, page_list) &&
+		 (page = list_next_entry(page, lru)));
 
 	if (memcg)
 		uncharge_batch(memcg, pgpgout, nr_anon, nr_file,
-- 
2.5.0



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH] mm/memcontrol.c: use list_{first,next}_entry
@ 2015-12-03 14:16 ` Geliang Tang
  0 siblings, 0 replies; 18+ messages in thread
From: Geliang Tang @ 2015-12-03 14:16 UTC (permalink / raw)
  To: Johannes Weiner, Michal Hocko
  Cc: Geliang Tang, cgroups, linux-mm, linux-kernel

To make the intention clearer, use list_{first,next}_entry instead
of list_entry.

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 mm/memcontrol.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 79a29d5..a6301ea 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5395,16 +5395,12 @@ static void uncharge_list(struct list_head *page_list)
 	unsigned long nr_file = 0;
 	unsigned long nr_huge = 0;
 	unsigned long pgpgout = 0;
-	struct list_head *next;
 	struct page *page;
 
-	next = page_list->next;
+	page = list_first_entry(page_list, struct page, lru);
 	do {
 		unsigned int nr_pages = 1;
 
-		page = list_entry(next, struct page, lru);
-		next = page->lru.next;
-
 		VM_BUG_ON_PAGE(PageLRU(page), page);
 		VM_BUG_ON_PAGE(page_count(page), page);
 
@@ -5440,7 +5436,8 @@ static void uncharge_list(struct list_head *page_list)
 		page->mem_cgroup = NULL;
 
 		pgpgout++;
-	} while (next != page_list);
+	} while (!list_is_last(&page->lru, page_list) &&
+		 (page = list_next_entry(page, lru)));
 
 	if (memcg)
 		uncharge_batch(memcg, pgpgout, nr_anon, nr_file,
-- 
2.5.0


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH] mm/memcontrol.c: use list_{first,next}_entry
@ 2015-12-03 14:16 ` Geliang Tang
  0 siblings, 0 replies; 18+ messages in thread
From: Geliang Tang @ 2015-12-03 14:16 UTC (permalink / raw)
  To: Johannes Weiner, Michal Hocko
  Cc: Geliang Tang, cgroups-u79uwXL29TY76Z2rM5mHXA,
	linux-mm-Bw31MaZKKs3YtjvyW6yDsg,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

To make the intention clearer, use list_{first,next}_entry instead
of list_entry.

Signed-off-by: Geliang Tang <geliangtang-9Onoh4P/yGk@public.gmane.org>
---
 mm/memcontrol.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 79a29d5..a6301ea 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5395,16 +5395,12 @@ static void uncharge_list(struct list_head *page_list)
 	unsigned long nr_file = 0;
 	unsigned long nr_huge = 0;
 	unsigned long pgpgout = 0;
-	struct list_head *next;
 	struct page *page;
 
-	next = page_list->next;
+	page = list_first_entry(page_list, struct page, lru);
 	do {
 		unsigned int nr_pages = 1;
 
-		page = list_entry(next, struct page, lru);
-		next = page->lru.next;
-
 		VM_BUG_ON_PAGE(PageLRU(page), page);
 		VM_BUG_ON_PAGE(page_count(page), page);
 
@@ -5440,7 +5436,8 @@ static void uncharge_list(struct list_head *page_list)
 		page->mem_cgroup = NULL;
 
 		pgpgout++;
-	} while (next != page_list);
+	} while (!list_is_last(&page->lru, page_list) &&
+		 (page = list_next_entry(page, lru)));
 
 	if (memcg)
 		uncharge_batch(memcg, pgpgout, nr_anon, nr_file,
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry
  2015-12-03 14:16 ` Geliang Tang
  (?)
@ 2015-12-03 16:27   ` Michal Hocko
  -1 siblings, 0 replies; 18+ messages in thread
From: Michal Hocko @ 2015-12-03 16:27 UTC (permalink / raw)
  To: Geliang Tang; +Cc: Johannes Weiner, cgroups, linux-mm, linux-kernel

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...

> Signed-off-by: Geliang Tang <geliangtang@163.com>
> ---
>  mm/memcontrol.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 79a29d5..a6301ea 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -5395,16 +5395,12 @@ static void uncharge_list(struct list_head *page_list)
>  	unsigned long nr_file = 0;
>  	unsigned long nr_huge = 0;
>  	unsigned long pgpgout = 0;
> -	struct list_head *next;
>  	struct page *page;
>  
> -	next = page_list->next;
> +	page = list_first_entry(page_list, struct page, lru);
>  	do {
>  		unsigned int nr_pages = 1;
>  
> -		page = list_entry(next, struct page, lru);
> -		next = page->lru.next;
> -
>  		VM_BUG_ON_PAGE(PageLRU(page), page);
>  		VM_BUG_ON_PAGE(page_count(page), page);
>  
> @@ -5440,7 +5436,8 @@ static void uncharge_list(struct list_head *page_list)
>  		page->mem_cgroup = NULL;
>  
>  		pgpgout++;
> -	} while (next != page_list);
> +	} while (!list_is_last(&page->lru, page_list) &&
> +		 (page = list_next_entry(page, lru)));
>  
>  	if (memcg)
>  		uncharge_batch(memcg, pgpgout, nr_anon, nr_file,
> -- 
> 2.5.0
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry
@ 2015-12-03 16:27   ` Michal Hocko
  0 siblings, 0 replies; 18+ messages in thread
From: Michal Hocko @ 2015-12-03 16:27 UTC (permalink / raw)
  To: Geliang Tang; +Cc: Johannes Weiner, cgroups, linux-mm, linux-kernel

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...

> Signed-off-by: Geliang Tang <geliangtang@163.com>
> ---
>  mm/memcontrol.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 79a29d5..a6301ea 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -5395,16 +5395,12 @@ static void uncharge_list(struct list_head *page_list)
>  	unsigned long nr_file = 0;
>  	unsigned long nr_huge = 0;
>  	unsigned long pgpgout = 0;
> -	struct list_head *next;
>  	struct page *page;
>  
> -	next = page_list->next;
> +	page = list_first_entry(page_list, struct page, lru);
>  	do {
>  		unsigned int nr_pages = 1;
>  
> -		page = list_entry(next, struct page, lru);
> -		next = page->lru.next;
> -
>  		VM_BUG_ON_PAGE(PageLRU(page), page);
>  		VM_BUG_ON_PAGE(page_count(page), page);
>  
> @@ -5440,7 +5436,8 @@ static void uncharge_list(struct list_head *page_list)
>  		page->mem_cgroup = NULL;
>  
>  		pgpgout++;
> -	} while (next != page_list);
> +	} while (!list_is_last(&page->lru, page_list) &&
> +		 (page = list_next_entry(page, lru)));
>  
>  	if (memcg)
>  		uncharge_batch(memcg, pgpgout, nr_anon, nr_file,
> -- 
> 2.5.0
> 

-- 
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry
@ 2015-12-03 16:27   ` Michal Hocko
  0 siblings, 0 replies; 18+ messages in thread
From: Michal Hocko @ 2015-12-03 16:27 UTC (permalink / raw)
  To: Geliang Tang
  Cc: Johannes Weiner, cgroups-u79uwXL29TY76Z2rM5mHXA,
	linux-mm-Bw31MaZKKs3YtjvyW6yDsg,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

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...

> Signed-off-by: Geliang Tang <geliangtang-9Onoh4P/yGk@public.gmane.org>
> ---
>  mm/memcontrol.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 79a29d5..a6301ea 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -5395,16 +5395,12 @@ static void uncharge_list(struct list_head *page_list)
>  	unsigned long nr_file = 0;
>  	unsigned long nr_huge = 0;
>  	unsigned long pgpgout = 0;
> -	struct list_head *next;
>  	struct page *page;
>  
> -	next = page_list->next;
> +	page = list_first_entry(page_list, struct page, lru);
>  	do {
>  		unsigned int nr_pages = 1;
>  
> -		page = list_entry(next, struct page, lru);
> -		next = page->lru.next;
> -
>  		VM_BUG_ON_PAGE(PageLRU(page), page);
>  		VM_BUG_ON_PAGE(page_count(page), page);
>  
> @@ -5440,7 +5436,8 @@ static void uncharge_list(struct list_head *page_list)
>  		page->mem_cgroup = NULL;
>  
>  		pgpgout++;
> -	} while (next != page_list);
> +	} while (!list_is_last(&page->lru, page_list) &&
> +		 (page = list_next_entry(page, lru)));
>  
>  	if (memcg)
>  		uncharge_batch(memcg, pgpgout, nr_anon, nr_file,
> -- 
> 2.5.0
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry
  2015-12-03 16:27   ` Michal Hocko
  (?)
@ 2015-12-03 19:27     ` Johannes Weiner
  -1 siblings, 0 replies; 18+ messages in thread
From: Johannes Weiner @ 2015-12-03 19:27 UTC (permalink / raw)
  To: Michal Hocko; +Cc: Geliang Tang, cgroups, linux-mm, linux-kernel

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


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry
@ 2015-12-03 19:27     ` Johannes Weiner
  0 siblings, 0 replies; 18+ messages in thread
From: Johannes Weiner @ 2015-12-03 19:27 UTC (permalink / raw)
  To: Michal Hocko; +Cc: Geliang Tang, cgroups, linux-mm, linux-kernel

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.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry
@ 2015-12-03 19:27     ` Johannes Weiner
  0 siblings, 0 replies; 18+ messages in thread
From: Johannes Weiner @ 2015-12-03 19:27 UTC (permalink / raw)
  To: Michal Hocko; +Cc: Geliang Tang, cgroups, linux-mm, linux-kernel

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

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry
  2015-12-03 19:27     ` Johannes Weiner
  (?)
@ 2015-12-04  8:46       ` Michal Hocko
  -1 siblings, 0 replies; 18+ messages in thread
From: Michal Hocko @ 2015-12-04  8:46 UTC (permalink / raw)
  To: Johannes Weiner; +Cc: Geliang Tang, cgroups, linux-mm, linux-kernel

On Thu 03-12-15 14:27:50, Johannes Weiner wrote:
> 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.

Ohh, I completely forgot about mem_cgroup_uncharge doing
uncharge_list(&page->lru)

> >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.

Yes, this is helpful.
 
> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  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

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry
@ 2015-12-04  8:46       ` Michal Hocko
  0 siblings, 0 replies; 18+ messages in thread
From: Michal Hocko @ 2015-12-04  8:46 UTC (permalink / raw)
  To: Johannes Weiner; +Cc: Geliang Tang, cgroups, linux-mm, linux-kernel

On Thu 03-12-15 14:27:50, Johannes Weiner wrote:
> 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.

Ohh, I completely forgot about mem_cgroup_uncharge doing
uncharge_list(&page->lru)

> >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.

Yes, this is helpful.
 
> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  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

-- 
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry
@ 2015-12-04  8:46       ` Michal Hocko
  0 siblings, 0 replies; 18+ messages in thread
From: Michal Hocko @ 2015-12-04  8:46 UTC (permalink / raw)
  To: Johannes Weiner
  Cc: Geliang Tang, cgroups-u79uwXL29TY76Z2rM5mHXA,
	linux-mm-Bw31MaZKKs3YtjvyW6yDsg,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Thu 03-12-15 14:27:50, Johannes Weiner wrote:
> 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.

Ohh, I completely forgot about mem_cgroup_uncharge doing
uncharge_list(&page->lru)

> >From e8ba3f31bb43ed4091b997b6ee8857dc8bbcd349 Mon Sep 17 00:00:00 2001
> From: Johannes Weiner <hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.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.

Yes, this is helpful.
 
> Signed-off-by: Johannes Weiner <hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>

Acked-by: Michal Hocko <mhocko-IBi9RG/b67k@public.gmane.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

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry
  2015-12-03 16:27   ` Michal Hocko
@ 2015-12-05  2:55     ` Geliang Tang
  -1 siblings, 0 replies; 18+ messages in thread
From: Geliang Tang @ 2015-12-05  2:55 UTC (permalink / raw)
  To: Michal Hocko, Johannes Weiner
  Cc: cgroups, linux-mm, linux-kernel, Geliang Tang

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...

I have tested it, list_for_each_entry can't work. Dose it mean that my
patch is OK? Or please give me some other advices.

Thanks.

- Geliang

> > Signed-off-by: Geliang Tang <geliangtang@163.com>
> > ---
> >  mm/memcontrol.c | 9 +++------
> >  1 file changed, 3 insertions(+), 6 deletions(-)
> > 
> > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > index 79a29d5..a6301ea 100644
> > --- a/mm/memcontrol.c
> > +++ b/mm/memcontrol.c
> > @@ -5395,16 +5395,12 @@ static void uncharge_list(struct list_head *page_list)
> >  	unsigned long nr_file = 0;
> >  	unsigned long nr_huge = 0;
> >  	unsigned long pgpgout = 0;
> > -	struct list_head *next;
> >  	struct page *page;
> >  
> > -	next = page_list->next;
> > +	page = list_first_entry(page_list, struct page, lru);
> >  	do {
> >  		unsigned int nr_pages = 1;
> >  
> > -		page = list_entry(next, struct page, lru);
> > -		next = page->lru.next;
> > -
> >  		VM_BUG_ON_PAGE(PageLRU(page), page);
> >  		VM_BUG_ON_PAGE(page_count(page), page);
> >  
> > @@ -5440,7 +5436,8 @@ static void uncharge_list(struct list_head *page_list)
> >  		page->mem_cgroup = NULL;
> >  
> >  		pgpgout++;
> > -	} while (next != page_list);
> > +	} while (!list_is_last(&page->lru, page_list) &&
> > +		 (page = list_next_entry(page, lru)));
> >  
> >  	if (memcg)
> >  		uncharge_batch(memcg, pgpgout, nr_anon, nr_file,
> > -- 
> > 2.5.0
> > 


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry
@ 2015-12-05  2:55     ` Geliang Tang
  0 siblings, 0 replies; 18+ messages in thread
From: Geliang Tang @ 2015-12-05  2:55 UTC (permalink / raw)
  To: Michal Hocko, Johannes Weiner
  Cc: cgroups, linux-mm, linux-kernel, Geliang Tang

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...

I have tested it, list_for_each_entry can't work. Dose it mean that my
patch is OK? Or please give me some other advices.

Thanks.

- Geliang

> > Signed-off-by: Geliang Tang <geliangtang@163.com>
> > ---
> >  mm/memcontrol.c | 9 +++------
> >  1 file changed, 3 insertions(+), 6 deletions(-)
> > 
> > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > index 79a29d5..a6301ea 100644
> > --- a/mm/memcontrol.c
> > +++ b/mm/memcontrol.c
> > @@ -5395,16 +5395,12 @@ static void uncharge_list(struct list_head *page_list)
> >  	unsigned long nr_file = 0;
> >  	unsigned long nr_huge = 0;
> >  	unsigned long pgpgout = 0;
> > -	struct list_head *next;
> >  	struct page *page;
> >  
> > -	next = page_list->next;
> > +	page = list_first_entry(page_list, struct page, lru);
> >  	do {
> >  		unsigned int nr_pages = 1;
> >  
> > -		page = list_entry(next, struct page, lru);
> > -		next = page->lru.next;
> > -
> >  		VM_BUG_ON_PAGE(PageLRU(page), page);
> >  		VM_BUG_ON_PAGE(page_count(page), page);
> >  
> > @@ -5440,7 +5436,8 @@ static void uncharge_list(struct list_head *page_list)
> >  		page->mem_cgroup = NULL;
> >  
> >  		pgpgout++;
> > -	} while (next != page_list);
> > +	} while (!list_is_last(&page->lru, page_list) &&
> > +		 (page = list_next_entry(page, lru)));
> >  
> >  	if (memcg)
> >  		uncharge_batch(memcg, pgpgout, nr_anon, nr_file,
> > -- 
> > 2.5.0
> > 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry
  2015-12-05  2:55     ` Geliang Tang
@ 2015-12-05 16:22       ` Johannes Weiner
  -1 siblings, 0 replies; 18+ messages in thread
From: Johannes Weiner @ 2015-12-05 16:22 UTC (permalink / raw)
  To: Geliang Tang; +Cc: Michal Hocko, cgroups, linux-mm, linux-kernel

On Sat, Dec 05, 2015 at 10:55:42AM +0800, Geliang Tang wrote:
> 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...
> 
> I have tested it, list_for_each_entry can't work. Dose it mean that my
> patch is OK? Or please give me some other advices.

Your patch is okay. Please feel free to add my

Acked-by: Johannes Weiner <hannes@cmpxchg.org>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry
@ 2015-12-05 16:22       ` Johannes Weiner
  0 siblings, 0 replies; 18+ messages in thread
From: Johannes Weiner @ 2015-12-05 16:22 UTC (permalink / raw)
  To: Geliang Tang; +Cc: Michal Hocko, cgroups, linux-mm, linux-kernel

On Sat, Dec 05, 2015 at 10:55:42AM +0800, Geliang Tang wrote:
> 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...
> 
> I have tested it, list_for_each_entry can't work. Dose it mean that my
> patch is OK? Or please give me some other advices.

Your patch is okay. Please feel free to add my

Acked-by: Johannes Weiner <hannes@cmpxchg.org>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry
  2015-12-05  2:55     ` Geliang Tang
@ 2015-12-07 16:21       ` Michal Hocko
  -1 siblings, 0 replies; 18+ messages in thread
From: Michal Hocko @ 2015-12-07 16:21 UTC (permalink / raw)
  To: Geliang Tang; +Cc: Johannes Weiner, cgroups, linux-mm, linux-kernel

On Sat 05-12-15 10:55:42, Geliang Tang wrote:
> 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...
> 
> I have tested it, list_for_each_entry can't work. Dose it mean that my
> patch is OK? Or please give me some other advices.

I dunno. Your change is technically correct of course. I find the exit
condition easier to read without your patch though.

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry
@ 2015-12-07 16:21       ` Michal Hocko
  0 siblings, 0 replies; 18+ messages in thread
From: Michal Hocko @ 2015-12-07 16:21 UTC (permalink / raw)
  To: Geliang Tang; +Cc: Johannes Weiner, cgroups, linux-mm, linux-kernel

On Sat 05-12-15 10:55:42, Geliang Tang wrote:
> 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...
> 
> I have tested it, list_for_each_entry can't work. Dose it mean that my
> patch is OK? Or please give me some other advices.

I dunno. Your change is technically correct of course. I find the exit
condition easier to read without your patch though.

-- 
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2015-12-07 16:21 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-03 14:16 [PATCH] mm/memcontrol.c: use list_{first,next}_entry Geliang Tang
2015-12-03 14:16 ` Geliang Tang
2015-12-03 14:16 ` Geliang Tang
2015-12-03 16:27 ` Michal Hocko
2015-12-03 16:27   ` Michal Hocko
2015-12-03 16:27   ` Michal Hocko
2015-12-03 19:27   ` Johannes Weiner
2015-12-03 19:27     ` Johannes Weiner
2015-12-03 19:27     ` Johannes Weiner
2015-12-04  8:46     ` Michal Hocko
2015-12-04  8:46       ` Michal Hocko
2015-12-04  8:46       ` Michal Hocko
2015-12-05  2:55   ` Geliang Tang
2015-12-05  2:55     ` Geliang Tang
2015-12-05 16:22     ` Johannes Weiner
2015-12-05 16:22       ` Johannes Weiner
2015-12-07 16:21     ` Michal Hocko
2015-12-07 16:21       ` Michal Hocko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.