* [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
2026-11-24 0:09 ` + mm-shrinker-stop-counting-when-the-seq-buffer-overflows.patch added to mm-new branch Andrew Morton
0 siblings, 2 replies; 3+ 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] 3+ 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
2026-11-24 0:09 ` + mm-shrinker-stop-counting-when-the-seq-buffer-overflows.patch added to mm-new branch Andrew Morton
1 sibling, 0 replies; 3+ 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] 3+ messages in thread
* + mm-shrinker-stop-counting-when-the-seq-buffer-overflows.patch added to mm-new branch
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
@ 2026-11-24 0:09 ` Andrew Morton
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2026-11-24 0:09 UTC (permalink / raw)
To: mm-commits, roman.gushchin, qi.zheng, muchun.song, david,
wangxuewen, akpm
The patch titled
Subject: mm: shrinker: stop counting when the seq buffer overflows
has been added to the -mm mm-new branch. Its filename is
mm-shrinker-stop-counting-when-the-seq-buffer-overflows.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-shrinker-stop-counting-when-the-seq-buffer-overflows.patch
This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews. Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.
The mm-new branch of mm.git is not included in linux-next
If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Xuewen Wang <wangxuewen@kylinos.cn>
Subject: mm: shrinker: stop counting when the seq buffer overflows
Date: Mon, 23 Nov 2026 13:50:20 +0800
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.
Tested 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).
Link: https://patch.msgid.link/20261123055020.287151-1-wangxuewen_ky@163.com
Signed-off-by: Xuewen Wang <wangxuewen@kylinos.cn>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Qi Zheng <qi.zheng@linux.dev>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Muchun Song <muchun.song@linux.dev>
mm/shrinker_debug.c | 5 +++++
1 file changed, 5 insertions(+)
--- a/mm/shrinker_debug.c~mm-shrinker-stop-counting-when-the-seq-buffer-overflows
+++ a/mm/shrinker_debug.c
@@ -84,6 +84,11 @@ static int shrinker_debugfs_count_show(s
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);
_
Patches currently in -mm which might be from wangxuewen@kylinos.cn are
mm-shrinker-stop-counting-when-the-seq-buffer-overflows.patch
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-24 0:09 UTC | newest]
Thread overview: 3+ 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
2026-11-24 0:09 ` + mm-shrinker-stop-counting-when-the-seq-buffer-overflows.patch added to mm-new branch Andrew Morton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.