[RFC PATCH v4 4/4] mm: swap: allow direct reclaim for synchronous multi-page swapin

From: Nanzhe Zhao

Date: Sat Nov 14 2026 - 21:47:24 EST


Synchronous swap devices such as zram complete swap I/O in the faulting
context. With multi-page compression enabled, a 16 KiB block is
stored and decompressed as a single object.

The swapin allocation inherits the VMA's THP gfp mask, which drops
__GFP_DIRECT_RECLAIM for VMAs without MADV_HUGEPAGE. Under memory
pressure, the order-2 allocation fails and falls back to order-0,
requiring the entire 16 KiB block to be decompressed just to swap in
an order-0 page.

Allow direct reclaim for order-2 swapin allocation to improve the
allocation success rate and avoid partial reads.

Signed-off-by: Nanzhe Zhao <zhaonanzhe@xxxxxxxxxx>
---
mm/swap_state.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/mm/swap_state.c b/mm/swap_state.c
index da65d75ceead..912b0e21a781 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -462,6 +462,13 @@ static struct folio *__swap_cache_alloc(struct swap_cluster_info *ci,
if (mpol || !vmf) {
folio = folio_alloc_mpol(gfp, order, mpol, ilx, numa_node_id());
} else {
+ /*
+ * zsmalloc uses order-2 pages to store compressed data.
+ * Allow direct reclaim to improve allocation success and
+ * avoid partial reads.
+ */
+ if (order == 2)
+ gfp |= __GFP_RECLAIM;
address = round_down(vmf->address, PAGE_SIZE << order);
folio = vma_alloc_folio(gfp, order, vmf->vma, address);
}
--
2.43.0