* Re: [PATCH v3] mm/bpf: Always flush memcg stats when explicitly requested
2026-11-12 4:13 [PATCH v3] mm/bpf: Always flush memcg stats when explicitly requested Runli
@ 2026-11-13 4:14 ` sashiko-bot
2026-11-17 7:09 ` Mingyu He
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-13 4:14 UTC (permalink / raw)
To: Runli, Johannes Weiner, Michal Hocko, Roman Gushchin,
Shakeel Butt, linux-mm
Cc: Muchun Song, Andrew Morton, Yosry Ahmed, littleswimmingwhale, tj,
mkoutny
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] mm/bpf: single-word nickname in Author and Signed-off-by
trailer
--
commit 4c2af3a1c095e013e48cf708056b8f9ea3fe242a
Author: Runli <mingyu.he@shopee.com>
> mm/bpf: Always flush memcg stats when explicitly requested
>
> memcg_rstat_updated() stops walking the ancestors when a memcg exceeds
> the flush threshold. A concurrent flush can leave an ancestor below the
> threshold, so the early exit prevents it from receiving further updates.
>
> Consider root and leaf on a 4-CPU system, with a threshold of 256.
> CPU 0 is flushing another CPU's stats after CPU 1's stats have already
> been flushed. The counts below are shared stats_updates counters:
>
> CPU 0 (root flush) CPU 1 (leaf updates)
> ------------------ --------------------
> clear leaf->stats_updates
> add 64 to leaf and root
> clear root->stats_updates
> finish flush
> leaf = 64, root = 0
> 4 more batches of 64:
> leaf = 320, root = 256
> next update:
> leaf > threshold
> break; root is not updated
>
> Root remains at the threshold, which is insufficient to trigger a flush,
> while further leaf updates keep taking the early exit. The periodic
> forced flush restores progress, but until then the root's aggregated
> statistics can fall far behind. For example, page cache grows at rate of
> 1 GiB/s, a two-second wait can leave the reported usage about 2 GiB below
> the actual usage.
>
> Make bpf_mem_cgroup_flush_stats() force a flush without waiting for the
> periodic flusher, while preserving the memcg flush bookkeeping.
>
> Suggested-by: Shakeel Butt <shakeel.butt@linux.dev>
> Link: https://lore.kernel.org/all/avKy9oMwDRjKjfzm@linux.dev/
> Signed-off-by: Runli <mingyu.he@shopee.com>
[Severity: High]
Documentation/process/submitting-patches.rst requires a full real name
rather than a single-word nickname or handle in the Author header and
Signed-off-by trailer (for example, Mingyu He <mingyu.he@shopee.com>).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261112041348.66915-1-mingyu.he@shopee.com?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v3] mm/bpf: Always flush memcg stats when explicitly requested
2026-11-12 4:13 [PATCH v3] mm/bpf: Always flush memcg stats when explicitly requested Runli
2026-11-13 4:14 ` sashiko-bot
@ 2026-11-17 7:09 ` Mingyu He
2026-11-24 7:49 ` Mingyu He
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Mingyu He @ 2026-11-17 7:09 UTC (permalink / raw)
To: Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt,
linux-mm
Cc: Muchun Song, Andrew Morton, Yosry Ahmed, cgroups, linux-kernel,
littleswimmingwhale
Hi, I wanna gently pin this email, thanks.
Runli
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v3] mm/bpf: Always flush memcg stats when explicitly requested
2026-11-12 4:13 [PATCH v3] mm/bpf: Always flush memcg stats when explicitly requested Runli
2026-11-13 4:14 ` sashiko-bot
2026-11-17 7:09 ` Mingyu He
@ 2026-11-24 7:49 ` Mingyu He
2026-11-24 8:07 ` Shakeel Butt
2026-12-01 5:52 ` + mm-bpf-always-flush-memcg-stats-when-explicitly-requested.patch added to mm-new branch Andrew Morton
4 siblings, 0 replies; 6+ messages in thread
From: Mingyu He @ 2026-11-24 7:49 UTC (permalink / raw)
To: Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt,
linux-mm
Cc: Muchun Song, Andrew Morton, Yosry Ahmed, cgroups, linux-kernel,
littleswimmingwhale
hi, gently pin this email, thanks!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3] mm/bpf: Always flush memcg stats when explicitly requested
2026-11-12 4:13 [PATCH v3] mm/bpf: Always flush memcg stats when explicitly requested Runli
` (2 preceding siblings ...)
2026-11-24 7:49 ` Mingyu He
@ 2026-11-24 8:07 ` Shakeel Butt
2026-12-01 5:52 ` + mm-bpf-always-flush-memcg-stats-when-explicitly-requested.patch added to mm-new branch Andrew Morton
4 siblings, 0 replies; 6+ messages in thread
From: Shakeel Butt @ 2026-11-24 8:07 UTC (permalink / raw)
To: Runli
Cc: Johannes Weiner, Michal Hocko, Roman Gushchin, linux-mm,
Muchun Song, Andrew Morton, Yosry Ahmed, cgroups, linux-kernel,
littleswimmingwhale
On Thu, Nov 12, 2026 at 12:13:48PM +0800, Runli wrote:
> memcg_rstat_updated() stops walking the ancestors when a memcg exceeds
> the flush threshold. A concurrent flush can leave an ancestor below the
> threshold, so the early exit prevents it from receiving further updates.
>
> Consider root and leaf on a 4-CPU system, with a threshold of 256.
> CPU 0 is flushing another CPU's stats after CPU 1's stats have already
> been flushed. The counts below are shared stats_updates counters:
>
> CPU 0 (root flush) CPU 1 (leaf updates)
> ------------------ --------------------
> clear leaf->stats_updates
> add 64 to leaf and root
> clear root->stats_updates
> finish flush
> leaf = 64, root = 0
> 4 more batches of 64:
> leaf = 320, root = 256
> next update:
> leaf > threshold
> break; root is not updated
>
> Root remains at the threshold, which is insufficient to trigger a flush,
> while further leaf updates keep taking the early exit. The periodic
> forced flush restores progress, but until then the root's aggregated
> statistics can fall far behind. For example, page cache grows at rate of
> 1 GiB/s, a two-second wait can leave the reported usage about 2 GiB below
> the actual usage.
>
> Make bpf_mem_cgroup_flush_stats() force a flush without waiting for the
> periodic flusher, while preserving the memcg flush bookkeeping.
>
> Suggested-by: Shakeel Butt <shakeel.butt@linux.dev>
> Link: https://lore.kernel.org/all/avKy9oMwDRjKjfzm@linux.dev/
> Signed-off-by: Runli <mingyu.he@shopee.com>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
^ permalink raw reply [flat|nested] 6+ messages in thread* + mm-bpf-always-flush-memcg-stats-when-explicitly-requested.patch added to mm-new branch
2026-11-12 4:13 [PATCH v3] mm/bpf: Always flush memcg stats when explicitly requested Runli
` (3 preceding siblings ...)
2026-11-24 8:07 ` Shakeel Butt
@ 2026-12-01 5:52 ` Andrew Morton
4 siblings, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2026-12-01 5:52 UTC (permalink / raw)
To: mm-commits, yosry, shakeel.butt, roman.gushchin, muchun.song,
mhocko, littleswimmingwhale, hannes, mingyu.he, akpm
The patch titled
Subject: mm/bpf: always flush memcg stats when explicitly requested
has been added to the -mm mm-new branch. Its filename is
mm-bpf-always-flush-memcg-stats-when-explicitly-requested.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-bpf-always-flush-memcg-stats-when-explicitly-requested.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: Runli <mingyu.he@shopee.com>
Subject: mm/bpf: always flush memcg stats when explicitly requested
Date: Thu, 12 Nov 2026 12:13:48 +0800
memcg_rstat_updated() stops walking the ancestors when a memcg exceeds
the flush threshold. A concurrent flush can leave an ancestor below the
threshold, so the early exit prevents it from receiving further updates.
Consider root and leaf on a 4-CPU system, with a threshold of 256.
CPU 0 is flushing another CPU's stats after CPU 1's stats have already
been flushed. The counts below are shared stats_updates counters:
CPU 0 (root flush) CPU 1 (leaf updates)
------------------ --------------------
clear leaf->stats_updates
add 64 to leaf and root
clear root->stats_updates
finish flush
leaf = 64, root = 0
4 more batches of 64:
leaf = 320, root = 256
next update:
leaf > threshold
break; root is not updated
Root remains at the threshold, which is insufficient to trigger a flush,
while further leaf updates keep taking the early exit. The periodic
forced flush restores progress, but until then the root's aggregated
statistics can fall far behind. For example, page cache grows at rate of
1 GiB/s, a two-second wait can leave the reported usage about 2 GiB below
the actual usage.
Make bpf_mem_cgroup_flush_stats() force a flush without waiting for the
periodic flusher, while preserving the memcg flush bookkeeping.
Link: https://patch.msgid.link/20261112041348.66915-1-mingyu.he@shopee.com
Signed-off-by: Runli <mingyu.he@shopee.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Suggested-by: Shakeel Butt <shakeel.butt@linux.dev>
Link: https://lore.kernel.org/all/avKy9oMwDRjKjfzm@linux.dev/
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Yosry Ahmed <yosry@kernel.org>
Cc: <littleswimmingwhale@gmail.com>
include/linux/memcontrol.h | 5 +++++
mm/bpf_memcontrol.c | 5 +++--
mm/memcontrol.c | 17 +++++++++++++++++
3 files changed, 25 insertions(+), 2 deletions(-)
--- a/include/linux/memcontrol.h~mm-bpf-always-flush-memcg-stats-when-explicitly-requested
+++ a/include/linux/memcontrol.h
@@ -975,6 +975,7 @@ void mod_memcg_lruvec_state(struct lruve
enum node_stat_item idx, int val);
void mem_cgroup_flush_stats(struct mem_cgroup *memcg);
+void mem_cgroup_flush_stats_force(struct mem_cgroup *memcg);
void mem_cgroup_flush_stats_ratelimited(struct mem_cgroup *memcg);
void mod_lruvec_kmem_state(void *p, enum node_stat_item idx, int val);
@@ -1441,6 +1442,10 @@ static inline void mem_cgroup_flush_stat
{
}
+static inline void mem_cgroup_flush_stats_force(struct mem_cgroup *memcg)
+{
+}
+
static inline void mem_cgroup_flush_stats_ratelimited(struct mem_cgroup *memcg)
{
}
--- a/mm/bpf_memcontrol.c~mm-bpf-always-flush-memcg-stats-when-explicitly-requested
+++ a/mm/bpf_memcontrol.c
@@ -154,11 +154,12 @@ __bpf_kfunc unsigned long bpf_mem_cgroup
* bpf_mem_cgroup_flush_stats - Flush memory cgroup's statistics
* @memcg: memory cgroup
*
- * Propagate memory cgroup's statistics up the cgroup tree.
+ * Flush the memory cgroup subtree and propagate its statistics up the cgroup
+ * tree, regardless of the number of pending updates.
*/
__bpf_kfunc void bpf_mem_cgroup_flush_stats(struct mem_cgroup *memcg)
{
- mem_cgroup_flush_stats(memcg);
+ mem_cgroup_flush_stats_force(memcg);
}
/**
--- a/mm/memcontrol.c~mm-bpf-always-flush-memcg-stats-when-explicitly-requested
+++ a/mm/memcontrol.c
@@ -824,6 +824,23 @@ void mem_cgroup_flush_stats(struct mem_c
__mem_cgroup_flush_stats(memcg, false);
}
+/**
+ * mem_cgroup_flush_stats_force - unconditionally flush memory cgroup statistics
+ * @memcg: root of the subtree to flush, or NULL for the root memory cgroup
+ *
+ * Flush the statistics regardless of the number of pending updates.
+ */
+void mem_cgroup_flush_stats_force(struct mem_cgroup *memcg)
+{
+ if (mem_cgroup_disabled())
+ return;
+
+ if (!memcg)
+ memcg = root_mem_cgroup;
+
+ __mem_cgroup_flush_stats(memcg, true);
+}
+
void mem_cgroup_flush_stats_ratelimited(struct mem_cgroup *memcg)
{
/* Only flush if the periodic flusher is one full cycle late */
_
Patches currently in -mm which might be from mingyu.he@shopee.com are
mm-bpf-always-flush-memcg-stats-when-explicitly-requested.patch
^ permalink raw reply [flat|nested] 6+ messages in thread