Re: [patch] mm, page_alloc: reintroduce page allocation stall warning

Andrew Morton
2026-03-30T03:17:38Z

On Sun, 29 Mar 2026 18:08:52 -0700 (PDT) David Rientjes <rientjes@google.com> wrote:

> Previously, we had warnings when a single page allocation took longer
> than reasonably expected. This was introduced in commit 63f53dea0c98
> ("mm: warn about allocations which stall for too long").
>
> The warning was subsequently reverted in commit 400e22499dd9 ("mm: don't
> warn about allocations which stall for too long") but for reasons
> unrelated to the warning itself.
>
> Page allocation stalls in excess of 10 seconds are always useful to debug
> because they can result in severe userspace unresponsiveness. Adding
> this artifact can be used to correlate with userspace going out to lunch
> and to understand the state of memory at the time.
>
> There should be a reasonable expectation that this warning will never
> trigger given it is very passive, it will only be emitted when a page
> allocation takes longer than 10 seconds. If it does trigger, this
> reveals an issue that should be fixed: a single page allocation should
> never loop for more than 10 seconds without oom killing to make memory
> available.
>
> Unlike the original implementation, this implementation only reports
> stalls once for the system every 10 seconds. Otherwise, many concurrent
> reclaimers could spam the kernel log unnecessarily. Stalls are only
> reported when calling into direct reclaim.
>
> ...
>
> +static void check_alloc_stall_warn(gfp_t gfp_mask, nodemask_t *nodemask,
> + unsigned int order, unsigned long alloc_start_time)
> +{
> + static DEFINE_SPINLOCK(alloc_stall_lock);
> + unsigned long stall_msecs = jiffies_to_msecs(jiffies - alloc_start_time);
> +
> + if (likely(stall_msecs < ALLOC_STALL_WARN_MSECS))
> + return;
> + if (time_before(jiffies, READ_ONCE(alloc_stall_warn_jiffies)))
> + return;
> + if (gfp_mask & __GFP_NOWARN)
> + return;
> +
> + if (!spin_trylock(&alloc_stall_lock))
> + return;
> +
> + if (time_after_eq(jiffies, alloc_stall_warn_jiffies)) {
> + WRITE_ONCE(alloc_stall_warn_jiffies,
> + jiffies + msecs_to_jiffies(ALLOC_STALL_WARN_MSECS));
> + spin_unlock(&alloc_stall_lock);
> +
> + pr_warn("%s: page allocation stall for %lu secs: order:%d, mode:%#x(%pGg) nodemask=%*pbl",
> + current->comm, stall_msecs / MSEC_PER_SEC, order, gfp_mask, &gfp_mask,
> + nodemask_pr_args(nodemask));

Snould we use dump_page() in here? It prints more info, does the
snapshotting thing.

> + cpuset_print_current_mems_allowed();
> + pr_cont("\n");
> + dump_stack();
> + warn_alloc_show_mem(gfp_mask, nodemask);
> + return;
> + }
> +
> + spin_unlock(&alloc_stall_lock);
> +}
> +