linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: Simplify for_each_populated_zone()
@ 2012-10-19 10:55 Srivatsa S. Bhat
  2012-10-19 13:54 ` Johannes Weiner
  0 siblings, 1 reply; 6+ messages in thread
From: Srivatsa S. Bhat @ 2012-10-19 10:55 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-mm, kosaki.motohiro, akpm, hannes, srivatsa.bhat

Move the check for populated_zone() to the control statement of the
'for' loop and get rid of the odd looking if/else block.

Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
---

 include/linux/mmzone.h |    7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 50aaca8..5bdf02e 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -913,11 +913,8 @@ extern struct zone *next_zone(struct zone *zone);
 
 #define for_each_populated_zone(zone)		        \
 	for (zone = (first_online_pgdat())->node_zones; \
-	     zone;					\
-	     zone = next_zone(zone))			\
-		if (!populated_zone(zone))		\
-			; /* do nothing */		\
-		else
+	     zone && populated_zone(zone);		\
+	     zone = next_zone(zone))
 
 static inline struct zone *zonelist_zone(struct zoneref *zoneref)
 {

--
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] 6+ messages in thread

* Re: [PATCH] mm: Simplify for_each_populated_zone()
  2012-10-19 10:55 [PATCH] mm: Simplify for_each_populated_zone() Srivatsa S. Bhat
@ 2012-10-19 13:54 ` Johannes Weiner
  2012-10-19 14:26   ` Srivatsa S. Bhat
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Weiner @ 2012-10-19 13:54 UTC (permalink / raw)
  To: Srivatsa S. Bhat; +Cc: linux-kernel, linux-mm, kosaki.motohiro, akpm

On Fri, Oct 19, 2012 at 04:25:47PM +0530, Srivatsa S. Bhat wrote:
> Move the check for populated_zone() to the control statement of the
> 'for' loop and get rid of the odd looking if/else block.
> 
> Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
> ---
> 
>  include/linux/mmzone.h |    7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index 50aaca8..5bdf02e 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -913,11 +913,8 @@ extern struct zone *next_zone(struct zone *zone);
>  
>  #define for_each_populated_zone(zone)		        \
>  	for (zone = (first_online_pgdat())->node_zones; \
> -	     zone;					\
> -	     zone = next_zone(zone))			\
> -		if (!populated_zone(zone))		\
> -			; /* do nothing */		\
> -		else
> +	     zone && populated_zone(zone);		\
> +	     zone = next_zone(zone))

I don't think we want to /abort/ the loop when encountering an
unpopulated zone.

--
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] 6+ messages in thread

* Re: [PATCH] mm: Simplify for_each_populated_zone()
  2012-10-19 13:54 ` Johannes Weiner
@ 2012-10-19 14:26   ` Srivatsa S. Bhat
  0 siblings, 0 replies; 6+ messages in thread
From: Srivatsa S. Bhat @ 2012-10-19 14:26 UTC (permalink / raw)
  To: Johannes Weiner; +Cc: linux-kernel, linux-mm, kosaki.motohiro, akpm

On 10/19/2012 07:24 PM, Johannes Weiner wrote:
> On Fri, Oct 19, 2012 at 04:25:47PM +0530, Srivatsa S. Bhat wrote:
>> Move the check for populated_zone() to the control statement of the
>> 'for' loop and get rid of the odd looking if/else block.
>>
>> Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
>> ---
>>
>>  include/linux/mmzone.h |    7 ++-----
>>  1 file changed, 2 insertions(+), 5 deletions(-)
>>
>> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
>> index 50aaca8..5bdf02e 100644
>> --- a/include/linux/mmzone.h
>> +++ b/include/linux/mmzone.h
>> @@ -913,11 +913,8 @@ extern struct zone *next_zone(struct zone *zone);
>>  
>>  #define for_each_populated_zone(zone)		        \
>>  	for (zone = (first_online_pgdat())->node_zones; \
>> -	     zone;					\
>> -	     zone = next_zone(zone))			\
>> -		if (!populated_zone(zone))		\
>> -			; /* do nothing */		\
>> -		else
>> +	     zone && populated_zone(zone);		\
>> +	     zone = next_zone(zone))
> 
> I don't think we want to /abort/ the loop when encountering an
> unpopulated zone.
> 

Oops! I totally missed that.. thanks for catching it! Please ignore
the patch.

Regards,
Srivatsa S. Bhat

--
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] 6+ messages in thread

* [PATCH] mm: Simplify for_each_populated_zone()
@ 2013-04-10 20:27 Srivatsa S. Bhat
  2013-04-10 20:41 ` David Rientjes
  0 siblings, 1 reply; 6+ messages in thread
