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=1796455938; b=qL94ytWEuV/YQvfNCwSYJ1cSV0RjhzmYI+3KEtcADbXL7P3McE8IbRIagGkknMngYpAz 5I+ZOwZrJwvp5GZHK2tMjypOB0xG4v6AuiJarYu0U5nPx2wsJhxuV6SWlDTTYz+hAmJAA 9joxbGvA+Bhomekrox4nrzVmXXTQVIKnCgjpC8rh8P8Lc8ASZToHJt+x/MGx3JF/J6uSj LApQFCtvCwCtVfUfA61xZatZOGZVuXFENDDoIwHUaqtfbipQXF0EX2q9XcmP2LY9kVYLa V8TYIZNIhDAlznzDEn3GlQRTpO5cz1UM39OWHjgVid0Ktwnf8MdMvlU86WldZoycHuQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796455938; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=34qEqAmA+vKo/hnjXe2OZgR2ioqEnmEZkHY34N8NAuc=; b=1gGD1yp0Fzov9oQyKDq0vhv3Q44mhLzzWIwpTkpknP/Pps292GacKFmGEUaeSCaPCSvf F4i7B7pogNYCPRkPkexZMyJZDcgNH8LbC+8/fkzKhpLxlST99Ti1WCOdbFpp+wQxq6Eu5 lBJxiw51WHKS/6WNYilxR6tk6xDb/e+nmSfbGbme/IO7NkJ3SE1dGfEPSQX38iM2iILzJ /nWSS9bcM9lf5boylx5IFZ+wQTO8RHaIazBeV2fvYLhls08HXJRqCbVN+nPIaKQX3sdMK xSnLAk5QaCMRTONhcYPISI5vYvdFGKt3MFAX7NXjZG/bXS4bpmu9r+kebWt823+MHLQ== 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=T2NlJron; 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 4B931606A322; Sat, 5 Dec 2026 07:32:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=T2NlJron Received: by smtp.kernel.org (Postfix) with ESMTPSA id C486D1F0092B; Sat, 5 Dec 2026 07:32:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796455937; bh=34qEqAmA+vKo/hnjXe2OZgR2ioqEnmEZkHY34N8NAuc=; h=Date:To:From:In-Reply-To:References:Subject; b=T2NlJronpDLKloapUtD3HfDrLgjRLHb9MfH8Ep6d5BhMX0FLoHl5bqMrFxOxV1vVj /jdSOtG8rXwfG9z5zNyy+0mgsBvL/SzfdhzPJPIR3REGZFXG8KrUMAd47iG7e4z2kt cn16Gv2oRpJadiv24+H/ozgCquTJTOuDcLeCdPUw= Date: Fri, 04 Dec 2026 23:32:17 -0800 To: mm-commits@vger.kernel.org,zhangjiao2@cmss.chinamobile.com, stable@vger.kernel.org,shakeel.butt@linux.dev,roman.gushchin@linux.dev, muchun.song@linux.dev,mhocko@kernel.org,husong@kylinos.cn,hannes@cmpxchg.org, cuitao@kylinos.cn,chris@chrisdown.name,alireza@asgari.net,zhuhui@kylinos.cn, akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <1ef1fa130f9bd4a94bf92335486729f05034c30d.1796367145.git.zhuhui@kylinos.cn> References: <1ef1fa130f9bd4a94bf92335486729f05034c30d.1796367145.git.zhuhui@kylinos.cn> Subject: + mm-memcg-fix-zero-throttle-delay-on-32-bit-kernels.patch added to mm-new branch Message-Id: <20261205073217.C486D1F0092B@smtp.kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: mm: memcg: fix zero throttle delay on 32-bit kernels has been added to the -mm mm-new branch. Its filename is mm-memcg-fix-zero-throttle-delay-on-32-bit-kernels.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-memcg-fix-zero-throttle-delay-on-32-bit-kernels.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: Hui Zhu Subject: mm: memcg: fix zero throttle delay on 32-bit kernels Date: Fri, 04 Dec 2026 15:18:19 +0800 Patch series "mm: memcg: fix memory.high allocator throttling", v2. calculate_high_delay() turns how far a cgroup is over memory.high or memory.swap.high into a sleep penalty. Two independent defects corrupt that penalty, and since the caller treats "penalty_jiffies <= HZ / 100" as "nothing to do", a small result silently skips both the throttle and the MAX_RECLAIM_RETRIES reclaim loop. 1/2: the u64 product is stored into an unsigned long before being shifted right 34 bits, so on 32-bit kernels it truncates to zero and throttling is completely inert there. Broken since v5.6. 2/2: the u64 product itself wraps once a cgroup is about 130x over its limit (at HZ=1000), leaving an arbitrary result that can be exactly zero. memory.high has no lower bound, so a one-page limit with a few MB of usage gets there. Affects 64-bit kernels too. Broken since v5.4. v2 reworks both per Johannes Weiner's review [3] of Zhang Jiao's earlier patch [1]: the v1 overage cap is replaced by check_mul_overflow(), and calculate_high_delay() and the caller's penalty_jiffies are now u64, so the value is narrowed only after the caller's clamp. That also drops v1's in-function min(), which was undoing commit ff144e69f733 ("mm/memcg: move penalty delay clamping out of calculate_high_delay()"). The series is now 9 insertions and 5 deletions instead of 19 and 2. The two problems stay separate patches: different regressions with different Fixes tags and stable lifetimes (e26733e0d0ec, v5.6, for the 32-bit truncation; 0e4b01df8659, v5.4, for the overflow). Both are Cc'd to stable. This series consolidates the earlier duplicate work: Song Hu reported the overflow, proposed check_mul_overflow() [2] and co-developed the fix, and Zhang Jiao posted the first fix [1]. I offered Zhang Jiao a combined series with the overflow fix under his name and followed up a week later, but had no reply, so I am carrying it forward under my own name with credit to both. Verified: built for arm64 and for arm (multi_v7_defconfig plus MEMCG) with W=1, no warnings; checkpatch --strict is clean. The arithmetic matches exact 128-bit results across the whole tuning table and a 28M-case sweep: the reworked version is correct on every case, while the current code is wrong on 1439 of them at 64-bit and on all of them at 32-bit. Neither patch was run on real 32-bit hardware. This patch (of 2): calculate_high_delay() stores max_overage * max_overage * HZ, computed as u64, into an unsigned long before shifting it right by 34 bits in total. On 32-bit kernels the store truncates the value to its low 32 bits, so the shift always yields zero: memory.high and memory.swap.high throttling is completely inert there. And since the caller reads "penalty_jiffies <= HZ / 100" as "nothing to do", the MAX_RECLAIM_RETRIES reclaim loop is skipped as well. Keep the intermediate in u64 so the shifts see the full width. Also make the function return u64, and the caller's penalty_jiffies u64, so the value is narrowed only after the caller has clamped it to MEMCG_MAX_HIGH_DELAY_JIFFIES. Nothing changes on 64-bit kernels, where unsigned long is already 64 bits wide. Link: https://lore.kernel.org/cover.1796367145.git.zhuhui@kylinos.cn Link: https://patch.msgid.link/1ef1fa130f9bd4a94bf92335486729f05034c30d.1796367145.git.zhuhui@kylinos.cn Fixes: e26733e0d0ec ("mm, memcg: throttle allocators based on ancestral memory.high") Signed-off-by: Hui Zhu Signed-off-by: Andrew Morton Acked-by: Shakeel Butt Reviewed-by: Johannes Weiner Cc: Michal Hocko Cc: Roman Gushchin Cc: Muchun Song Cc: Chris Down Cc: Alireza Asgari Cc: zhang jiao Cc: Song Hu Cc: Tao Cui Cc: mm/memcontrol.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/mm/memcontrol.c~mm-memcg-fix-zero-throttle-delay-on-32-bit-kernels +++ a/mm/memcontrol.c @@ -2623,10 +2623,10 @@ static u64 swap_find_max_overage(struct * Get the number of jiffies that we should penalise a mischievous cgroup which * is exceeding its memory.high by checking both it and its ancestors. */ -static unsigned long calculate_high_delay(unsigned int nr_pages, - u64 max_overage) +static u64 calculate_high_delay(unsigned int nr_pages, + u64 max_overage) { - unsigned long penalty_jiffies; + u64 penalty_jiffies; if (!max_overage) return 0; @@ -2660,7 +2660,7 @@ static unsigned long calculate_high_dela */ void __mem_cgroup_handle_over_high(gfp_t gfp_mask) { - unsigned long penalty_jiffies; + u64 penalty_jiffies; unsigned long pflags; unsigned long nr_reclaimed; unsigned int nr_pages = current->memcg_nr_pages_over_high; _ Patches currently in -mm which might be from zhuhui@kylinos.cn are mm-vmstat-annotate-data-race-in-zone_page_state_snapshot.patch mm-mglru-use-a-smaller-batch-in-fill-drain_evictable.patch mm-mglru-reset-the-mm-iteration-cursor-in-try_to_inc_max_seq_nowalk.patch mm-compaction-annotate-data-race-for-zone-free_areanr_free.patch mm-memcg-fix-zero-throttle-delay-on-32-bit-kernels.patch mm-memcg-fix-memoryhigh-throttle-lost-to-u64-overflow.patch