From: Kairui Song <ryncsn@gmail.com>
To: Vlastimil Babka <vbabka@suse.cz>,
hannes@cmpxchg.org, Jingxiang Zeng <linuszeng@tencent.com>
Cc: linux-mm@kvack.org, akpm@linux-foundation.org, mhocko@kernel.org,
roman.gushchin@linux.dev, shakeel.butt@linux.dev,
david@redhat.com, muchun.song@linux.dev,
chengming.zhou@linux.dev, lkp@intel.com
Subject: Re: [PATCH] mm/list_lru: allocate on first insert instead of allocation
Date: Mon, 3 Mar 2025 12:58:55 +0800 [thread overview]
Message-ID: <CAMgjq7Bc3_jn7rpS9zzOBNASg8K1oOqNi+rWcJo6s3EVT3_01g@mail.gmail.com> (raw)
In-Reply-To: <b9e1b9c5-a429-453e-8ced-de377b1b0bd6@suse.cz>
On Sun, Mar 2, 2025 at 2:33 AM Vlastimil Babka <vbabka@suse.cz> wrote:
>
> On 2/28/25 12:38, Jingxiang Zeng wrote:
> > From: Zeng Jingxiang <linuszeng@tencent.com>
> >
> > It is observed that each time the memcg_slab_post_alloc_hook function
> > and the zswap_store function are executed, xa_load will be executed
> > once through the following path, which adds unnecessary overhead.
> > This patch optimizes this part of the code. When a new mlru is
> > inserted into list_lru, xa_load is only executed once, and other slab
> > requests of the same type will not be executed repeatedly.
> >
> > __memcg_slab_post_alloc_hook
> > ->memcg_list_lru_alloc
> > ->->memcg_list_lru_allocated
> > ->->->xa_load
> >
> > zswap_store
> > ->memcg_list_lru_alloc
> > ->->memcg_list_lru_allocated
> > ->->->xa_load
>
> How do you know it's xa_load itself that's the issue?
>
> I think you might be able to eliminate some call overhead easily:
> - move list_lru_memcg_aware() and memcg_list_lru_allocated() to list_lru.h
> - make memcg_list_lru_alloc() also a static inline in list_lru.h, so it does
> the list_lru_memcg_aware() and memcg_list_lru_allocated() checks inline (can
> be even likely()) and then call __memcg_list_lru_alloc() which is renamed
> from the current memcg_list_lru_alloc() but the checks moved away.
>
> The result is callers of memcg_list_lru_alloc() will (in the likely case)
> only perform a direct call to xa_load() in xarray.c and not additional call
> through memcg_list_lru_alloc() in list_lru.c
>
Hi all,
I think Jinxiang's test with a different number of cgroups showed the
xa_load here is indeed an overhead here, and actually many burdens,
like the objcg lookup, cgroup ref pinning, are removed. Also removing
an extra "lru" argument.
Still hoping there is another way to avoid all these instead
of just removing part of the overhead, e.g. maybe
change the API of list_lru_add, add a variant using GFP_NOWAIT
for atomic contexts, and on failure, let the caller try again after
calling some allocation helpers in an unlocked context? There isn't too
many users of list_lru_add, doing the refractor from that side seems
cleaner, not sure if doable though.
prev parent reply other threads:[~2025-03-03 4:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-28 11:38 Jingxiang Zeng
2025-02-28 16:34 ` Johannes Weiner
2025-02-28 17:18 ` Vlastimil Babka
2025-02-28 22:05 ` Vlastimil Babka
2025-03-01 18:32 ` Vlastimil Babka
2025-03-03 4:58 ` Kairui Song [this message]
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=CAMgjq7Bc3_jn7rpS9zzOBNASg8K1oOqNi+rWcJo6s3EVT3_01g@mail.gmail.com \
--to=ryncsn@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=david@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=linuszeng@tencent.com \
--cc=linux-mm@kvack.org \
--cc=lkp@intel.com \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=vbabka@suse.cz \
/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