From: Srivatsa S. Bhat @ 2013-04-10 20:27 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-kernel, Srivatsa S. Bhat, KOSAKI Motohiro,
	KAMEZAWA Hiroyuki, Johannes Weiner, Mel Gorman, Andrew Morton

Simplify the if/else block to make it more readable.

Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
---

 include/linux/mmzone.h |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index ede2749..2489042 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -948,9 +948,7 @@ extern struct zone *next_zone(struct zone *zone);
 	for (zone = (first_online_pgdat())->node_zones; \
 	     zone;					\
 	     zone = next_zone(zone))			\
-		if (!populated_zone(zone))		\
-			; /* do nothing */		\
-		else
+		if (populated_zone(zone))
 
 static inline struct zone *zonelist_zone(struct zoneref *zoneref)
 {

--
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] 6+ messages in thread

* Re: [PATCH] mm: Simplify for_each_populated_zone()
  2013-04-10 20:27 Srivatsa S. Bhat
@ 2013-04-10 20:41 ` David Rientjes
  2013-04-10 20:42   ` Srivatsa S. Bhat
  0 siblings, 1 reply; 6+ messages in thread
From: David Rientjes @ 2013-04-10 20:41 UTC (permalink / raw)
  To: Srivatsa S. Bhat
  Cc: linux-mm, linux-kernel, KOSAKI Motohiro, KAMEZAWA Hiroyuki,
	Johannes Weiner, Mel Gorman, Andrew Morton

On Thu, 11 Apr 2013, Srivatsa S. Bhat wrote:

> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index ede2749..2489042 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -948,9 +948,7 @@ extern struct zone *next_zone(struct zone *zone);
>  	for (zone = (first_online_pgdat())->node_zones; \
>  	     zone;					\
>  	     zone = next_zone(zone))			\
> -		if (!populated_zone(zone))		\
> -			; /* do nothing */		\
> -		else
> +		if (populated_zone(zone))
>  
>  static inline struct zone *zonelist_zone(struct zoneref *zoneref)
>  {

Nack, it's written the way it is to avoid ambiguous else statements 
following it.  People do things like

	for_each_populated_zone(z)
		if (...) {
		} else (...) {
		}

and it's now ambiguous (and should warn with -Wparentheses).

--
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] 6+ messages in thread

* Re: [PATCH] mm: Simplify for_each_populated_zone()
  2013-04-10 20:41 ` David Rientjes
@ 2013-04-10 20:42   ` Srivatsa S. Bhat
  0 siblings, 0 replies; 6+ messages in thread
From: Srivatsa S. Bhat @ 2013-04-10 20:42 UTC (permalink / raw)
  To: David Rientjes
  Cc: linux-mm, linux-kernel, KOSAKI Motohiro, KAMEZAWA Hiroyuki,
	Johannes Weiner, Mel Gorman, Andrew Morton

On 04/11/2013 02:11 AM, David Rientjes wrote:
> On Thu, 11 Apr 2013, Srivatsa S. Bhat wrote:
> 
>> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
>> index ede2749..2489042 100644
>> --- a/include/linux/mmzone.h
>> +++ b/include/linux/mmzone.h
>> @@ -948,9 +948,7 @@ extern struct zone *next_zone(struct zone *zone);
>>  	for (zone = (first_online_pgdat())->node_zones; \
>>  	     zone;					\
>>  	     zone = next_zone(zone))			\
>> -		if (!populated_zone(zone))		\
>> -			; /* do nothing */		\
>> -		else
>> +		if (populated_zone(zone))
>>  
>>  static inline struct zone *zonelist_zone(struct zoneref *zoneref)
>>  {
> 
> Nack, it's written the way it is to avoid ambiguous else statements 
> following it.  People do things like
> 
> 	for_each_populated_zone(z)
> 		if (...) {
> 		} else (...) {
> 		}
> 
> and it's now ambiguous (and should warn with -Wparentheses).
> 

Hmm, fair enough. Please ignore this patch then. Thanks!

Regards,
Srivatsa S. Bhat

--
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] 6+ messages in thread

end of thread, other threads:[~2013-04-10 20:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-19 10:55 [PATCH] mm: Simplify for_each_populated_zone() Srivatsa S. Bhat
2012-10-19 13:54 ` Johannes Weiner
2012-10-19 14:26   ` Srivatsa S. Bhat
  -- strict thread matches above, loose matches on Subject: below --
2013-04-10 20:27 Srivatsa S. Bhat
2013-04-10 20:41 ` David Rientjes
2013-04-10 20:42   ` Srivatsa S. Bhat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).