* [PATCH v2 1/2] mm: memcg: fix zero throttle delay on 32-bit kernels [not found] <cover.1796367145.git.zhuhui@kylinos.cn> @ 2026-12-04 7:18 ` Hui Zhu 2026-12-04 14:02 ` Johannes Weiner ` (2 more replies) 2026-12-04 7:18 ` [PATCH v2 2/2] mm: memcg: fix memory.high throttle lost to u64 overflow Hui Zhu 1 sibling, 3 replies; 10+ messages in thread From: Hui Zhu @ 2026-12-04 7:18 UTC (permalink / raw) To: Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt, Muchun Song, Andrew Morton, Chris Down, zhangjiao2, Alireza Asgari, cgroups, linux-mm, linux-kernel Cc: Hui Zhu, stable From: Hui Zhu <zhuhui@kylinos.cn> 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. Fixes: e26733e0d0ec ("mm, memcg: throttle allocators based on ancestral memory.high") Cc: stable@vger.kernel.org Signed-off-by: Hui Zhu <zhuhui@kylinos.cn> --- mm/memcontrol.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 84f4a8fd4d16..2625107a1096 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2573,10 +2573,10 @@ static u64 swap_find_max_overage(struct mem_cgroup *memcg) * 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; @@ -2611,7 +2611,7 @@ static unsigned long calculate_high_delay(unsigned int nr_pages, */ 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; -- 2.53.0 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/2] mm: memcg: fix zero throttle delay on 32-bit kernels 2026-12-04 7:18 ` [PATCH v2 1/2] mm: memcg: fix zero throttle delay on 32-bit kernels Hui Zhu @ 2026-12-04 14:02 ` Johannes Weiner 2026-12-04 16:30 ` Shakeel Butt 2026-12-05 7:32 ` + mm-memcg-fix-zero-throttle-delay-on-32-bit-kernels.patch added to mm-new branch Andrew Morton 2 siblings, 0 replies; 10+ messages in thread From: Johannes Weiner @ 2026-12-04 14:02 UTC (permalink / raw) To: Hui Zhu Cc: Michal Hocko, Roman Gushchin, Shakeel Butt, Muchun Song, Andrew Morton, Chris Down, zhangjiao2, Alireza Asgari, cgroups, linux-mm, linux-kernel, Hui Zhu, stable On Fri, Dec 04, 2026 at 03:18:19PM +0800, Hui Zhu wrote: > From: Hui Zhu <zhuhui@kylinos.cn> > > 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. > > Fixes: e26733e0d0ec ("mm, memcg: throttle allocators based on ancestral memory.high") > Cc: stable@vger.kernel.org > Signed-off-by: Hui Zhu <zhuhui@kylinos.cn> Reviewed-by: Johannes Weiner <hannes@cmpxchg.org> ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/2] mm: memcg: fix zero throttle delay on 32-bit kernels 2026-12-04 7:18 ` [PATCH v2 1/2] mm: memcg: fix zero throttle delay on 32-bit kernels Hui Zhu 2026-12-04 14:02 ` Johannes Weiner @ 2026-12-04 16:30 ` Shakeel Butt 2026-12-05 7:32 ` + mm-memcg-fix-zero-throttle-delay-on-32-bit-kernels.patch added to mm-new branch Andrew Morton 2 siblings, 0 replies; 10+ messages in thread From: Shakeel Butt @ 2026-12-04 16:30 UTC (permalink / raw) To: Hui Zhu Cc: Johannes Weiner, Michal Hocko, Roman Gushchin, Muchun Song, Andrew Morton, Chris Down, zhangjiao2, Alireza Asgari, cgroups, linux-mm, linux-kernel, Hui Zhu, stable On Fri, Dec 04, 2026 at 03:18:19PM +0800, Hui Zhu wrote: > From: Hui Zhu <zhuhui@kylinos.cn> > > 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. > > Fixes: e26733e0d0ec ("mm, memcg: throttle allocators based on ancestral memory.high") > Cc: stable@vger.kernel.org > Signed-off-by: Hui Zhu <zhuhui@kylinos.cn> Acked-by: Shakeel Butt <shakeel.butt@linux.dev> ^ permalink raw reply [flat|nested] 10+ messages in thread
* + mm-memcg-fix-zero-throttle-delay-on-32-bit-kernels.patch added to mm-new branch 2026-12-04 7:18 ` [PATCH v2 1/2] mm: memcg: fix zero throttle delay on 32-bit kernels Hui Zhu 2026-12-04 14:02 ` Johannes Weiner 2026-12-04 16:30 ` Shakeel Butt @ 2026-12-05 7:32 ` Andrew Morton 2 siblings, 0 replies; 10+ messages in thread From: Andrew Morton @ 2026-12-05 7:32 UTC (permalink / raw) To: mm-commits, zhangjiao2, stable, shakeel.butt, roman.gushchin, muchun.song, mhocko, husong, hannes, cuitao, chris, alireza, zhuhui, akpm 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 <zhuhui@kylinos.cn> 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 <zhuhui@kylinos.cn> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: Shakeel Butt <shakeel.butt@linux.dev> Reviewed-by: 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: Chris Down <chris@chrisdown.name> Cc: Alireza Asgari <alireza@asgari.net> Cc: zhang jiao <zhangjiao2@cmss.chinamobile.com> Cc: Song Hu <husong@kylinos.cn> Cc: Tao Cui <cuitao@kylinos.cn> Cc: <stable@vger.kernel.org> 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 2/2] mm: memcg: fix memory.high throttle lost to u64 overflow [not found] <cover.1796367145.git.zhuhui@kylinos.cn> 2026-12-04 7:18 ` [PATCH v2 1/2] mm: memcg: fix zero throttle delay on 32-bit kernels Hui Zhu @ 2026-12-04 7:18 ` Hui Zhu 2026-12-04 14:03 ` Johannes Weiner ` (4 more replies) 1 sibling, 5 replies; 10+ messages in thread From: Hui Zhu @ 2026-12-04 7:18 UTC (permalink / raw) To: Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt, Muchun Song, Andrew Morton, Chris Down, zhangjiao2, Alireza Asgari, cgroups, linux-mm, linux-kernel Cc: Hui Zhu, stable, Song Hu From: Hui Zhu <zhuhui@kylinos.cn> calculate_high_delay() squares max_overage and scales it by HZ in u64. max_overage is the ratio ((usage - high) << 20) / high, and memory.high has no lower bound, so the product wraps once a cgroup is about 130x over its limit (at HZ=1000). The wrapped value is arbitrary and can be exactly zero: with memory.high set to one page and usage at 2049 pages, max_overage is 2^31, the product wraps to zero and the penalty comes out 0 jiffies instead of the 2 seconds the formula calls for. The caller then takes its "penalty_jiffies <= HZ / 100" exit, skipping both the throttle and the reclaim retry loop. Use check_mul_overflow() for the two multiplications and return MEMCG_MAX_HIGH_DELAY_JIFFIES when either of them wraps. An overflow means the exact product is at least 2^64, so the delay is past its cap even when nr_pages is a single page, and the caller clamps to the same value anyway. Song Hu reported this and proposed check_mul_overflow(). Zhang Jiao posted an earlier fix using an overage cap; per Johannes Weiner's review this version uses check_mul_overflow() instead. Fixes: 0e4b01df8659 ("mm, memcg: throttle allocators when failing reclaim over memory.high") Link: https://lore.kernel.org/all/20260818012115.65838-1-husong@kylinos.cn/ Link: https://lore.kernel.org/all/20261029073857.974-1-zhangjiao2@cmss.chinamobile.com/ Cc: stable@vger.kernel.org Co-developed-by: Song Hu <husong@kylinos.cn> Signed-off-by: Song Hu <husong@kylinos.cn> Signed-off-by: Hui Zhu <zhuhui@kylinos.cn> --- mm/memcontrol.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 2625107a1096..85b6654e254f 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2589,7 +2589,11 @@ static u64 calculate_high_delay(unsigned int nr_pages, * its crazy behaviour, so we exponentially increase the delay based on * overage amount. */ - penalty_jiffies = max_overage * max_overage * HZ; + /* An overflow puts the delay far past the cap the caller applies. */ + if (check_mul_overflow(max_overage, max_overage, &penalty_jiffies) || + check_mul_overflow(penalty_jiffies, (u64)HZ, &penalty_jiffies)) + return MEMCG_MAX_HIGH_DELAY_JIFFIES; + penalty_jiffies >>= MEMCG_DELAY_PRECISION_SHIFT; penalty_jiffies >>= MEMCG_DELAY_SCALING_SHIFT; -- 2.53.0 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2 2/2] mm: memcg: fix memory.high throttle lost to u64 overflow 2026-12-04 7:18 ` [PATCH v2 2/2] mm: memcg: fix memory.high throttle lost to u64 overflow Hui Zhu @ 2026-12-04 14:03 ` Johannes Weiner 2026-12-04 16:36 ` Shakeel Butt ` (3 subsequent siblings) 4 siblings, 0 replies; 10+ messages in thread From: Johannes Weiner @ 2026-12-04 14:03 UTC (permalink / raw) To: Hui Zhu Cc: Michal Hocko, Roman Gushchin, Shakeel Butt, Muchun Song, Andrew Morton, Chris Down, zhangjiao2, Alireza Asgari, cgroups, linux-mm, linux-kernel, Hui Zhu, stable, Song Hu On Fri, Dec 04, 2026 at 03:18:20PM +0800, Hui Zhu wrote: > From: Hui Zhu <zhuhui@kylinos.cn> > > calculate_high_delay() squares max_overage and scales it by HZ in u64. > max_overage is the ratio ((usage - high) << 20) / high, and memory.high has > no lower bound, so the product wraps once a cgroup is about 130x over its > limit (at HZ=1000). The wrapped value is arbitrary and can be exactly zero: > with memory.high set to one page and usage at 2049 pages, max_overage is > 2^31, the product wraps to zero and the penalty comes out 0 jiffies instead > of the 2 seconds the formula calls for. The caller then takes its > "penalty_jiffies <= HZ / 100" exit, skipping both the throttle and the > reclaim retry loop. > > Use check_mul_overflow() for the two multiplications and return > MEMCG_MAX_HIGH_DELAY_JIFFIES when either of them wraps. An overflow means > the exact product is at least 2^64, so the delay is past its cap even when > nr_pages is a single page, and the caller clamps to the same value anyway. > > Song Hu reported this and proposed check_mul_overflow(). Zhang Jiao posted > an earlier fix using an overage cap; per Johannes Weiner's review this > version uses check_mul_overflow() instead. > > Fixes: 0e4b01df8659 ("mm, memcg: throttle allocators when failing reclaim over memory.high") > Link: https://lore.kernel.org/all/20260818012115.65838-1-husong@kylinos.cn/ > Link: https://lore.kernel.org/all/20261029073857.974-1-zhangjiao2@cmss.chinamobile.com/ > Cc: stable@vger.kernel.org > Co-developed-by: Song Hu <husong@kylinos.cn> > Signed-off-by: Song Hu <husong@kylinos.cn> > Signed-off-by: Hui Zhu <zhuhui@kylinos.cn> Reviewed-by: Johannes Weiner <hannes@cmpxchg.org> Andrew, could you please pick those for 7.4 still? ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 2/2] mm: memcg: fix memory.high throttle lost to u64 overflow 2026-12-04 7:18 ` [PATCH v2 2/2] mm: memcg: fix memory.high throttle lost to u64 overflow Hui Zhu 2026-12-04 14:03 ` Johannes Weiner @ 2026-12-04 16:36 ` Shakeel Butt 2026-12-05 4:28 ` Tao Cui ` (2 subsequent siblings) 4 siblings, 0 replies; 10+ messages in thread From: Shakeel Butt @ 2026-12-04 16:36 UTC (permalink / raw) To: Hui Zhu Cc: Johannes Weiner, Michal Hocko, Roman Gushchin, Muchun Song, Andrew Morton, Chris Down, zhangjiao2, Alireza Asgari, cgroups, linux-mm, linux-kernel, Hui Zhu, stable, Song Hu On Fri, Dec 04, 2026 at 03:18:20PM +0800, Hui Zhu wrote: > From: Hui Zhu <zhuhui@kylinos.cn> > > calculate_high_delay() squares max_overage and scales it by HZ in u64. > max_overage is the ratio ((usage - high) << 20) / high, and memory.high has > no lower bound, so the product wraps once a cgroup is about 130x over its > limit (at HZ=1000). The wrapped value is arbitrary and can be exactly zero: > with memory.high set to one page and usage at 2049 pages, max_overage is > 2^31, the product wraps to zero and the penalty comes out 0 jiffies instead > of the 2 seconds the formula calls for. The caller then takes its > "penalty_jiffies <= HZ / 100" exit, skipping both the throttle and the > reclaim retry loop. > > Use check_mul_overflow() for the two multiplications and return > MEMCG_MAX_HIGH_DELAY_JIFFIES when either of them wraps. An overflow means > the exact product is at least 2^64, so the delay is past its cap even when > nr_pages is a single page, and the caller clamps to the same value anyway. > > Song Hu reported this and proposed check_mul_overflow(). Zhang Jiao posted > an earlier fix using an overage cap; per Johannes Weiner's review this > version uses check_mul_overflow() instead. > > Fixes: 0e4b01df8659 ("mm, memcg: throttle allocators when failing reclaim over memory.high") > Link: https://lore.kernel.org/all/20260818012115.65838-1-husong@kylinos.cn/ > Link: https://lore.kernel.org/all/20261029073857.974-1-zhangjiao2@cmss.chinamobile.com/ > Cc: stable@vger.kernel.org > Co-developed-by: Song Hu <husong@kylinos.cn> > Signed-off-by: Song Hu <husong@kylinos.cn> > Signed-off-by: Hui Zhu <zhuhui@kylinos.cn> Acked-by: Shakeel Butt <shakeel.butt@linux.dev> ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 2/2] mm: memcg: fix memory.high throttle lost to u64 overflow 2026-12-04 7:18 ` [PATCH v2 2/2] mm: memcg: fix memory.high throttle lost to u64 overflow Hui Zhu 2026-12-04 14:03 ` Johannes Weiner 2026-12-04 16:36 ` Shakeel Butt @ 2026-12-05 4:28 ` Tao Cui 2026-12-05 5:58 ` Muchun Song 2026-12-05 7:32 ` + mm-memcg-fix-memoryhigh-throttle-lost-to-u64-overflow.patch added to mm-new branch Andrew Morton 4 siblings, 0 replies; 10+ messages in thread From: Tao Cui @ 2026-12-05 4:28 UTC (permalink / raw) To: Hui Zhu, Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt, Muchun Song, Andrew Morton, Chris Down, zhangjiao2, Alireza Asgari, cgroups, linux-mm, linux-kernel Cc: cui.tao, Hui Zhu, stable, Song Hu 在 2026/12/4 15:18, Hui Zhu 写道: > From: Hui Zhu <zhuhui@kylinos.cn> > > calculate_high_delay() squares max_overage and scales it by HZ in u64. > max_overage is the ratio ((usage - high) << 20) / high, and memory.high has > no lower bound, so the product wraps once a cgroup is about 130x over its > limit (at HZ=1000). The wrapped value is arbitrary and can be exactly zero: > with memory.high set to one page and usage at 2049 pages, max_overage is > 2^31, the product wraps to zero and the penalty comes out 0 jiffies instead > of the 2 seconds the formula calls for. The caller then takes its > "penalty_jiffies <= HZ / 100" exit, skipping both the throttle and the > reclaim retry loop. > > Use check_mul_overflow() for the two multiplications and return > MEMCG_MAX_HIGH_DELAY_JIFFIES when either of them wraps. An overflow means > the exact product is at least 2^64, so the delay is past its cap even when > nr_pages is a single page, and the caller clamps to the same value anyway. > > Song Hu reported this and proposed check_mul_overflow(). Zhang Jiao posted > an earlier fix using an overage cap; per Johannes Weiner's review this > version uses check_mul_overflow() instead. > > Fixes: 0e4b01df8659 ("mm, memcg: throttle allocators when failing reclaim over memory.high") > Link: https://lore.kernel.org/all/20260818012115.65838-1-husong@kylinos.cn/ > Link: https://lore.kernel.org/all/20261029073857.974-1-zhangjiao2@cmss.chinamobile.com/ > Cc: stable@vger.kernel.org > Co-developed-by: Song Hu <husong@kylinos.cn> > Signed-off-by: Song Hu <husong@kylinos.cn> > Signed-off-by: Hui Zhu <zhuhui@kylinos.cn> > --- Reviewed-by: Tao Cui <cuitao@kylinos.cn> ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 2/2] mm: memcg: fix memory.high throttle lost to u64 overflow 2026-12-04 7:18 ` [PATCH v2 2/2] mm: memcg: fix memory.high throttle lost to u64 overflow Hui Zhu ` (2 preceding siblings ...) 2026-12-05 4:28 ` Tao Cui @ 2026-12-05 5:58 ` Muchun Song 2026-12-05 7:32 ` + mm-memcg-fix-memoryhigh-throttle-lost-to-u64-overflow.patch added to mm-new branch Andrew Morton 4 siblings, 0 replies; 10+ messages in thread From: Muchun Song @ 2026-12-05 5:58 UTC (permalink / raw) To: Hui Zhu Cc: Muchun Song, Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt, Andrew Morton, Chris Down, zhangjiao2, Alireza Asgari, cgroups, linux-mm, linux-kernel, Hui Zhu, stable, Song Hu > On Dec 4, 2026, at 15:18, Hui Zhu <hui.zhu@linux.dev> wrote: > > From: Hui Zhu <zhuhui@kylinos.cn> > > calculate_high_delay() squares max_overage and scales it by HZ in u64. > max_overage is the ratio ((usage - high) << 20) / high, and memory.high has > no lower bound, so the product wraps once a cgroup is about 130x over its > limit (at HZ=1000). The wrapped value is arbitrary and can be exactly zero: > with memory.high set to one page and usage at 2049 pages, max_overage is > 2^31, the product wraps to zero and the penalty comes out 0 jiffies instead > of the 2 seconds the formula calls for. The caller then takes its > "penalty_jiffies <= HZ / 100" exit, skipping both the throttle and the > reclaim retry loop. > > Use check_mul_overflow() for the two multiplications and return > MEMCG_MAX_HIGH_DELAY_JIFFIES when either of them wraps. An overflow means > the exact product is at least 2^64, so the delay is past its cap even when > nr_pages is a single page, and the caller clamps to the same value anyway. > > Song Hu reported this and proposed check_mul_overflow(). Zhang Jiao posted > an earlier fix using an overage cap; per Johannes Weiner's review this > version uses check_mul_overflow() instead. > > Fixes: 0e4b01df8659 ("mm, memcg: throttle allocators when failing reclaim over memory.high") > Link: https://lore.kernel.org/all/20260818012115.65838-1-husong@kylinos.cn/ > Link: https://lore.kernel.org/all/20261029073857.974-1-zhangjiao2@cmss.chinamobile.com/ > Cc: stable@vger.kernel.org > Co-developed-by: Song Hu <husong@kylinos.cn> > Signed-off-by: Song Hu <husong@kylinos.cn> > Signed-off-by: Hui Zhu <zhuhui@kylinos.cn> Acked-by: Muchun Song (ByteDance) <muchun.song@linux.dev> Thanks. ^ permalink raw reply [flat|nested] 10+ messages in thread
* + mm-memcg-fix-memoryhigh-throttle-lost-to-u64-overflow.patch added to mm-new branch 2026-12-04 7:18 ` [PATCH v2 2/2] mm: memcg: fix memory.high throttle lost to u64 overflow Hui Zhu ` (3 preceding siblings ...) 2026-12-05 5:58 ` Muchun Song @ 2026-12-05 7:32 ` Andrew Morton 4 siblings, 0 replies; 10+ messages in thread From: Andrew Morton @ 2026-12-05 7:32 UTC (permalink / raw) To: mm-commits, zhangjiao2, stable, shakeel.butt, roman.gushchin, muchun.song, mhocko, husong, hannes, cui.tao, cuitao, chris, alireza, zhuhui, akpm The patch titled Subject: mm: memcg: fix memory.high throttle lost to u64 overflow has been added to the -mm mm-new branch. Its filename is mm-memcg-fix-memoryhigh-throttle-lost-to-u64-overflow.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-memoryhigh-throttle-lost-to-u64-overflow.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 <zhuhui@kylinos.cn> Subject: mm: memcg: fix memory.high throttle lost to u64 overflow Date: Fri, 04 Dec 2026 15:18:20 +0800 calculate_high_delay() squares max_overage and scales it by HZ in u64. max_overage is the ratio ((usage - high) << 20) / high, and memory.high has no lower bound, so the product wraps once a cgroup is about 130x over its limit (at HZ=1000). The wrapped value is arbitrary and can be exactly zero: with memory.high set to one page and usage at 2049 pages, max_overage is 2^31, the product wraps to zero and the penalty comes out 0 jiffies instead of the 2 seconds the formula calls for. The caller then takes its "penalty_jiffies <= HZ / 100" exit, skipping both the throttle and the reclaim retry loop. Use check_mul_overflow() for the two multiplications and return MEMCG_MAX_HIGH_DELAY_JIFFIES when either of them wraps. An overflow means the exact product is at least 2^64, so the delay is past its cap even when nr_pages is a single page, and the caller clamps to the same value anyway. Song Hu reported this and proposed check_mul_overflow(). Zhang Jiao posted an earlier fix using an overage cap; per Johannes Weiner's review this version uses check_mul_overflow() instead. Link: https://patch.msgid.link/32198723709067dfefc0d7048e03586a25714453.1796367145.git.zhuhui@kylinos.cn Link: https://lore.kernel.org/all/20260818012115.65838-1-husong@kylinos.cn/ Link: https://lore.kernel.org/all/20261029073857.974-1-zhangjiao2@cmss.chinamobile.com/ Fixes: 0e4b01df8659 ("mm, memcg: throttle allocators when failing reclaim over memory.high") Signed-off-by: Song Hu <husong@kylinos.cn> Signed-off-by: Hui Zhu <zhuhui@kylinos.cn> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Co-developed-by: Song Hu <husong@kylinos.cn> Acked-by: Muchun Song (ByteDance) <muchun.song@linux.dev> Acked-by: Shakeel Butt <shakeel.butt@linux.dev> Reviewed-by: Johannes Weiner <hannes@cmpxchg.org> Reviewed-by: Tao Cui <cuitao@kylinos.cn> Cc: Michal Hocko <mhocko@kernel.org> Cc: Roman Gushchin <roman.gushchin@linux.dev> Cc: Chris Down <chris@chrisdown.name> Cc: Alireza Asgari <alireza@asgari.net> Cc: zhang jiao <zhangjiao2@cmss.chinamobile.com> Cc: Tao Cui <cui.tao@linux.dev> Cc: <stable@vger.kernel.org> mm/memcontrol.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/mm/memcontrol.c~mm-memcg-fix-memoryhigh-throttle-lost-to-u64-overflow +++ a/mm/memcontrol.c @@ -2639,7 +2639,11 @@ static u64 calculate_high_delay(unsigned * its crazy behaviour, so we exponentially increase the delay based on * overage amount. */ - penalty_jiffies = max_overage * max_overage * HZ; + /* An overflow puts the delay far past the cap the caller applies. */ + if (check_mul_overflow(max_overage, max_overage, &penalty_jiffies) || + check_mul_overflow(penalty_jiffies, (u64)HZ, &penalty_jiffies)) + return MEMCG_MAX_HIGH_DELAY_JIFFIES; + penalty_jiffies >>= MEMCG_DELAY_PRECISION_SHIFT; penalty_jiffies >>= MEMCG_DELAY_SCALING_SHIFT; _ 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-12-05 7:32 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <cover.1796367145.git.zhuhui@kylinos.cn>
2026-12-04 7:18 ` [PATCH v2 1/2] mm: memcg: fix zero throttle delay on 32-bit kernels Hui Zhu
2026-12-04 14:02 ` Johannes Weiner
2026-12-04 16:30 ` Shakeel Butt
2026-12-05 7:32 ` + mm-memcg-fix-zero-throttle-delay-on-32-bit-kernels.patch added to mm-new branch Andrew Morton
2026-12-04 7:18 ` [PATCH v2 2/2] mm: memcg: fix memory.high throttle lost to u64 overflow Hui Zhu
2026-12-04 14:03 ` Johannes Weiner
2026-12-04 16:36 ` Shakeel Butt
2026-12-05 4:28 ` Tao Cui
2026-12-05 5:58 ` Muchun Song
2026-12-05 7:32 ` + mm-memcg-fix-memoryhigh-throttle-lost-to-u64-overflow.patch added to mm-new branch Andrew Morton
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox