From: Xuewen Wang 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 --- 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