Skip to content

Commit

Permalink
mm, swap: fix false warning for large allocation with !THP_SWAP
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Kairui Song authored and Andrew Morton committed May 8, 2025
1 parent 8cf6ecb commit 9a9794a
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions mm/swapfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9a9794a

Please sign in to comment.