From: Yosry Ahmed <yosry@kernel.org>
To: Joanne Koong <joannelkoong@gmail.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>,
James Houghton <jthoughton@google.com>,
Shakeel Butt <shakeel.butt@linux.dev>, Tejun Heo <tj@kernel.org>,
Jan Kara <jack@suse.cz>, Miklos Szeredi <miklos@szeredi.hu>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
kernel-team@meta.com, fuse-devel <fuse-devel@lists.linux.dev>,
Jingbo Xu <jefflexu@linux.alibaba.com>,
Roman Gushchin <roman.gushchin@linux.dev>,
linux-mm <linux-mm@kvack.org>,
"open list:CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG)"
<cgroups@vger.kernel.org>, Nhat Pham <nphamcs@gmail.com>,
Jesper Dangaard Brouer <hawk@kernel.org>,
Yunzhao Li <yunzhao@cloudflare.com>, Song Hu <husong@kylinos.cn>
Subject: Re: memcg stats flushing (WAS "Re: [PATCH] fuse: disable default bdi strictlimiting")
Date: Wed, 14 Oct 2026 15:34:23 +0000 [thread overview]
Message-ID: <as-fG4VB_4xnAI8n@google.com> (raw)
In-Reply-To: <CAJnrk1ayOhrFY8LOMYxqEMYZvhK10zjTTyOK93VzMgxpV5W5sA@mail.gmail.com>
> Thinking some more about how stats are used... I think there's two
> categories the stats fall into: a) hot in-kernel ones (eg LRU sizes,
> workingset counters, dirty/writeback, zswap) which are read very
> frequently from the reclaim, refault, writeback and zswap paths and b)
> userspace-only ones (everything else) that are read through
> memory.stat / bpf / etc and much less often. The hot in-kernel ones
> are a small subset (~20 of ~80). Most of the stats fall into category
> b). However right now, a flush always aggregates *all* of these stats,
> even when the caller only needs / cares about the hot in-kernel ones.
> Flushing does all the work for the stats in category b), which the
> in-kernel flushers don't need. With the per-node lruvec copies, a
> flush goes through 100+ counters per cgroup per CPU vs ~30 for just
> the hot in-kernel ones (on a single-node machine).
I didn't measure this before, but I did tree adding a bitmask to check
which stats have updates and that actually made flushing more expensive.
It could have been the case that hot stats were distributed enough that
all the cachelines were being fetched anyway and the bitmask was just
added overhead.
I think you should do a simple experiment first about how much flushing
gets faster if you skip the stats not used by the kernel. It may or may
not matter, depends on prefetching (conversely, I wonder if explicitly
prefetching the entire stats array on each CPU would help).
I think it would matter less if we manage to completely get rid of root
flushes (except for userspace stat reads).
>
> What do you think about splitting the stats into two rstat trees, one
> for each category? In-kernel flushers would then only flush the hot
> tree (~30 counters). memory.stat would still flush both (eg userspace
> would see the same thing as it sees today). Each tree would have its
> own lock and its own stats_updates threshold. I can run some
> benchmarks but I think this would make flushes a lot cheaper, and
> since flushes would hold the lock for less time, it should also reduce
> the contention we see between concurrent flushers right now. Together
> with using node counters for root readers, hopefully this will make
> the non-ratelimited flush cheap enough for all non-root in-kernel
> readers and ideally let us get rid of the ratelimiting variant
> altogether.
>
> Do you think something like this makes sense?
We have to consider the update side of things as well. How many code
paths will need to update both trees? That could be a problem.
From a code perspective, it would also be a bit annoying to maintain. I
would check if we can eliminate root flushes first tbh, then check any
other potential optimizations on top. Subtrees should me a lot smaller
than the entire tree.
> Separate from this but also kind of semi-related, I noticed
> css_rstat_flush() takes the rstat lock for every possible cpu, even
> cpus that have nothing to flush for the subtree. Maybe another
> improvement is to just first check locklessly whether there's any
> updates and then just skip the cpu if there aren't any. I can send a
> patch out for this.
Only the updated cgroups are on the update tree, not their ancestors,
not until the flush time. We used to put the ancestors on the tree on
the update side, but we don't anymore.
So we can only check the if the per-subsystem list is empty, not the
subtree specifically, right? Can we walk the per-subsystem list without
holding the lock or deleting first?
>
> Thanks,
> Joanne
next prev parent reply other threads:[~2026-10-14 15:34 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 21:04 memcg stats flushing (WAS "Re: [PATCH] fuse: disable default bdi strictlimiting") Joanne Koong
2026-08-06 21:12 ` Joanne Koong
2026-08-06 21:31 ` Yosry Ahmed
2026-08-10 16:49 ` Joanne Koong
2026-08-11 0:48 ` Yosry Ahmed
2026-08-12 20:59 ` Joanne Koong
2026-08-18 18:40 ` Yosry Ahmed
2026-08-20 23:39 ` Joanne Koong
2026-08-21 19:40 ` Yosry Ahmed
2026-08-22 1:38 ` James Houghton
2026-08-24 23:42 ` Joanne Koong
2026-09-14 19:01 ` Joanne Koong
2026-09-22 18:27 ` James Houghton
2026-09-23 0:50 ` Joanne Koong
2026-10-05 20:45 ` Yosry Ahmed
2026-10-14 0:05 ` Joanne Koong
2026-10-14 15:34 ` Yosry Ahmed [this message]
2026-08-27 0:28 ` Joanne Koong
2026-08-27 6:31 ` Yosry Ahmed
2026-08-28 0:51 ` Joanne Koong
2026-08-28 13:17 ` Yosry Ahmed
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=as-fG4VB_4xnAI8n@google.com \
--to=yosry@kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=fuse-devel@lists.linux.dev \
--cc=hannes@cmpxchg.org \
--cc=hawk@kernel.org \
--cc=husong@kylinos.cn \
--cc=jack@suse.cz \
--cc=jefflexu@linux.alibaba.com \
--cc=joannelkoong@gmail.com \
--cc=jthoughton@google.com \
--cc=kernel-team@meta.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=miklos@szeredi.hu \
--cc=nphamcs@gmail.com \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=tj@kernel.org \
--cc=yunzhao@cloudflare.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