From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796104343; b=ou2w7/+3bWXnclHK1KtxT2ZdLXs/SJwJyAIAyzypWDgPa2vTaiiFWV2Frezh+3ZHORN+ C+ftkKcO/bFrKWsd09z+EdnYXEqufE3cMmef7eZK2YpgmadAc+7aW2NvzT9aP0r+NtE0j mCLe0RevDgzz9glHi1hCSkBGbhZeW1Em/gEUUWRubOdUY7uFHpei118A9Rm5SdLVFTn4i DF8ejyjjdN4HE6vBepxtFZIJQIk3Sgu4fOXELY0yhWkw9IuS66393waYZMCHEGBu8266T 4p+xcnbYVG4YNyUgWIvd6XGWq0tdraXa3nu/IvR1C2VgLgKEJscBlFu/NX/HfF+UroA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796104343; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=BcOFn5c11s7ueFKXBbLqUFZDVffBDWcG9V0W8ntVHS0=; b=lnu7v0l1jNApVClStxU7r2/JNT1QlFCHeWoZ2JJ6W0u6c5Bv1V5tNb/17LffTzehWtPm szsNewsWkojPHtzqu8UGhGk/mZzQxwHqHHIYv5w9dBJZ9SIHw1n55FTsx/aRh2TY0E084 eR5NaacFcJA+YS6z+lT128+NJAKQ/ZK7RsdGf93NYmznXXwUIT7R7ZtD1dWb+qEENf8zk 7L7oXNaLPcW0rQbSjqv/5xdqpEhQ/gihdSxTLIJcmVTgx8JiztEzqaqmITaYpeYsWeCyM ONSTRPAixB/CJDnCMO246ZcKsiEVN6W8JgifJqriUkkLd7Rcn1BN2B0xY6h71AyodZQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=PyhaxABQ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D5A4606A31A for ; Tue, 1 Dec 2026 05:52:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=PyhaxABQ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9490A1F00893; Tue, 1 Dec 2026 05:52:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796104342; bh=BcOFn5c11s7ueFKXBbLqUFZDVffBDWcG9V0W8ntVHS0=; h=Date:To:From:In-Reply-To:References:Subject; b=PyhaxABQGsw0f6mZ7rX9hXN56pOkX3UUaYZi3GSJw8bXDOPeZUKfzeil1b4nYazR9 D0Fd12j/UQppbxaZ3D5rKrY0B3PVDW3hT2oRvr5pz+u7QrDipewBZ7eQUsfwGM2y4O du+2fkzHqk2DGzVrvm1D/3OCNoW2cphrGMlQC/rk= Date: Mon, 30 Nov 2026 21:52:22 -0800 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 From: Andrew Morton In-Reply-To: <20261112041348.66915-1-mingyu.he@shopee.com> References: <20261112041348.66915-1-mingyu.he@shopee.com> Subject: + mm-bpf-always-flush-memcg-stats-when-explicitly-requested.patch added to mm-new branch Message-Id: <20261201055222.9490A1F00893@smtp.kernel.org> X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 Signed-off-by: Andrew Morton Suggested-by: Shakeel Butt Link: https://lore.kernel.org/all/avKy9oMwDRjKjfzm@linux.dev/ Acked-by: Shakeel Butt Cc: Johannes Weiner Cc: Michal Hocko Cc: Roman Gushchin Cc: Muchun Song Cc: Yosry Ahmed Cc: 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