From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42AB4333424 for ; Mon, 30 Mar 2026 15:00:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774882827; cv=none; b=r2N6Eg2Sk+j1rGAL29cwqdSyc+WZVW2F5pC2EUMXcRYzpwUSUBc5xP3api/pVN5YKrk+vMpjrADJPPIy2e+iOtOlLB4svioDsiCLp7TLASNNe4RKTIuZKVIloZMK7xNcAoZ+qnF/wWuGHbmSHM+PKGuU9cm5CWEkx4P46qNQfL8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774882827; c=relaxed/simple; bh=ALCW94wbuSogxnAbtTw+nxjhUDLVX0cRyoDJHU2dn20=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=O5df9DhtxdCpF8cFoUFsI/xIvHGFoFDaKMjQmc7Vfs6xMeEGFUKApRCgXF5UkYGLlR7TfVGwS621FaZowuPgSlwf9x5AmfzDWQXa3mY4brcU8U1FlAIAwDLOFBZrOtDgnAQvogVXzZM2BkUApwzyz8p5/mAFwvCJsNUoQi6Ds58= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Dxba+iSI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Dxba+iSI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EAD4AC4CEF7; Mon, 30 Mar 2026 15:00:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774882826; bh=ALCW94wbuSogxnAbtTw+nxjhUDLVX0cRyoDJHU2dn20=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=Dxba+iSISY7aFU2yWaJ9zsY2iRii8l9TgsJux0sFGh5ImuoDNY9Pw6dMlA6kKsxwB CNx8ajzJlX3bT18xXFfCLDgd3XvubqCdyNPpFQvOsDdvhLVGlPjCxlLO/nvreiXoP2 HHYZhVDJV8KUkQxXentQIO+5nUyemfVbEZAm9PBSZpSSbgy1QCDJ15jFLnd+r8fmO/ ZIasr6HDHUq56pp4i4VpkpunGVeVNlV9hEFT7xMRs6BjOyAfnd3EY+TtexwkxnjxCc TfU4lj81sWZ/+R6WdGEbZ3+K4u2G6V6Yc0lLZ+bnI2VNFKJ4wA8PD4gCDqsnT0nXpM qObUQXgBwSd7Q== Message-ID: Date: Mon, 30 Mar 2026 17:00:23 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [patch] mm, page_alloc: reintroduce page allocation stall warning Content-Language: en-US To: David Rientjes , Andrew Morton Cc: Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , Petr Mladek , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <30945cc3-9c4d-94bb-e7e7-dde71483800c@google.com> <231154f8-a3c3-229a-31a7-f91ab8ec1773@google.com> From: "Vlastimil Babka (SUSE)" In-Reply-To: <231154f8-a3c3-229a-31a7-f91ab8ec1773@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 Acked-by: Vlastimil Babka (SUSE) 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); > +} > +