Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
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,
	cui.tao@linux.dev,cuitao@kylinos.cn,chris@chrisdown.name,alireza@asgari.net,
	zhuhui@kylinos.cn,akpm@linux-foundation.org
Subject: + mm-memcg-fix-memoryhigh-throttle-lost-to-u64-overflow.patch added to mm-new branch
Date: Fri, 04 Dec 2026 23:32:19 -0800	[thread overview]
Message-ID: <20261205073220.205DA1F00936@smtp.kernel.org> (raw)
In-Reply-To: <32198723709067dfefc0d7048e03586a25714453.1796367145.git.zhuhui@kylinos.cn>


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


      parent reply	other threads:[~2026-12-05  7:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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   ` 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=20261205073220.205DA1F00936@smtp.kernel.org \
    --to=akpm@linux-foundation.org \
    --cc=alireza@asgari.net \
    --cc=chris@chrisdown.name \
    --cc=cui.tao@linux.dev \
    --cc=cuitao@kylinos.cn \
    --cc=hannes@cmpxchg.org \
    --cc=husong@kylinos.cn \
    --cc=mhocko@kernel.org \
    --cc=mm-commits@vger.kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=zhangjiao2@cmss.chinamobile.com \
    --cc=zhuhui@kylinos.cn \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox