From: Qi Zheng <qi.zheng@linux.dev>
To: Xuewen Wang <wangxuewen_ky@163.com>,
akpm@linux-foundation.org, david@fromorbit.com,
roman.gushchin@linux.dev, muchun.song@linux.dev
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Xuewen Wang <wangxuewen@kylinos.cn>
Subject: Re: [PATCH v2] mm: shrinker: stop counting when the seq buffer overflows
Date: Mon, 23 Nov 2026 14:14:06 +0800 [thread overview]
Message-ID: <00efba16-87da-4fb1-8da9-2fe554a6eed9@linux.dev> (raw)
In-Reply-To: <20261123055020.287151-1-wangxuewen_ky@163.com>
On 11/23/26 1:50 PM, Xuewen Wang wrote:
> From: Xuewen Wang <wangxuewen@kylinos.cn>
>
> The shrinker debugfs count file uses single_open(), so all memcg rows
> belong to one seq_file record. When the buffer overflows, seq_file grows
> it and retries the entire record. Queries for subsequent memcgs in
> an overflowing pass cannot contribute to the final output.
>
> Stop the traversal once seq_has_overflowed() is true, using the existing
> mem_cgroup_iter_break() path to release the current memcg reference.
> Check for pending signals first to preserve the existing -EINTR
> priority. Leave the overflow state intact and return zero on overflow
> so seq_file can grow the buffer and retry.
>
> Signed-off-by: Xuewen Wang <wangxuewen@kylinos.cn>
> ---
> Changes in v2:
> - Move the overflow check after signal_pending(), as suggested by Qi
> Zheng, preserving the original -EINTR priority.
>
> Retested in a single-node KVM guest with 1024 cgroups each caching 16
> ordinary files on ext4. Output remained 8865 bytes with three show
> attempts. Count callbacks fell from 3075 to 2472 (19.6%). Six fresh
> guests per variant each performed 101 full reads with no probes
> registered. The median of guest medians fell from 127.8 us to 114.0 us
> (10.7%, about 13.7 us per read).
>
> Output matched byte-for-byte across the tested guests. Small reads,
> seek-to-zero rereads, populated memcg teardown and signal stress passed.
> Separate probe runs had no missed or dropped events. Small/sparse cases
> had unchanged callbacks. The 64-cgroup baseline timings were bimodal,
> so their apparent timing difference is not attributed to this change.
>
> mm/shrinker_debug.c | 5 +++++
> 1 file changed, 5 insertions(+)
LGTM, so:
Reviewed-by: Qi Zheng <qi.zheng@linux.dev>
Thanks,
Qi
>
> diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c
> index cafb566301326..eabdb33353a45 100644
> --- a/mm/shrinker_debug.c
> +++ b/mm/shrinker_debug.c
> @@ -84,6 +84,11 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v)
> ret = -EINTR;
> break;
> }
> +
> + if (seq_has_overflowed(m)) {
> + mem_cgroup_iter_break(NULL, memcg);
> + break;
> + }
> } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL);
>
> kfree(count_per_node);
>
prev parent reply other threads:[~2026-11-23 6:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 5:50 Xuewen Wang
2026-11-23 6:14 ` Qi Zheng [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=00efba16-87da-4fb1-8da9-2fe554a6eed9@linux.dev \
--to=qi.zheng@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=david@fromorbit.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=wangxuewen@kylinos.cn \
--cc=wangxuewen_ky@163.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
all inboxes | Powered by JetHome®