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] mm: shrinker: stop counting when the seq buffer overflows
Date: Sat, 21 Nov 2026 19:10:37 +0800 [thread overview]
Message-ID: <57ef6b0f-e9eb-4484-b07f-63c848ffde4e@linux.dev> (raw)
In-Reply-To: <20261120110538.3256962-1-wangxuewen_ky@163.com>
On 11/20/26 7:05 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.
> Leave the overflow state intact and return zero so seq_file can retry.
>
> Signed-off-by: Xuewen Wang <wangxuewen@kylinos.cn>
> ---
> In a single-node KVM guest with 1024 cgroups each caching 16 ordinary
> files on ext4, the 8865-byte output required three show attempts. Count
> callbacks fell from 3075 to 2472 (19.6%). With probes disabled, six fresh
> guests per variant each performed 101 full reads. The median of guest
> medians fell from 128.2 us to 112.2 us (12.4%, about 16 us per read).
> Small and sparse outputs had unchanged callback counts. Complete output,
> small reads and seek-to-zero rereads matched; concurrent memcg deletion
> and signal interruption checks also passed.
>
> The successful pass still traverses the full list. Early exit skips
> count queries for subsequent memcgs in overflowing passes.
>
> When overflow coincides with a pending signal, the original code can
> return -EINTR in the current pass. With early exit, seq_file attempts to
> grow the buffer first. The retry can return -EINTR, or buffer allocation
> can fail first with -ENOMEM.
Would something like the following work instead?
if (!memcg_aware) {
mem_cgroup_iter_break(NULL, memcg);
break;
}
if (signal_pending(current)) {
mem_cgroup_iter_break(NULL, memcg);
ret = -EINTR;
break;
}
+ if (seq_has_overflowed(m)) {
+ mem_cgroup_iter_break(NULL, memcg);
+ break;
+ }
} while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL);
Thanks,
Qi
>
> mm/shrinker_debug.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c
> index cafb566301326..3022d103b0b1e 100644
> --- a/mm/shrinker_debug.c
> +++ b/mm/shrinker_debug.c
> @@ -74,7 +74,7 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v)
> seq_putc(m, '\n');
> }
>
> - if (!memcg_aware) {
> + if (!memcg_aware || seq_has_overflowed(m)) {
> mem_cgroup_iter_break(NULL, memcg);
> break;
> }
prev parent reply other threads:[~2026-11-21 11:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 11:05 Xuewen Wang
2026-11-20 11:48 ` Muchun Song
2026-11-21 11:10 ` 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=57ef6b0f-e9eb-4484-b07f-63c848ffde4e@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®