* [PATCH] mm: remove a redundant condition in the for loop @ 2017-06-19 13:54 Hao Lee 2017-06-19 14:17 ` Vlastimil Babka 0 siblings, 1 reply; 10+ messages in thread From: Hao Lee @ 2017-06-19 13:54 UTC (permalink / raw) To: akpm Cc: vbabka, mgorman, mhocko, hannes, iamjoonsoo.kim, minchan, linux-mm, linux-kernel, Hao Lee The variable current_order decreases from MAX_ORDER-1 to order, so the condition current_order <= MAX_ORDER-1 is always true. Signed-off-by: Hao Lee <haolee.swjtu@gmail.com> --- mm/page_alloc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 2302f25..9120c2b 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2215,9 +2215,8 @@ __rmqueue_fallback(struct zone *zone, unsigned int order, int start_migratetype) bool can_steal; /* Find the largest possible block of pages in the other list */ - for (current_order = MAX_ORDER-1; - current_order >= order && current_order <= MAX_ORDER-1; - --current_order) { + for (current_order = MAX_ORDER-1; current_order >= order; + --current_order) { area = &(zone->free_area[current_order]); fallback_mt = find_suitable_fallback(area, current_order, start_migratetype, false, &can_steal); -- 2.9.3 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] mm: remove a redundant condition in the for loop 2017-06-19 13:54 [PATCH] mm: remove a redundant condition in the for loop Hao Lee @ 2017-06-19 14:17 ` Vlastimil Babka 2017-06-19 19:05 ` Rasmus Villemoes 0 siblings, 1 reply; 10+ messages in thread From: Vlastimil Babka @ 2017-06-19 14:17 UTC (permalink / raw) To: Hao Lee, akpm Cc: mgorman, mhocko, hannes, iamjoonsoo.kim, minchan, linux-mm, linux-kernel On 06/19/2017 03:54 PM, Hao Lee wrote: > The variable current_order decreases from MAX_ORDER-1 to order, so the > condition current_order <= MAX_ORDER-1 is always true. > > Signed-off-by: Hao Lee <haolee.swjtu@gmail.com> Sounds right. Acked-by: Vlastimil Babka <vbabka@suse.cz> > --- > mm/page_alloc.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 2302f25..9120c2b 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -2215,9 +2215,8 @@ __rmqueue_fallback(struct zone *zone, unsigned int order, int start_migratetype) > bool can_steal; > > /* Find the largest possible block of pages in the other list */ > - for (current_order = MAX_ORDER-1; > - current_order >= order && current_order <= MAX_ORDER-1; > - --current_order) { > + for (current_order = MAX_ORDER-1; current_order >= order; > + --current_order) { > area = &(zone->free_area[current_order]); > fallback_mt = find_suitable_fallback(area, current_order, > start_migratetype, false, &can_steal); > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] mm: remove a redundant condition in the for loop 2017-06-19 14:17 ` Vlastimil Babka @ 2017-06-19 19:05 ` Rasmus Villemoes 2017-06-19 20:23 ` Vlastimil Babka ` (2 more replies) 0 siblings, 3 replies; 10+ messages in thread From: Rasmus Villemoes @ 2017-06-19 19:05 UTC (permalink / raw) To: Vlastimil Babka Cc: Hao Lee, akpm, mgorman, mhocko, hannes, iamjoonsoo.kim, minchan, linux-mm, linux-kernel On Mon, Jun 19 2017, Vlastimil Babka <vbabka@suse.cz> wrote: > On 06/19/2017 03:54 PM, Hao Lee wrote: >> The variable current_order decreases from MAX_ORDER-1 to order, so the >> condition current_order <= MAX_ORDER-1 is always true. >> >> Signed-off-by: Hao Lee <haolee.swjtu@gmail.com> > > Sounds right. > > Acked-by: Vlastimil Babka <vbabka@suse.cz> current_order and order are both unsigned, and if order==0, current_order >= order is always true, and we may decrement current_order past 0 making it UINT_MAX... A comment would be in order, though. >> --- >> mm/page_alloc.c | 5 ++--- >> 1 file changed, 2 insertions(+), 3 deletions(-) >> >> diff --git a/mm/page_alloc.c b/mm/page_alloc.c >> index 2302f25..9120c2b 100644 >> --- a/mm/page_alloc.c >> +++ b/mm/page_alloc.c >> @@ -2215,9 +2215,8 @@ __rmqueue_fallback(struct zone *zone, unsigned int order, int start_migratetype) >> bool can_steal; >> >> /* Find the largest possible block of pages in the other list */ >> - for (current_order = MAX_ORDER-1; >> - current_order >= order && current_order <= MAX_ORDER-1; >> - --current_order) { >> + for (current_order = MAX_ORDER-1; current_order >= order; >> + --current_order) { >> area = &(zone->free_area[current_order]); >> fallback_mt = find_suitable_fallback(area, current_order, >> start_migratetype, false, &can_steal); >> ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] mm: remove a redundant condition in the for loop 2017-06-19 19:05 ` Rasmus Villemoes @ 2017-06-19 20:23 ` Vlastimil Babka 2017-06-20 1:39 ` Hao Lee 2017-06-21 9:43 ` Michal Hocko 2 siblings, 0 replies; 10+ messages in thread From: Vlastimil Babka @ 2017-06-19 20:23 UTC (permalink / raw) To: Rasmus Villemoes Cc: Hao Lee, akpm, mgorman, mhocko, hannes, iamjoonsoo.kim, minchan, linux-mm, linux-kernel On 06/19/2017 09:05 PM, Rasmus Villemoes wrote: > On Mon, Jun 19 2017, Vlastimil Babka <vbabka@suse.cz> wrote: > >> On 06/19/2017 03:54 PM, Hao Lee wrote: >>> The variable current_order decreases from MAX_ORDER-1 to order, so the >>> condition current_order <= MAX_ORDER-1 is always true. >>> >>> Signed-off-by: Hao Lee <haolee.swjtu@gmail.com> >> >> Sounds right. >> >> Acked-by: Vlastimil Babka <vbabka@suse.cz> > > current_order and order are both unsigned, and if order==0, > current_order >= order is always true, and we may decrement > current_order past 0 making it UINT_MAX... A comment would be in order, > though. Doh, right. Thanks. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] mm: remove a redundant condition in the for loop 2017-06-19 19:05 ` Rasmus Villemoes 2017-06-19 20:23 ` Vlastimil Babka @ 2017-06-20 1:39 ` Hao Lee 2017-06-21 9:43 ` Michal Hocko 2 siblings, 0 replies; 10+ messages in thread From: Hao Lee @ 2017-06-20 1:39 UTC (permalink / raw) To: Rasmus Villemoes Cc: Vlastimil Babka, akpm, mgorman, mhocko, Johannes Weiner, iamjoonsoo.kim, minchan, linux-mm, linux-kernel On Tue, Jun 20, 2017 at 3:05 AM, Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote: > On Mon, Jun 19 2017, Vlastimil Babka <vbabka@suse.cz> wrote: > >> On 06/19/2017 03:54 PM, Hao Lee wrote: >>> The variable current_order decreases from MAX_ORDER-1 to order, so the >>> condition current_order <= MAX_ORDER-1 is always true. >>> >>> Signed-off-by: Hao Lee <haolee.swjtu@gmail.com> >> >> Sounds right. >> >> Acked-by: Vlastimil Babka <vbabka@suse.cz> > > current_order and order are both unsigned, and if order==0, > current_order >= order is always true, and we may decrement > current_order past 0 making it UINT_MAX... A comment would be in order, > though. Thanks, I didn't notice unsigned subtraction. Sorry about that. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] mm: remove a redundant condition in the for loop 2017-06-19 19:05 ` Rasmus Villemoes 2017-06-19 20:23 ` Vlastimil Babka 2017-06-20 1:39 ` Hao Lee @ 2017-06-21 9:43 ` Michal Hocko 2017-06-21 18:55 ` [PATCH] mm/page_alloc.c: eliminate unsigned confusion in __rmqueue_fallback Rasmus Villemoes 2 siblings, 1 reply; 10+ messages in thread From: Michal Hocko @ 2017-06-21 9:43 UTC (permalink / raw) To: Rasmus Villemoes Cc: Vlastimil Babka, Hao Lee, akpm, mgorman, hannes, iamjoonsoo.kim, minchan, linux-mm, linux-kernel On Mon 19-06-17 21:05:29, Rasmus Villemoes wrote: > On Mon, Jun 19 2017, Vlastimil Babka <vbabka@suse.cz> wrote: > > > On 06/19/2017 03:54 PM, Hao Lee wrote: > >> The variable current_order decreases from MAX_ORDER-1 to order, so the > >> condition current_order <= MAX_ORDER-1 is always true. > >> > >> Signed-off-by: Hao Lee <haolee.swjtu@gmail.com> > > > > Sounds right. > > > > Acked-by: Vlastimil Babka <vbabka@suse.cz> > > current_order and order are both unsigned, and if order==0, > current_order >= order is always true, and we may decrement > current_order past 0 making it UINT_MAX... A comment would be in order, > though. Yes, not the first time this has been brought up https://lkml.org/lkml/2016/6/20/493. I guess a comment is long overdue. Or just get rid of the unsigned trap which would be probably more clean. > >> --- > >> mm/page_alloc.c | 5 ++--- > >> 1 file changed, 2 insertions(+), 3 deletions(-) > >> > >> diff --git a/mm/page_alloc.c b/mm/page_alloc.c > >> index 2302f25..9120c2b 100644 > >> --- a/mm/page_alloc.c > >> +++ b/mm/page_alloc.c > >> @@ -2215,9 +2215,8 @@ __rmqueue_fallback(struct zone *zone, unsigned int order, int start_migratetype) > >> bool can_steal; > >> > >> /* Find the largest possible block of pages in the other list */ > >> - for (current_order = MAX_ORDER-1; > >> - current_order >= order && current_order <= MAX_ORDER-1; > >> - --current_order) { > >> + for (current_order = MAX_ORDER-1; current_order >= order; > >> + --current_order) { > >> area = &(zone->free_area[current_order]); > >> fallback_mt = find_suitable_fallback(area, current_order, > >> start_migratetype, false, &can_steal); > >> -- Michal Hocko SUSE Labs ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH] mm/page_alloc.c: eliminate unsigned confusion in __rmqueue_fallback 2017-06-21 9:43 ` Michal Hocko @ 2017-06-21 18:55 ` Rasmus Villemoes 2017-06-23 12:22 ` Michal Hocko ` (2 more replies) 0 siblings, 3 replies; 10+ messages in thread From: Rasmus Villemoes @ 2017-06-21 18:55 UTC (permalink / raw) To: Michal Hocko, Andrew Morton, Vlastimil Babka, Hillf Danton, Johannes Weiner, Tetsuo Handa, Vinayak Menon, Xishi Qiu Cc: Hao Lee, Rasmus Villemoes, linux-mm, linux-kernel Since current_order starts as MAX_ORDER-1 and is then only decremented, the second half of the loop condition seems superfluous. However, if order is 0, we may decrement current_order past 0, making it UINT_MAX. This is obviously too subtle ([1], [2]). Since we need to add some comment anyway, change the two variables to signed, making the counting-down for loop look more familiar, and apparently also making gcc generate slightly smaller code. [1] https://lkml.org/lkml/2016/6/20/493 [2] https://lkml.org/lkml/2017/6/19/345 Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> --- Michal, something like this, perhaps? mm/page_alloc.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 2302f250d6b1..e656f4da9772 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2204,19 +2204,23 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac, * list of requested migratetype, possibly along with other pages from the same * block, depending on fragmentation avoidance heuristics. Returns true if * fallback was found so that __rmqueue_smallest() can grab it. + * + * The use of signed ints for order and current_order is a deliberate + * deviation from the rest of this file, to make the for loop + * condition simpler. */ static inline bool -__rmqueue_fallback(struct zone *zone, unsigned int order, int start_migratetype) +__rmqueue_fallback(struct zone *zone, int order, int start_migratetype) { struct free_area *area; - unsigned int current_order; + int current_order; struct page *page; int fallback_mt; bool can_steal; /* Find the largest possible block of pages in the other list */ for (current_order = MAX_ORDER-1; - current_order >= order && current_order <= MAX_ORDER-1; + current_order >= order; --current_order) { area = &(zone->free_area[current_order]); fallback_mt = find_suitable_fallback(area, current_order, -- 2.11.0 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] mm/page_alloc.c: eliminate unsigned confusion in __rmqueue_fallback 2017-06-21 18:55 ` [PATCH] mm/page_alloc.c: eliminate unsigned confusion in __rmqueue_fallback Rasmus Villemoes @ 2017-06-23 12:22 ` Michal Hocko 2017-06-23 13:10 ` Vlastimil Babka 2017-06-24 13:26 ` Wei Yang 2 siblings, 0 replies; 10+ messages in thread From: Michal Hocko @ 2017-06-23 12:22 UTC (permalink / raw) To: Rasmus Villemoes Cc: Andrew Morton, Vlastimil Babka, Hillf Danton, Johannes Weiner, Tetsuo Handa, Vinayak Menon, Xishi Qiu, Hao Lee, linux-mm, linux-kernel On Wed 21-06-17 20:55:28, Rasmus Villemoes wrote: > Since current_order starts as MAX_ORDER-1 and is then only > decremented, the second half of the loop condition seems > superfluous. However, if order is 0, we may decrement current_order > past 0, making it UINT_MAX. This is obviously too subtle ([1], [2]). > > Since we need to add some comment anyway, change the two variables to > signed, making the counting-down for loop look more familiar, and > apparently also making gcc generate slightly smaller code. > > [1] https://lkml.org/lkml/2016/6/20/493 > [2] https://lkml.org/lkml/2017/6/19/345 > > Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> I would hope for a more consistent usage of the type but his alone should prevent future attempts to "clean up" the code. Acked-by: Michal Hocko <mhocko@suse.com> > --- > Michal, something like this, perhaps? > > mm/page_alloc.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 2302f250d6b1..e656f4da9772 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -2204,19 +2204,23 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac, > * list of requested migratetype, possibly along with other pages from the same > * block, depending on fragmentation avoidance heuristics. Returns true if > * fallback was found so that __rmqueue_smallest() can grab it. > + * > + * The use of signed ints for order and current_order is a deliberate > + * deviation from the rest of this file, to make the for loop > + * condition simpler. > */ > static inline bool > -__rmqueue_fallback(struct zone *zone, unsigned int order, int start_migratetype) > +__rmqueue_fallback(struct zone *zone, int order, int start_migratetype) > { > struct free_area *area; > - unsigned int current_order; > + int current_order; > struct page *page; > int fallback_mt; > bool can_steal; > > /* Find the largest possible block of pages in the other list */ > for (current_order = MAX_ORDER-1; > - current_order >= order && current_order <= MAX_ORDER-1; > + current_order >= order; > --current_order) { > area = &(zone->free_area[current_order]); > fallback_mt = find_suitable_fallback(area, current_order, > -- > 2.11.0 > -- Michal Hocko SUSE Labs ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] mm/page_alloc.c: eliminate unsigned confusion in __rmqueue_fallback 2017-06-21 18:55 ` [PATCH] mm/page_alloc.c: eliminate unsigned confusion in __rmqueue_fallback Rasmus Villemoes 2017-06-23 12:22 ` Michal Hocko @ 2017-06-23 13:10 ` Vlastimil Babka 2017-06-24 13:26 ` Wei Yang 2 siblings, 0 replies; 10+ messages in thread From: Vlastimil Babka @ 2017-06-23 13:10 UTC (permalink / raw) To: Rasmus Villemoes, Michal Hocko, Andrew Morton, Hillf Danton, Johannes Weiner, Tetsuo Handa, Vinayak Menon, Xishi Qiu Cc: Hao Lee, linux-mm, linux-kernel On 06/21/2017 08:55 PM, Rasmus Villemoes wrote: > Since current_order starts as MAX_ORDER-1 and is then only > decremented, the second half of the loop condition seems > superfluous. However, if order is 0, we may decrement current_order > past 0, making it UINT_MAX. This is obviously too subtle ([1], [2]). > > Since we need to add some comment anyway, change the two variables to > signed, making the counting-down for loop look more familiar, and > apparently also making gcc generate slightly smaller code. > > [1] https://lkml.org/lkml/2016/6/20/493 > [2] https://lkml.org/lkml/2017/6/19/345 > > Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Acked-by: Vlastimil Babka <vbabka@suse.cz> > --- > Michal, something like this, perhaps? > > mm/page_alloc.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 2302f250d6b1..e656f4da9772 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -2204,19 +2204,23 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac, > * list of requested migratetype, possibly along with other pages from the same > * block, depending on fragmentation avoidance heuristics. Returns true if > * fallback was found so that __rmqueue_smallest() can grab it. > + * > + * The use of signed ints for order and current_order is a deliberate > + * deviation from the rest of this file, to make the for loop > + * condition simpler. > */ > static inline bool > -__rmqueue_fallback(struct zone *zone, unsigned int order, int start_migratetype) > +__rmqueue_fallback(struct zone *zone, int order, int start_migratetype) > { > struct free_area *area; > - unsigned int current_order; > + int current_order; > struct page *page; > int fallback_mt; > bool can_steal; > > /* Find the largest possible block of pages in the other list */ > for (current_order = MAX_ORDER-1; > - current_order >= order && current_order <= MAX_ORDER-1; > + current_order >= order; > --current_order) { > area = &(zone->free_area[current_order]); > fallback_mt = find_suitable_fallback(area, current_order, > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] mm/page_alloc.c: eliminate unsigned confusion in __rmqueue_fallback 2017-06-21 18:55 ` [PATCH] mm/page_alloc.c: eliminate unsigned confusion in __rmqueue_fallback Rasmus Villemoes 2017-06-23 12:22 ` Michal Hocko 2017-06-23 13:10 ` Vlastimil Babka @ 2017-06-24 13:26 ` Wei Yang 2 siblings, 0 replies; 10+ messages in thread From: Wei Yang @ 2017-06-24 13:26 UTC (permalink / raw) To: Rasmus Villemoes Cc: Michal Hocko, Andrew Morton, Vlastimil Babka, Hillf Danton, Johannes Weiner, Tetsuo Handa, Vinayak Menon, Xishi Qiu, Hao Lee, linux-mm, linux-kernel [-- Attachment #1: Type: text/plain, Size: 2285 bytes --] On Wed, Jun 21, 2017 at 08:55:28PM +0200, Rasmus Villemoes wrote: >Since current_order starts as MAX_ORDER-1 and is then only >decremented, the second half of the loop condition seems >superfluous. However, if order is 0, we may decrement current_order >past 0, making it UINT_MAX. This is obviously too subtle ([1], [2]). > >Since we need to add some comment anyway, change the two variables to >signed, making the counting-down for loop look more familiar, and >apparently also making gcc generate slightly smaller code. > >[1] https://lkml.org/lkml/2016/6/20/493 >[2] https://lkml.org/lkml/2017/6/19/345 > >Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> >--- >Michal, something like this, perhaps? > >mm/page_alloc.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > >diff --git a/mm/page_alloc.c b/mm/page_alloc.c >index 2302f250d6b1..e656f4da9772 100644 >--- a/mm/page_alloc.c >+++ b/mm/page_alloc.c >@@ -2204,19 +2204,23 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac, > * list of requested migratetype, possibly along with other pages from the same > * block, depending on fragmentation avoidance heuristics. Returns true if > * fallback was found so that __rmqueue_smallest() can grab it. >+ * >+ * The use of signed ints for order and current_order is a deliberate >+ * deviation from the rest of this file, to make the for loop >+ * condition simpler. > */ > static inline bool >-__rmqueue_fallback(struct zone *zone, unsigned int order, int start_migratetype) >+__rmqueue_fallback(struct zone *zone, int order, int start_migratetype) > { > struct free_area *area; >- unsigned int current_order; >+ int current_order; > struct page *page; > int fallback_mt; > bool can_steal; > > /* Find the largest possible block of pages in the other list */ > for (current_order = MAX_ORDER-1; >- current_order >= order && current_order <= MAX_ORDER-1; >+ current_order >= order; > --current_order) { > area = &(zone->free_area[current_order]); > fallback_mt = find_suitable_fallback(area, current_order, >-- >2.11.0 Looks nice. Why I didn't come up with this change. Acked-by: Wei Yang <weiyang@gmail.com> -- Wei Yang Help you, Help me [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 819 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2017-06-24 13:26 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-06-19 13:54 [PATCH] mm: remove a redundant condition in the for loop Hao Lee 2017-06-19 14:17 ` Vlastimil Babka 2017-06-19 19:05 ` Rasmus Villemoes 2017-06-19 20:23 ` Vlastimil Babka 2017-06-20 1:39 ` Hao Lee 2017-06-21 9:43 ` Michal Hocko 2017-06-21 18:55 ` [PATCH] mm/page_alloc.c: eliminate unsigned confusion in __rmqueue_fallback Rasmus Villemoes 2017-06-23 12:22 ` Michal Hocko 2017-06-23 13:10 ` Vlastimil Babka 2017-06-24 13:26 ` Wei Yang
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).