From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,yosry@kernel.org,shakeel.butt@linux.dev,
roman.gushchin@linux.dev,muchun.song@linux.dev,mhocko@kernel.org,
littleswimmingwhale@gmail.com,hannes@cmpxchg.org,mingyu.he@shopee.com,
akpm@linux-foundation.org
Subject: + mm-bpf-always-flush-memcg-stats-when-explicitly-requested.patch added to mm-new branch
Date: Mon, 30 Nov 2026 21:52:22 -0800 [thread overview]
Message-ID: <20261201055222.9490A1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20261112041348.66915-1-mingyu.he@shopee.com>
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
prev parent reply other threads:[~2026-12-01 5:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Andrew Morton [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201055222.9490A1F00893@smtp.kernel.org \
--to=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=littleswimmingwhale@gmail.com \
--cc=mhocko@kernel.org \
--cc=mingyu.he@shopee.com \
--cc=mm-commits@vger.kernel.org \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=yosry@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.