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 --- 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; } -- 2.43.0