Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Fix spurious warnings about memory allocation
@ 2026-12-03 14:23 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-03 14:23 ` [PATCH 2/2] mm/page_alloc: Move PF_MEMALLOC warning to nopage tag in the slowpath Wang Wensheng
  0 siblings, 2 replies; 4+ messages in thread
From: Wang Wensheng @ 2026-12-03 14:23 UTC (permalink / raw)
  To: vbabka, hannes, surenb, mhocko, brendan.jackman, ziy, akpm,
	chrisl, kasong, shikemeng, nphamcs, baoquan.he, baohua,
	youngjun.park, david, linux-mm
  Cc: wsw9603

After upgrading our product to kernel 6.18, we observed several memory
allocation warnings. They do not affect real workloads and are false
positives, so address them.

Wang Wensheng (2):
  mm/swap: Don't warn if swap_cluster_alloc_table() failed
  mm/page_alloc: Move PF_MEMALLOC warning to nopage tag in the slowpath

 mm/page_alloc.c | 25 ++++++++++++-------------
 mm/swapfile.c   |  2 +-
 2 files changed, 13 insertions(+), 14 deletions(-)

-- 
2.43.0



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] mm/swap: Don't warn if swap_cluster_alloc_table() failed
  2026-12-03 14:23 [PATCH 0/2] Fix spurious warnings about memory allocation Wang Wensheng
@ 2026-12-03 14:23 ` Wang Wensheng
  2026-12-03 14:23 ` [PATCH 2/2] mm/page_alloc: Move PF_MEMALLOC warning to nopage tag in the slowpath Wang Wensheng
  1 sibling, 0 replies; 4+ messages in thread
From: Wang Wensheng @ 2026-12-03 14:23 UTC (permalink / raw)
  To: vbabka, hannes, surenb, mhocko, brendan.jackman, ziy, akpm,
	chrisl, kasong, shikemeng, nphamcs, baoquan.he, baohua,
	youngjun.park, david, linux-mm
  Cc: wsw9603

swap_cluster_alloc_table() is mostly used in the memory reclaim path
and should not warn when memory allocation fails. The actual user may
reclaim pagecache or slab to free up memory. Even if the user ultimately
cannot obtain memory, it is more useful to issue the warning at the last
possible point.

Signed-off-by: Wang Wensheng <wsw9603@163.com>
---
 mm/swapfile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 226230dda0aa..b8fc4e25f1f3 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -602,7 +602,7 @@ swap_cluster_populate(struct swap_info_struct *si,
 	local_unlock(&percpu_swap_cluster.lock);
 
 	ret = swap_cluster_alloc_table(si, ci, __GFP_HIGH | __GFP_NOMEMALLOC |
-					     GFP_KERNEL, false);
+					     __GFP_NOWARN | GFP_KERNEL, false);
 
 	/*
 	 * Back to atomic context. We might have migrated to a new CPU with a
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] mm/page_alloc: Move PF_MEMALLOC warning to nopage tag in the slowpath
  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-03 14:23 ` Wang Wensheng
  2026-12-03 17:24   ` Michal Hocko
  1 sibling, 1 reply; 4+ messages in thread
From: Wang Wensheng @ 2026-12-03 14:23 UTC (permalink / raw)
  To: vbabka, hannes, surenb, mhocko, brendan.jackman, ziy, akpm,
	chrisl, kasong, shikemeng, nphamcs, baoquan.he, baohua,
	youngjun.park, david, linux-mm
  Cc: wsw9603

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>
---
 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



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] mm/page_alloc: Move PF_MEMALLOC warning to nopage tag in the slowpath
  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
  0 siblings, 0 replies; 4+ messages in thread
From: Michal Hocko @ 2026-12-03 17:24 UTC (permalink / raw)
  To: Wang Wensheng
  Cc: vbabka, hannes, surenb, brendan.jackman, ziy, akpm, chrisl,
	kasong, shikemeng, nphamcs, baoquan.he, baohua, youngjun.park,
	david, linux-mm

On Thu 03-12-26 22:23:06, 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.

So essentially you are telling that we shouldn't warn if the allocation
just manages to succeeds because there are memory reserves available.
While the intention of the code is to catch the unsupported GFP_NOFAIL
use from the allocation context. See the difference?

-- 
Michal Hocko
SUSE Labs


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-03 17:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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-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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox