From: Joshua Hahn <joshua.hahnjy@gmail.com>
To: Hui Zhu <hui.zhu@linux.dev>
Cc: Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Muchun Song <muchun.song@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
Chris Down <chris@chrisdown.name>,
cgroups@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, Hui Zhu <zhuhui@kylinos.cn>,
stable@vger.kernel.org
Subject: Re: [PATCH 1/2] mm: memcg: fix zero throttle delay on 32-bit kernels
Date: Tue, 17 Nov 2026 15:57:31 -0800 [thread overview]
Message-ID: <avznwfoMxq9s2NwC@devbig011.atn3.facebook.com> (raw)
In-Reply-To: <6931674296b98139f5e02821d66ad1855eba36c9.1794902513.git.zhuhui@kylinos.cn>
On Tue, Nov 17, 2026 at 04:04:20PM +0800, Hui Zhu wrote:
> From: Hui Zhu <zhuhui@kylinos.cn>
Hello, thanks for the patch.
> 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 first, so the shift always
> yields zero. Tasks over memory.high or memory.swap.high are then never
> throttled, and the reclaim retry loop in __mem_cgroup_handle_over_high()
> is skipped as well.
>
> Keep the intermediate in u64 so the shifts see the full width, and clamp
> to MEMCG_MAX_HIGH_DELAY_JIFFIES before narrowing to the unsigned long
> return value: a truncated result would escape the caller's own min().
> Nothing changes on 64-bit kernels, where clamping each term is equivalent
> to clamping their sum, which the caller already does.
>
> Fixes: e26733e0d0ec ("mm, memcg: throttle allocators based on ancestral memory.high")
Is this the right fixes tag? That one doesn't introduce the division by
MEMCG_CHARGE_BATCH.
> Cc: stable@vger.kernel.org
>
> Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
> ---
> mm/memcontrol.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 84f4a8fd4d16..1ba42724ed1e 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -2576,7 +2576,7 @@ static u64 swap_find_max_overage(struct mem_cgroup *memcg)
> static unsigned long calculate_high_delay(unsigned int nr_pages,
> u64 max_overage)
> {
> - unsigned long penalty_jiffies;
> + u64 penalty_jiffies;
>
> if (!max_overage)
> return 0;
> @@ -2601,7 +2601,13 @@ static unsigned long calculate_high_delay(unsigned int nr_pages,
> * MEMCG_CHARGE_BATCH pages is nominal, so work out how much smaller or
> * larger the current charge patch is than that.
> */
> - return penalty_jiffies * nr_pages / MEMCG_CHARGE_BATCH;
> + penalty_jiffies = penalty_jiffies * nr_pages / MEMCG_CHARGE_BATCH;
> +
> + /*
> + * Clamp before narrowing to unsigned long: a truncated return value
> + * would escape the caller's min() and look like a small delay.
> + */
I think this is a bit verbose for what is happening here.
Why not:
return min_t(u64, penalty_jiffies * nr_pages / MEMCG_CHARGE_BATCH,
MEMCG_MAX_HIGH_DELAY_JIFFIES);
Or just dropping the comment block seems fine. I think folks should be
familiar enough with values wrapping around.
Thanks, have a great day!
Joshua
> + return min_t(u64, penalty_jiffies, MEMCG_MAX_HIGH_DELAY_JIFFIES);
> }
>
> /*
> --
> 2.53.0
>
>
next prev parent reply other threads:[~2026-11-17 23:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 8:04 [PATCH 0/2] mm: memcg: fix memory.high allocator throttling Hui Zhu
2026-11-17 8:04 ` [PATCH 1/2] mm: memcg: fix zero throttle delay on 32-bit kernels Hui Zhu
2026-11-17 23:57 ` Joshua Hahn [this message]
2026-11-17 8:04 ` [PATCH 2/2] mm: memcg: fix memory.high throttle lost to u64 overflow Hui Zhu
2026-11-17 22:17 ` [PATCH 0/2] mm: memcg: fix memory.high allocator throttling Chris Down
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=avznwfoMxq9s2NwC@devbig011.atn3.facebook.com \
--to=joshua.hahnjy@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=chris@chrisdown.name \
--cc=hannes@cmpxchg.org \
--cc=hui.zhu@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=stable@vger.kernel.org \
--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