Skip to contentSkip to conversation

mm, swap: fix false warning for large allocation with !THP_SWAP

PATCH Applied Kairui Song 2 participants 2 messages Apr 29, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm, swap: fix false warning for large allocation with !THP_SWAP

From: Kairui Song <[email protected]>

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")
---
 mm/swapfile.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)
mm/swapfile.c +16 -7
index e727021b8e2c..b86637cfb17a 100644
@@ -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);
Signature · 1 line
2.49.0
Tested-by on v1 1/1
#1 lore raw
Quoted 13 lines · Kairui Song

From: Kairui Song <[email protected]>

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.

Quoted 7 lines
Fixes 0ff67f990bd4 ("mm, swap: remove swap slot cache")
---
 mm/swapfile.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)