* [PATCH] mm/list_lru: optimize condition of exiting the loop
@ 2020-10-27 17:04 Hui Su
2020-10-27 18:45 ` Vlastimil Babka
0 siblings, 1 reply; 3+ messages in thread
From: Hui Su @ 2020-10-27 17:04 UTC (permalink / raw)
To: akpm, gustavo, sh_def, linux-kernel, linux-mm
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.
Signed-off-by: Hui Su <sh_def@163.com>
---
include/linux/list_lru.h | 2 +-
mm/list_lru.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h
index 9dcaa3e582c9..b7bc4a2636b9 100644
--- a/include/linux/list_lru.h
+++ b/include/linux/list_lru.h
@@ -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;
diff --git a/mm/list_lru.c b/mm/list_lru.c
index 5aa6e44bc2ae..39b8d467159d 100644
--- a/mm/list_lru.c
+++ b/mm/list_lru.c
@@ -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;
}
}
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/list_lru: optimize condition of exiting the loop
2020-10-27 17:04 [PATCH] mm/list_lru: optimize condition of exiting the loop Hui Su
@ 2020-10-27 18:45 ` Vlastimil Babka
2020-10-27 19:06 ` Hui Su
0 siblings, 1 reply; 3+ messages in thread
From: Vlastimil Babka @ 2020-10-27 18:45 UTC (permalink / raw)
To: Hui Su, akpm, gustavo, linux-kernel, linux-mm
On 10/27/20 6:04 PM, Hui Su wrote:
> 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.
>
> Signed-off-by: Hui Su <sh_def@163.com>
OK. Why not this too?
--- a/mm/list_lru.c
+++ b/mm/list_lru.c
@@ -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];
> ---
> include/linux/list_lru.h | 2 +-
> mm/list_lru.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h
> index 9dcaa3e582c9..b7bc4a2636b9 100644
> --- a/include/linux/list_lru.h
> +++ b/include/linux/list_lru.h
> @@ -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;
> diff --git a/mm/list_lru.c b/mm/list_lru.c
> index 5aa6e44bc2ae..39b8d467159d 100644
> --- a/mm/list_lru.c
> +++ b/mm/list_lru.c
> @@ -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;
> }
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/list_lru: optimize condition of exiting the loop
2020-10-27 18:45 ` Vlastimil Babka
@ 2020-10-27 19:06 ` Hui Su
0 siblings, 0 replies; 3+ messages in thread
From: Hui Su @ 2020-10-27 19:06 UTC (permalink / raw)
To: Vlastimil Babka; +Cc: akpm, gustavo, linux-kernel, linux-mm
On Tue, Oct 27, 2020 at 07:45:53PM +0100, Vlastimil Babka wrote:
> On 10/27/20 6:04 PM, Hui Su wrote:
> > 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.
> >
> > Signed-off-by: Hui Su <sh_def@163.com>
>
> OK. Why not this too?
>
> --- a/mm/list_lru.c
> +++ b/mm/list_lru.c
> @@ -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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-10-27 19:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-27 17:04 [PATCH] mm/list_lru: optimize condition of exiting the loop Hui Su
2020-10-27 18:45 ` Vlastimil Babka
2020-10-27 19:06 ` Hui Su
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).