linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm, swap: fix false warning for large allocation with !THP_SWAP
@ 2025-04-29  9:48 Kairui Song
  2025-04-29 10:08 ` Heiko Carstens
  0 siblings, 1 reply; 2+ messages in thread
From: Kairui Song @ 2025-04-29  9:48 UTC (permalink / raw)
  To: linux-mm; +Cc: Andrew Morton, Heiko Carstens, linux-kernel, Kairui Song

From: Kairui Song <kasong@tencent.com>

The !CONFIG_THP_SWAP check existed before just fine because slot
cache would reject high order allocation and let the caller split
all folios and try again.

But slot cache is gone, so large allocation will directly go
to the allocator, and the allocator should just fail silently
to inform caller to do the folio split, this is totally fine
and expected.

Remove this meaning less warning.

Fixes: 0ff67f990bd4 ("mm, swap: remove swap slot cache")
Reported-by: Heiko Carstens <hca@linux.ibm.com>
Closes: https://lore.kernel.org/linux-mm/20250428135252.25453B17-hca@linux.ibm.com/
Signed-off-by: Kairui Song <kasong@tencent.com>
---
 mm/swapfile.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index e727021b8e2c..b86637cfb17a 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1272,13 +1272,22 @@ int folio_alloc_swap(struct folio *folio, gfp_t gfp)
 	VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
 	VM_BUG_ON_FOLIO(!folio_test_uptodate(folio), folio);
 
-	/*
-	 * Should not even be attempting large allocations when huge
-	 * page swap is disabled. Warn and fail the allocation.
-	 */
-	if (order && (!IS_ENABLED(CONFIG_THP_SWAP) || size > SWAPFILE_CLUSTER)) {
-		VM_WARN_ON_ONCE(1);
-		return -EINVAL;
+	if (order) {
+		/*
+		 * Reject large allocation when THP_SWAP is disabled,
+		 * the caller should split the folio and try again.
+		 */
+		if (!IS_ENABLED(CONFIG_THP_SWAP))
+			return -EAGAIN;
+
+		/*
+		 * Allocation size should never exceed cluster size
+		 * (HPAGE_PMD_SIZE).
+		 */
+		if (size > SWAPFILE_CLUSTER) {
+			VM_WARN_ON_ONCE(1);
+			return -EINVAL;
+		}
 	}
 
 	local_lock(&percpu_swap_cluster.lock);
-- 
2.49.0



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

* Re: [PATCH] mm, swap: fix false warning for large allocation with !THP_SWAP
  2025-04-29  9:48 [PATCH] mm, swap: fix false warning for large allocation with !THP_SWAP Kairui Song
@ 2025-04-29 10:08 ` Heiko Carstens
  0 siblings, 0 replies; 2+ messages in thread
From: Heiko Carstens @ 2025-04-29 10:08 UTC (permalink / raw)
  To: Kairui Song; +Cc: linux-mm, Andrew Morton, linux-kernel

On Tue, Apr 29, 2025 at 05:48:03PM +0800, Kairui Song wrote:
> From: Kairui Song <kasong@tencent.com>
> 
> The !CONFIG_THP_SWAP check existed before just fine because slot
> cache would reject high order allocation and let the caller split
> all folios and try again.
> 
> But slot cache is gone, so large allocation will directly go
> to the allocator, and the allocator should just fail silently
> to inform caller to do the folio split, this is totally fine
> and expected.
> 
> Remove this meaning less warning.
> 
> Fixes: 0ff67f990bd4 ("mm, swap: remove swap slot cache")
> Reported-by: Heiko Carstens <hca@linux.ibm.com>
> Closes: https://lore.kernel.org/linux-mm/20250428135252.25453B17-hca@linux.ibm.com/
> Signed-off-by: Kairui Song <kasong@tencent.com>
> ---
>  mm/swapfile.c | 23 ++++++++++++++++-------
>  1 file changed, 16 insertions(+), 7 deletions(-)

Tested-by: Heiko Carstens <hca@linux.ibm.com>


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

end of thread, other threads:[~2025-04-29 10:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-29  9:48 [PATCH] mm, swap: fix false warning for large allocation with !THP_SWAP Kairui Song
2025-04-29 10:08 ` Heiko Carstens

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