mm/page_alloc.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
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>
---
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)) {
+ 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);
+}
+
static inline struct page *
__alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
struct alloc_context *ac)
@@ -4726,6 +4768,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
int reserve_flags;
bool compact_first = false;
bool can_retry_reserves = true;
+ unsigned long alloc_start_time = jiffies;
if (unlikely(nofail)) {
/*
@@ -4841,6 +4884,9 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
if (current->flags & PF_MEMALLOC)
goto nopage;
+ /* If allocation has taken excessively long, warn about it */
+ check_alloc_stall_warn(gfp_mask, ac->nodemask, order, alloc_start_time);
+
/* Try direct reclaim and then allocating */
if (!compact_first) {
page = __alloc_pages_direct_reclaim(gfp_mask, order, alloc_flags,
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);
> +}
> +
On Sun 29-03-26 18:08:52, 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.
I think it makes sense to summarize reasons for the revert. I would
propose to change the above to somehting like
"
The warning was subsequently reverted in commit 400e22499dd9 ("mm: don't
warn about allocations which stall for too long") because it was
possible to generate memory pressure that would effectivelly stall
further progress through printk execution.
"
> @@ -4841,6 +4884,9 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
> if (current->flags & PF_MEMALLOC)
> goto nopage;
>
> + /* If allocation has taken excessively long, warn about it */
> + check_alloc_stall_warn(gfp_mask, ac->nodemask, order, alloc_start_time);
> +
> /* Try direct reclaim and then allocating */
> if (!compact_first) {
> page = __alloc_pages_direct_reclaim(gfp_mask, order, alloc_flags,
Is there any specific reason for this placement? Compaction can take
quite some time as well.
--
Michal Hocko
SUSE Labs
On 3/30/26 15:54, Michal Hocko wrote:
> On Sun 29-03-26 18:08:52, 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.
>
> I think it makes sense to summarize reasons for the revert. I would
> propose to change the above to somehting like
> "
> The warning was subsequently reverted in commit 400e22499dd9 ("mm: don't
> warn about allocations which stall for too long") because it was
> possible to generate memory pressure that would effectivelly stall
> further progress through printk execution.
> "
>
>> @@ -4841,6 +4884,9 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
>> if (current->flags & PF_MEMALLOC)
>> goto nopage;
>>
>> + /* If allocation has taken excessively long, warn about it */
>> + check_alloc_stall_warn(gfp_mask, ac->nodemask, order, alloc_start_time);
>> +
>> /* Try direct reclaim and then allocating */
>> if (!compact_first) {
>> page = __alloc_pages_direct_reclaim(gfp_mask, order, alloc_flags,
>
> Is there any specific reason for this placement? Compaction can take
> quite some time as well.
It seems fine to me - as longs as the slowpath is retrying for 10 seconds
and still can't obtain a page, there's a warning.
We don't catch cases when either the get_page_from_freelist() attempt,
direct compaction or direct reclaim attempt is what gets us over 10 seconds,
and at the same time it results in success. If that's a concern, we should
add another check_alloc_stall_warn() call under got_pg label (as the RFC
had) - I'm not sure it's all achievable with a single place with the call.
On Mon, 30 Mar 2026, Vlastimil Babka (SUSE) 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.
> >
> > I think it makes sense to summarize reasons for the revert. I would
> > propose to change the above to somehting like
> > "
> > The warning was subsequently reverted in commit 400e22499dd9 ("mm: don't
> > warn about allocations which stall for too long") because it was
> > possible to generate memory pressure that would effectivelly stall
> > further progress through printk execution.
> > "
> >
Will do!
> >> @@ -4841,6 +4884,9 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
> >> if (current->flags & PF_MEMALLOC)
> >> goto nopage;
> >>
> >> + /* If allocation has taken excessively long, warn about it */
> >> + check_alloc_stall_warn(gfp_mask, ac->nodemask, order, alloc_start_time);
> >> +
> >> /* Try direct reclaim and then allocating */
> >> if (!compact_first) {
> >> page = __alloc_pages_direct_reclaim(gfp_mask, order, alloc_flags,
> >
> > Is there any specific reason for this placement? Compaction can take
> > quite some time as well.
>
> It seems fine to me - as longs as the slowpath is retrying for 10 seconds
> and still can't obtain a page, there's a warning.
>
> We don't catch cases when either the get_page_from_freelist() attempt,
> direct compaction or direct reclaim attempt is what gets us over 10 seconds,
> and at the same time it results in success. If that's a concern, we should
> add another check_alloc_stall_warn() call under got_pg label (as the RFC
> had) - I'm not sure it's all achievable with a single place with the call.
>
Right, the big idea here is that at least one of the allocations that is
looping will run into the check_alloc_stall_warn(). We might miss a
borderline case but the 10 seconds is already arbitrary and this is the
placement where commit 63f53dea0c98 ("mm: warn about allocations which
stall for too long") ended up before it was reverted.
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);
> +}
> +
On 3/30/26 05:17, Andrew Morton wrote:
> 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.
But we have no page to dump, or did you mean something else? Maybe some part
of warn_alloc() (without its own ratelimit etc) could be extracted end reused.
>> + cpuset_print_current_mems_allowed();
>> + pr_cont("\n");
>> + dump_stack();
>> + warn_alloc_show_mem(gfp_mask, nodemask);
>> + return;
>> + }
>> +
>> + spin_unlock(&alloc_stall_lock);
>> +}
>> +
>
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") because it was possible
to generate memory pressure that would effectively stall further progress
through printk execution.
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.
Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
Signed-off-by: David Rientjes <rientjes@google.com>
---
v2:
- commit message update per Michal
- check_alloc_stall_warn() cleanup per Vlastimil
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;
+
+ /* Check again, this time under the lock */
+ if (time_before(jiffies, alloc_stall_warn_jiffies)) {
+ spin_unlock(&alloc_stall_lock);
+ return;
+ }
+
+ 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);
+}
+
static inline struct page *
__alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
struct alloc_context *ac)
@@ -4726,6 +4768,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
int reserve_flags;
bool compact_first = false;
bool can_retry_reserves = true;
+ unsigned long alloc_start_time = jiffies;
if (unlikely(nofail)) {
/*
@@ -4841,6 +4884,9 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
if (current->flags & PF_MEMALLOC)
goto nopage;
+ /* If allocation has taken excessively long, warn about it */
+ check_alloc_stall_warn(gfp_mask, ac->nodemask, order, alloc_start_time);
+
/* Try direct reclaim and then allocating */
if (!compact_first) {
page = __alloc_pages_direct_reclaim(gfp_mask, order, alloc_flags,
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") because it was possible
to generate memory pressure that would effectively stall further progress
through printk execution.
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.
Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
Signed-off-by: David Rientjes <rientjes@google.com>
---
v3:
- initialize to INITIAL_JIFFIES per AI review so warnings are not
suppressed in the first five minutes after boot
- time_before(jiffies, a) -> time_is_after_jiffies(a)
v2:
- commit message update per Michal
- check_alloc_stall_warn() cleanup per Vlastimil
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 = INITIAL_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_is_after_jiffies(READ_ONCE(alloc_stall_warn_jiffies)))
+ return;
+ if (gfp_mask & __GFP_NOWARN)
+ return;
+
+ if (!spin_trylock(&alloc_stall_lock))
+ return;
+
+ /* Check again, this time under the lock */
+ if (time_is_after_jiffies(alloc_stall_warn_jiffies)) {
+ spin_unlock(&alloc_stall_lock);
+ return;
+ }
+
+ 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);
+}
+
static inline struct page *
__alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
struct alloc_context *ac)
@@ -4726,6 +4768,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
int reserve_flags;
bool compact_first = false;
bool can_retry_reserves = true;
+ unsigned long alloc_start_time = jiffies;
if (unlikely(nofail)) {
/*
@@ -4841,6 +4884,9 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
if (current->flags & PF_MEMALLOC)
goto nopage;
+ /* If allocation has taken excessively long, warn about it */
+ check_alloc_stall_warn(gfp_mask, ac->nodemask, order, alloc_start_time);
+
/* Try direct reclaim and then allocating */
if (!compact_first) {
page = __alloc_pages_direct_reclaim(gfp_mask, order, alloc_flags,
On Mon 30-03-26 18:20:57, 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") because it was possible
> to generate memory pressure that would effectively stall further progress
> through printk execution.
>
> 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.
>
> Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
> Signed-off-by: David Rientjes <rientjes@google.com>
OK, let's go with this and tune it up as we find a need in the future.
Acked-by: Michal Hocko <mhocko@suse.com>
Thanks!
--
Michal Hocko
SUSE Labs
On Mon, Mar 30, 2026 at 06:20:57PM -0700, 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") because it was possible
> to generate memory pressure that would effectively stall further progress
> through printk execution.
>
> 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.
>
> Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
> Signed-off-by: David Rientjes <rientjes@google.com>
Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>
I am hoping that the reason you are reintroducing these warnings is
because you already are seeing such cases in your production
environment. Do you have anything interesting to share?
© 2016 - 2026 Red Hat, Inc.