[PATCH v5 08/19] mm, swap: require zswap for xswap devices

From: Baoquan He

Date: Mon Nov 09 2026 - 00:58:12 EST


From: Baoquan He <hebaoquan@xxxxxxxxxx>

xswap pages live only in zswap. Without zswap, swapout cannot
free the page, but still takes a swap entry. So the device consumes
swap entries without freeing memory. Fail to create a device when
zswap is unavailable.

Acked-by: Chris Li <chrisl@xxxxxxxxxx>
Signed-off-by: Baoquan He <hebaoquan@xxxxxxxxxx>
---
mm/swapfile.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 3f2b863f7dd7..35c8aac1e25d 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -4268,6 +4268,10 @@ static int xswap_create(int prio)
(prio < 0 || prio > SWAP_FLAG_PRIO_MASK))
return -EINVAL;

+ /* xswap has no backing store, it relies on zswap. */
+ if (!zswap_is_enabled())
+ return -EOPNOTSUPP;
+
si = alloc_swap_info();
if (IS_ERR(si))
return PTR_ERR(si);
--
2.54.0