Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
To: Wang Wensheng <wsw9603@163.com>,
	hannes@cmpxchg.org, surenb@google.com, mhocko@suse.com,
	brendan.jackman@linux.dev, ziy@nvidia.com,
	akpm@linux-foundation.org, chrisl@kernel.org, kasong@tencent.com,
	shikemeng@huaweicloud.com, nphamcs@gmail.com,
	baoquan.he@linux.dev, baohua@kernel.org, youngjun.park@lge.com,
	david@kernel.org, linux-mm@kvack.org, Jan Kara <jack@suse.cz>
Subject: Re: [PATCH 2/2] mm/page_alloc: Move PF_MEMALLOC warning to nopage tag in the slowpath
Date: Fri, 4 Dec 2026 10:06:32 +0100	[thread overview]
Message-ID: <b0320d46-3790-4f72-81e5-402ff3ec9d7a@kernel.org> (raw)
In-Reply-To: <20261203142306.468748-3-wsw9603@163.com>

On 12/3/26 15:23, Wang Wensheng wrote:
> It is not uncommon to enter __alloc_pages_slowpath() with both
> PF_MEMALLOC and __GFP_NOFAIL set during memory reclaim. The original
> warning was placed where an allocation attempt had failed, intended to
> alert about a potential silent stall: with PF_MEMALLOC, direct reclaim
> cannot be performed, while __GFP_NOFAIL forces the allocation to keep
> retrying.
> 
> Commit 903edea6c53f ("mm: warn about illegal __GFP_NOFAIL usage in
> a more appropriate location and manner") moved this warning to the
> very start of __alloc_pages_slowpath(), before any allocation attempt.
> This causes frequent false positives: PF_MEMALLOC allows allocations
> to ignore watermarks, and the fastpath only checks the low watermark,
> so the first allocation attempt inside the slowpath is likely to
> succeed.
> 
> Move the warning to the nopage label to suppress these false warnings.
> The following calltrace triggers the spurious warning:
>         __alloc_pages_slowpath
>         __alloc_frozen_pages_noprof
>         __folio_alloc_noprof
>         __filemap_get_folio
>         ext4_mb_load_buddy_gfp
>         ext4_free_blocks
>         ext4_ext_remove_space
>         ext4_ext_truncate
>         ext4_truncate
>         ext4_evict_inode
>         evict
>         iput
>         dentry_unlink_inode
>         __dentry_kill
>         shrink_dentry_list
>         prune_dcache_sb
>         super_cache_scan
>         do_shrink_slab
>         shrink_slab
>         shrink_node
>         do_try_to_free_pages
>         try_to_free_pages
>         __alloc_pages_direct_reclaim
>         __alloc_pages_slowpath
>         __alloc_frozen_pages_noprof
>         __folio_alloc_noprof
>         vma_alloc_zeroed_movable_folio
> 
> Fixes: 903edea6c53f ("mm: warn about illegal __GFP_NOFAIL usage in a more appropriate location and manner")
> Signed-off-by: Wang Wensheng <wsw9603@163.com>

This is just shooting the messenger. The real fix to this issue is here:
https://lore.kernel.org/all/20261201105733.18997-1-jack@suse.cz/

> ---
>  mm/page_alloc.c | 25 ++++++++++++-------------
>  1 file changed, 12 insertions(+), 13 deletions(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 2fef4092c913..abdf4ba3f757 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -4823,19 +4823,11 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
>  	can_compact = can_direct_reclaim && gfp_compaction_allowed(gfp_mask);
>  	nofail = gfp_mask & __GFP_NOFAIL;
>  
> -	if (unlikely(nofail)) {
> -		/*
> -		 * We don't support __GFP_NOFAIL without __GFP_DIRECT_RECLAIM,
> -		 * otherwise, we may result in lockup.
> -		 */
> -		WARN_ON_ONCE(!can_direct_reclaim);
> -		/*
> -		 * PF_MEMALLOC request from this context is rather bizarre
> -		 * because we cannot reclaim anything and only can loop waiting
> -		 * for somebody to do a work for us.
> -		 */
> -		WARN_ON_ONCE(current->flags & PF_MEMALLOC);
> -	}
> +	/*
> +	 * We don't support __GFP_NOFAIL without __GFP_DIRECT_RECLAIM,
> +	 * otherwise, we may result in lockup.
> +	 */
> +	WARN_ON_ONCE(unlikely(nofail) && !can_direct_reclaim);
>  
>  restart:
>  	compaction_retries = 0;
> @@ -5124,6 +5116,13 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
>  		if (page)
>  			goto got_pg;
>  
> +		/*
> +		 * PF_MEMALLOC request from this context is rather bizarre
> +		 * because we cannot reclaim anything and only can loop waiting
> +		 * for somebody to do a work for us.
> +		 */
> +		WARN_ON_ONCE(current->flags & PF_MEMALLOC);
> +
>  		cond_resched();
>  		goto retry;
>  	}



      parent reply	other threads:[~2026-12-04  9:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 14:23 [PATCH 0/2] Fix spurious warnings about memory allocation Wang Wensheng
2026-12-03 14:23 ` [PATCH 1/2] mm/swap: Don't warn if swap_cluster_alloc_table() failed Wang Wensheng
2026-12-04  2:32   ` Youngjun Park
2026-12-04  5:06     ` wangwensheng
2026-12-04  8:21   ` Dev Jain
2026-12-03 14:23 ` [PATCH 2/2] mm/page_alloc: Move PF_MEMALLOC warning to nopage tag in the slowpath Wang Wensheng
2026-12-03 17:24   ` Michal Hocko
2026-12-04  1:42     ` wangwensheng
2026-12-04  9:29       ` Michal Hocko
2026-12-04  9:06   ` Vlastimil Babka (SUSE) [this message]

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=b0320d46-3790-4f72-81e5-402ff3ec9d7a@kernel.org \
    --to=vbabka@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baoquan.he@linux.dev \
    --cc=brendan.jackman@linux.dev \
    --cc=chrisl@kernel.org \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=jack@suse.cz \
    --cc=kasong@tencent.com \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=nphamcs@gmail.com \
    --cc=shikemeng@huaweicloud.com \
    --cc=surenb@google.com \
    --cc=wsw9603@163.com \
    --cc=youngjun.park@lge.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