mm: remove a redundant condition in the for loop
Subsystems (2)
PATCH 1/1 mm: remove a redundant condition in the for loop
The variable current_order decreases from MAX_ORDER-1 to order, so the condition current_order <= MAX_ORDER-1 is always true.
--- mm/page_alloc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
mm/page_alloc.c +2 -3
@@ -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);
Signature · 7 lines
2.9.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines · Hao Lee
The variable
current_orderdecreases from MAX_ORDER-1 to order, so the conditioncurrent_order<= MAX_ORDER-1 is always true.Signed-off-by Hao Lee <[email protected]>
Sounds right.
Quoted 11 lines
--- mm/page_alloc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)mm/page_alloc.c +0
-0@@ -2215,9 +2215,8 @@ __rmqueue_fallback(struct zone *zone, unsigned int order, int start_migratetype)bool can_steal;
mm/page_alloc.c __rmqueue_fallback(struct zone *zone, unsigned int order, int start_migratetype) · line 2222
Quoted 10 lines
mm/page_alloc.c +2
-3/* 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);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 9 lines · Vlastimil Babka
Quoted 4 lines · Hao Lee
The variable
current_orderdecreases from MAX_ORDER-1 to order, so the conditioncurrent_order<= MAX_ORDER-1 is always true.Signed-off-by Hao Lee <[email protected]>Sounds right.
Acked-by Vlastimil Babka <[email protected]>
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.
Quoted 11 lines
Quoted 11 lines
--- mm/page_alloc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)mm/page_alloc.c +0
-0@@ -2215,9 +2215,8 @@ __rmqueue_fallback(struct zone *zone, unsigned int order, int start_migratetype)bool can_steal;
Quoted 10 lines
mm/page_alloc.c __rmqueue_fallback(struct zone *zone, unsigned int order, int start_migratetype) · line 2222
Quoted 10 lines
mm/page_alloc.c +2
-3/* 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);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines · Rasmus Villemoes
Quoted 6 lines · Vlastimil Babka
Quoted 4 lines · Hao Lee
The variable
current_orderdecreases from MAX_ORDER-1 to order, so the conditioncurrent_order<= MAX_ORDER-1 is always true.Signed-off-by Hao Lee <[email protected]>
Quoted 8 lines
Quoted 3 lines
Sounds right.
Acked-by Vlastimil Babka <[email protected]>
current_orderand order are both unsigned, and if order==0,current_order>= order is always true, and we may decrementcurrent_orderpast 0 making itUINT_MAX... A comment would be in order, though.
Doh, right. Thanks.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines · Rasmus Villemoes
Quoted 6 lines · Vlastimil Babka
Quoted 4 lines · Hao Lee
The variable
current_orderdecreases from MAX_ORDER-1 to order, so the conditioncurrent_order<= MAX_ORDER-1 is always true.Signed-off-by Hao Lee <[email protected]>
Quoted 8 lines
Quoted 3 lines
Sounds right.
Acked-by Vlastimil Babka <[email protected]>
current_orderand order are both unsigned, and if order==0,current_order>= order is always true, and we may decrementcurrent_orderpast 0 making itUINT_MAX... A comment would be in order, though.
Thanks, I didn't notice unsigned subtraction. Sorry about that.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines · Rasmus Villemoes
Quoted 6 lines · Vlastimil Babka
Quoted 4 lines · Hao Lee
The variable
current_orderdecreases from MAX_ORDER-1 to order, so the conditioncurrent_order<= MAX_ORDER-1 is always true.Signed-off-by Hao Lee <[email protected]>
Quoted 8 lines
Quoted 3 lines
Sounds right.
Acked-by Vlastimil Babka <[email protected]>
current_orderand order are both unsigned, and if order==0,current_order>= order is always true, and we may decrementcurrent_orderpast 0 making itUINT_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.
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
--- mm/page_alloc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)mm/page_alloc.c +2
-3@@ -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);
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/1 mm/page_alloc.c: eliminate unsigned confusion in __rmqueue_fallback
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
---
Michal, something like this, perhaps?
mm/page_alloc.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
mm/page_alloc.c +7 -3
@@ -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,
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH] mm/page_alloc.c: eliminate unsigned confusion in __rmqueue_fallback
Quoted 5 lines · Rasmus Villemoes
Since
current_orderstarts 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 decrementcurrent_orderpast 0, making itUINT_MAX. This is obviously too subtle ([1], [2]).
Quoted 8 lines
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/345Signed-off-by Rasmus Villemoes <[email protected]>
I would hope for a more consistent usage of the type but his alone should prevent future attempts to "clean up" the code.
Quoted 40 lines
---
Michal, something like this, perhaps?
mm/page_alloc.c| 10 +++++++---1 file changed, 7 insertions(+), 3 deletions(-)mm/page_alloc.c +7
-3@@ -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,Signature · 1 line
2.11.0
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH] mm/page_alloc.c: eliminate unsigned confusion in __rmqueue_fallback
In reply to Rasmus VillemoesQuoted 5 lines · Rasmus Villemoes
Since
current_orderstarts 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 decrementcurrent_orderpast 0, making itUINT_MAX. This is obviously too subtle ([1], [2]).
Quoted 8 lines
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/345Signed-off-by Rasmus Villemoes <[email protected]>
Quoted 28 lines
---
Michal, something like this, perhaps?
mm/page_alloc.c| 10 +++++++---1 file changed, 7 insertions(+), 3 deletions(-)mm/page_alloc.c +6
-2@@ -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;
mm/page_alloc.c static bool unreserve_highatomic_pageblock(const struct alloc_context *ac, · line 2226
Quoted 10 lines
mm/page_alloc.c +1
-1int 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,
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH] mm/page_alloc.c: eliminate unsigned confusion in __rmqueue_fallback
In reply to Rasmus VillemoesQuoted 47 lines · Rasmus Villemoes
Since
current_orderstarts 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 decrementcurrent_orderpast 0, making itUINT_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/345Signed-off-by Rasmus Villemoes <[email protected]>---
Michal, something like this, perhaps?
mm/page_alloc.c| 10 +++++++---1 file changed, 7 insertions(+), 3 deletions(-)mm/page_alloc.c +4
-0@@ -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
mm/page_alloc.c +1
-1-__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;mm/page_alloc.c +1
-1-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;mm/page_alloc.c +1
-1- current_order >= order && current_order <=MAX_ORDER -1 ; + current_order >= order;
Quoted 5 lines
--current_order) { area = &(zone->free_area[current_order]); fallback_mt = find_suitable_fallback(area, current_order,Signature · 1 line
2.11.0
Looks nice. Why I didn't come up with this change.
Signature · 2 lines
Wei Yang Help you, Help me