Skip to content

Commit 9a9794a

Browse files
ryncsnakpm00
authored andcommitted
mm, swap: fix false warning for large allocation with !THP_SWAP
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 meaningless warning. Link: https://lkml.kernel.org/r/20250429094803.85518-1-ryncsn@gmail.com Fixes: 0ff67f9 ("mm, swap: remove swap slot cache") Signed-off-by: Kairui Song <kasong@tencent.com> Reported-by: Heiko Carstens <hca@linux.ibm.com> Closes: https://lore.kernel.org/linux-mm/20250428135252.25453B17-hca@linux.ibm.com/ Tested-by: Heiko Carstens <hca@linux.ibm.com> Cc: Baoquan He <bhe@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 8cf6ecb commit 9a9794a

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

mm/swapfile.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,13 +1272,22 @@ int folio_alloc_swap(struct folio *folio, gfp_t gfp)
12721272
VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
12731273
VM_BUG_ON_FOLIO(!folio_test_uptodate(folio), folio);
12741274

1275-
/*
1276-
* Should not even be attempting large allocations when huge
1277-
* page swap is disabled. Warn and fail the allocation.
1278-
*/
1279-
if (order && (!IS_ENABLED(CONFIG_THP_SWAP) || size > SWAPFILE_CLUSTER)) {
1280-
VM_WARN_ON_ONCE(1);
1281-
return -EINVAL;
1275+
if (order) {
1276+
/*
1277+
* Reject large allocation when THP_SWAP is disabled,
1278+
* the caller should split the folio and try again.
1279+
*/
1280+
if (!IS_ENABLED(CONFIG_THP_SWAP))
1281+
return -EAGAIN;
1282+
1283+
/*
1284+
* Allocation size should never exceed cluster size
1285+
* (HPAGE_PMD_SIZE).
1286+
*/
1287+
if (size > SWAPFILE_CLUSTER) {
1288+
VM_WARN_ON_ONCE(1);
1289+
return -EINVAL;
1290+
}
12821291
}
12831292

12841293
local_lock(&percpu_swap_cluster.lock);

0 commit comments

Comments
 (0)