Re: [PATCH 1/2] mm: memcg: fix zero throttle delay on 32-bit kernels
From: Joshua Hahn
Date: Tue Nov 17 2026 - 18:57:46 EST
On Tue, Nov 17, 2026 at 04:04:20PM +0800, Hui Zhu wrote:
> From: Hui Zhu <zhuhui@xxxxxxxxxx>
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@xxxxxxxxxxxxxxx
>
> Signed-off-by: Hui Zhu <zhuhui@xxxxxxxxxx>
> ---
> 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
>
>