* [PATCH] mm: shrinker: stop counting when the seq buffer overflows
@ 2026-11-20 11:05 Xuewen Wang
2026-11-20 11:48 ` Muchun Song
0 siblings, 1 reply; 2+ messages in thread
From: Xuewen Wang @ 2026-11-20 11:05 UTC (permalink / raw)
To: akpm, david, qi.zheng, roman.gushchin, muchun.song
Cc: linux-mm, linux-kernel, Xuewen Wang
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.
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;
}
--
2.53.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] mm: shrinker: stop counting when the seq buffer overflows
2026-11-20 11:05 [PATCH] mm: shrinker: stop counting when the seq buffer overflows Xuewen Wang
@ 2026-11-20 11:48 ` Muchun Song
0 siblings, 0 replies; 2+ messages in thread
From: Muchun Song @ 2026-11-20 11:48 UTC (permalink / raw)
To: Xuewen Wang
Cc: Muchun Song, akpm, david, qi.zheng, roman.gushchin, linux-mm,
linux-kernel, Xuewen Wang
> On Nov 20, 2026, at 19:05, Xuewen Wang <wangxuewen_ky@163.com> 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>
Acked-by: Muchun Song (ByteDance) <muchun.song@linux.dev>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-20 11:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 11:05 [PATCH] mm: shrinker: stop counting when the seq buffer overflows Xuewen Wang
2026-11-20 11:48 ` Muchun Song
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®