* [PATCH v2] mm: shrinker: stop counting when the seq buffer overflows
@ 2026-11-23 5:50 Xuewen Wang
2026-11-23 6:14 ` Qi Zheng
0 siblings, 1 reply; 2+ messages in thread
From: Xuewen Wang @ 2026-11-23 5:50 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.
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(+)
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);
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] mm: shrinker: stop counting when the seq buffer overflows
2026-11-23 5:50 [PATCH v2] mm: shrinker: stop counting when the seq buffer overflows Xuewen Wang
@ 2026-11-23 6:14 ` Qi Zheng
0 siblings, 0 replies; 2+ messages in thread
From: Qi Zheng @ 2026-11-23 6:14 UTC (permalink / raw)
To: Xuewen Wang, akpm, david, roman.gushchin, muchun.song
Cc: linux-mm, linux-kernel, Xuewen Wang
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);
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-23 6:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 5:50 [PATCH v2] mm: shrinker: stop counting when the seq buffer overflows Xuewen Wang
2026-11-23 6:14 ` Qi Zheng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox