mm/list_lru: optimize condition of exiting the loop
Subsystems (2)
PATCH 1/1 mm/list_lru: optimize condition of exiting the loop
In list_lru_walk(), nr_to_walk type is 'unsigned long', so nr_to_walk won't be '< 0'.
In list_lru_walk_node(), nr_to_walk type is 'unsigned long', so *nr_to_walk won't be '< 0' too.
We can use '!nr_to_walk' instead of 'nr_to_walk <= 0', which is more precise.
--- include/linux/list_lru.h | 2 +- mm/list_lru.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/linux/list_lru.h +1 -1
@@ -214,7 +214,7 @@ list_lru_walk(struct list_lru *lru, list_lru_walk_cb isolate,for_each_node_state (nid,N_NORMAL_MEMORY ) { isolated +=list_lru_walk_node (lru, nid, isolate, cb_arg, &nr_to_walk); -if (nr_to_walk <=0 ) +if (!nr_to_walk)break ; }return isolated;
mm/list_lru.c +1 -1
@@ -304,7 +304,7 @@ unsigned long list_lru_walk_node(struct list_lru *lru, int nid, nr_to_walk);spin_unlock (&nlru->lock); -if (*nr_to_walk <=0 ) +if (!*nr_to_walk)break ; } }
Signature · 1 line
2.25.1
Quoted 10 lines · Hui Su
In
list_lru_walk(),nr_to_walktype is 'unsigned long', sonr_to_walkwon't be '< 0'.In
list_lru_walk_node(),nr_to_walktype is 'unsigned long', so*nr_to_walkwon't be '< 0' too.We can use '!nr_to_walk' instead of '
nr_to_walk<= 0', which is more precise.Signed-off-by Hui Su <[email protected]>
OK. Why not this too?
mm/list_lru.c +1 -1
@@ -294,7 +294,7 @@ unsigned long list_lru_walk_node(struct list_lru *lru, int nid, isolated +=list_lru_walk_one (lru, nid,NULL , isolate, cb_arg, nr_to_walk); -if (*nr_to_walk >0 &&list_lru_memcg_aware (lru)) { +if (*nr_to_walk &&list_lru_memcg_aware (lru)) {for_each_memcg_cache_index (memcg_idx) {struct list_lru_node *nlru = &lru->node[nid];
Quoted 32 lines
--- include/linux/list_lru.h | 2 +- mm/list_lru.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)include/linux/list_lru.h +1
-1@@ -214,7 +214,7 @@ list_lru_walk(struct list_lru *lru, list_lru_walk_cb isolate,for_each_node_state (nid,N_NORMAL_MEMORY ) { isolated +=list_lru_walk_node (lru, nid, isolate, cb_arg, &nr_to_walk); -if (nr_to_walk <=0 ) +if (!nr_to_walk)break ; }return isolated;mm/list_lru.c +1
-1@@ -304,7 +304,7 @@ unsigned long list_lru_walk_node(struct list_lru *lru, int nid, nr_to_walk);spin_unlock (&nlru->lock); -if (*nr_to_walk <=0 ) +if (!*nr_to_walk)break ; } }
Quoted 18 lines · Vlastimil Babka
Quoted 10 lines · Hui Su
In
list_lru_walk(),nr_to_walktype is 'unsigned long', sonr_to_walkwon't be '< 0'.In
list_lru_walk_node(),nr_to_walktype is 'unsigned long', so*nr_to_walkwon't be '< 0' too.We can use '!nr_to_walk' instead of '
nr_to_walk<= 0', which is more precise.Signed-off-by Hui Su <[email protected]>OK. Why not this too?
mm/list_lru.c unsigned long list_lru_walk_node(struct list_lru *lru, int nid, · line 300
Quoted 8 lines
mm/list_lru.c +1
-1@@ -294,7 +294,7 @@ unsigned long list_lru_walk_node(struct list_lru *lru, int nid, isolated +=list_lru_walk_one (lru, nid,NULL , isolate, cb_arg, nr_to_walk); -if (*nr_to_walk >0 &&list_lru_memcg_aware (lru)) { +if (*nr_to_walk &&list_lru_memcg_aware (lru)) {for_each_memcg_cache_index (memcg_idx) {struct list_lru_node *nlru = &lru->node[nid];
Thanks for your fast reply.
I did not notice that, and i would add this to my change. I will resend PATCH V2, and cc to you.
Thanks.