Re: [PATCH] mm: remove a redundant condition in the for loop
On Mon 19-06-17 21:05:29, Rasmus Villemoes wrote: > On Mon, Jun 19 2017, Vlastimil Babkawrote: > > > 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 > > > > Sounds right. > > > > Acked-by: Vlastimil Babka > > 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, _steal); > >> -- Michal Hocko SUSE Labs
Re: [PATCH] mm: remove a redundant condition in the for loop
On Mon 19-06-17 21:05:29, Rasmus Villemoes wrote: > On Mon, Jun 19 2017, Vlastimil Babka 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 > > > > Sounds right. > > > > Acked-by: Vlastimil Babka > > 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, _steal); > >> -- Michal Hocko SUSE Labs
Re: [PATCH] mm: remove a redundant condition in the for loop
On Tue, Jun 20, 2017 at 3:05 AM, Rasmus Villemoeswrote: > On Mon, Jun 19 2017, Vlastimil Babka 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 >> >> Sounds right. >> >> Acked-by: Vlastimil Babka > > 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.
Re: [PATCH] mm: remove a redundant condition in the for loop
On Tue, Jun 20, 2017 at 3:05 AM, Rasmus Villemoes wrote: > On Mon, Jun 19 2017, Vlastimil Babka 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 >> >> Sounds right. >> >> Acked-by: Vlastimil Babka > > 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.
Re: [PATCH] mm: remove a redundant condition in the for loop
On 06/19/2017 09:05 PM, Rasmus Villemoes wrote: > On Mon, Jun 19 2017, Vlastimil Babkawrote: > >> 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 >> >> Sounds right. >> >> Acked-by: Vlastimil Babka > > 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.
Re: [PATCH] mm: remove a redundant condition in the for loop
On 06/19/2017 09:05 PM, Rasmus Villemoes wrote: > On Mon, Jun 19 2017, Vlastimil Babka 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 >> >> Sounds right. >> >> Acked-by: Vlastimil Babka > > 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.
Re: [PATCH] mm: remove a redundant condition in the for loop
On Mon, Jun 19 2017, Vlastimil Babkawrote: > 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 > > Sounds right. > > Acked-by: Vlastimil Babka 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, _steal); >>
Re: [PATCH] mm: remove a redundant condition in the for loop
On Mon, Jun 19 2017, Vlastimil Babka 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 > > Sounds right. > > Acked-by: Vlastimil Babka 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, _steal); >>
Re: [PATCH] mm: remove a redundant condition in the for loop
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 LeeSounds right. Acked-by: Vlastimil Babka > --- > 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, _steal); >
Re: [PATCH] mm: remove a redundant condition in the for loop
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 Sounds right. Acked-by: Vlastimil Babka > --- > 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, _steal); >