From: Vlastimil Babka <vbabka@suse.cz>
To: Hui Su <sh_def@163.com>,
akpm@linux-foundation.org, gustavo@embeddedor.com,
songmuchun@bytedance.com, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [PATCH v2] mm/list_lru: optimize condition of exiting the loop
Date: Mon, 2 Nov 2020 14:34:14 +0100 [thread overview]
Message-ID: <f9da5b26-17b8-2d55-c725-215be4410368@suse.cz> (raw)
In-Reply-To: <20201028141646.GA75933@rlk>
On 10/28/20 3:16 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.
Yes, imho comparisons that make no sense are only misleading for the readers.
Compilers can probably find out easier, so maybe there's no code generation
change, but for making it less misleading:
> Signed-off-by: Hui Su <sh_def@163.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
> ---
> include/linux/list_lru.h | 2 +-
> mm/list_lru.c | 4 ++--
> 2 files changed, 3 insertions(+), 3 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..35be4de9fd77 100644
> --- 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];
>
> @@ -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;
> }
> }
>
next prev parent reply other threads:[~2020-11-02 13:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-28 14:16 Hui Su
2020-11-02 13:34 ` Vlastimil Babka [this message]
2020-11-02 13:44 ` Pankaj Gupta
2020-11-02 13:48 ` [External] " Muchun Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f9da5b26-17b8-2d55-c725-215be4410368@suse.cz \
--to=vbabka@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=gustavo@embeddedor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=sh_def@163.com \
--cc=songmuchun@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox