public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
From: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
To: David Rientjes <rientjes@google.com>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	Brendan Jackman <jackmanb@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>, Zi Yan <ziy@nvidia.com>,
	Petr Mladek <pmladek@suse.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [patch] mm, page_alloc: reintroduce page allocation stall warning
Date: Mon, 30 Mar 2026 17:00:23 +0200	[thread overview]
Message-ID: <bc146b2b-8d34-466a-84e6-d49eac9b66cf@kernel.org> (raw)
In-Reply-To: <231154f8-a3c3-229a-31a7-f91ab8ec1773@google.com>

On 3/30/26 03:08, David Rientjes 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.
> 
> Signed-off-by: David Rientjes <rientjes@google.com>

Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>

Nit below:

> ---
>  mm/page_alloc.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -316,6 +316,14 @@ EXPORT_SYMBOL(nr_node_ids);
>  EXPORT_SYMBOL(nr_online_nodes);
>  #endif
>  
> +/*
> + * When page allocations stall for longer than a threshold,
> + * ALLOC_STALL_WARN_MSECS, leave a warning in the kernel log.  Only one warning
> + * will be printed during this duration for the entire system.
> + */
> +#define ALLOC_STALL_WARN_MSECS (10 * 1000UL)
> +static unsigned long alloc_stall_warn_jiffies;
> +
>  static bool page_contains_unaccepted(struct page *page, unsigned int order);
>  static bool cond_accept_memory(struct zone *zone, unsigned int order,
>  			       int alloc_flags);
> @@ -4706,6 +4714,40 @@ check_retry_cpuset(int cpuset_mems_cookie, struct alloc_context *ac)
>  	return false;
>  }
>  
> +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)) {

This could also be an unlock+return if the opposite (time_before()) is true,
reducing the indentation for the actual warning code.

> +		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));
> +		cpuset_print_current_mems_allowed();
> +		pr_cont("\n");
> +		dump_stack();
> +		warn_alloc_show_mem(gfp_mask, nodemask);
> +		return;
> +	}
> +
> +	spin_unlock(&alloc_stall_lock);
> +}
> +


  parent reply	other threads:[~2026-03-30 15:00 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-22  3:03 [RFC] mm, page_alloc: reintroduce page allocation stall warning David Rientjes
2026-03-22 20:28 ` David Rientjes
2026-03-23 14:24 ` Vlastimil Babka (SUSE)
2026-03-24  1:06   ` David Rientjes
2026-03-23 16:53 ` Michal Hocko
2026-03-24  1:13   ` David Rientjes
2026-03-24  8:05     ` Petr Mladek
2026-03-23 19:05 ` Andrew Morton
2026-03-30  1:08 ` [patch] " David Rientjes
2026-03-30  3:17   ` Andrew Morton
2026-03-30 14:06     ` Vlastimil Babka (SUSE)
2026-03-30 13:54   ` Michal Hocko
2026-03-30 15:13     ` Vlastimil Babka (SUSE)
2026-03-30 22:34       ` David Rientjes
2026-03-30 15:00   ` Vlastimil Babka (SUSE) [this message]
2026-03-30 22:42   ` [patch v2] " David Rientjes
2026-03-31  1:20     ` [patch v3] " David Rientjes
2026-03-31  3:02       ` Shakeel Butt
2026-03-31  7:54       ` Michal Hocko
     [not found]       ` <69cb3957.5d0a0220.93499.af4cSMTPIN_ADDED_BROKEN@mx.google.com>
2026-03-31 16:44         ` David Rientjes

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=bc146b2b-8d34-466a-84e6-d49eac9b66cf@kernel.org \
    --to=vbabka@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=jackmanb@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=pmladek@suse.com \
    --cc=rientjes@google.com \
    --cc=surenb@google.com \
    --cc=ziy@nvidia.com \
    /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