From: Baoquan He zswap_store() can refuse a page if the pool may be at its limit, or the page may not compress well enough. For an xswap device there was no way to store it, so swap_writeout() put the page back on the LRU. Under memory pressure that turns into a livelock: reclaim keeps picking the same page and the pool keeps refusing it. Now that xswap slots have a physical backend, write the page out instead. If no backend can be reserved, keep the old behaviour. Signed-off-by: Baoquan He --- Documentation/admin-guide/mm/zswap.rst | 12 ++++++++++++ mm/page_io.c | 16 +++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Documentation/admin-guide/mm/zswap.rst b/Documentation/admin-guide/mm/zswap.rst index 2464425c783d..3c0b8c59599d 100644 --- a/Documentation/admin-guide/mm/zswap.rst +++ b/Documentation/admin-guide/mm/zswap.rst @@ -136,3 +136,15 @@ selected. A debugfs interface is provided for various statistic about pool size, number of pages stored, same-value filled pages and various counters for the reasons pages are rejected. + +xswap devices +------------- + +An xswap device is a file-less swap device backed by zswap. While such a +device exists, do not disable zswap at runtime (``enabled=0``) or set +``max_pool_percent`` to 0. The device would have no backing: pages already +in zswap can still be read, but new pages cannot be stored. Destroy the +xswap devices first. + +Writeback needs a real swap device. Without one, a page that zswap refuses +stays in memory. diff --git a/mm/page_io.c b/mm/page_io.c index 76e8d08961bb..30d46218122b 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -259,10 +259,20 @@ int swap_writeout(struct swap_io_ctx *ctx, struct folio *folio) } rcu_read_unlock(); - /* No backing store: keep the folio; ctx->sis is not set yet. */ + /* An xswap entry has no store of its own: use a physical slot. */ if (unlikely(__swap_entry_to_info(folio->swap)->flags & SWP_XSWAP)) { - folio_mark_dirty(folio); - return AOP_WRITEPAGE_ACTIVATE; + swp_entry_t entry = folio->swap; + swp_entry_t phys; + + /* The pool refused it: fall back to a real swap device. */ + phys = xswap_backend_alloc(entry); + if (!phys.val) { + folio_mark_dirty(folio); + return AOP_WRITEPAGE_ACTIVATE; + } + + __swap_writeout(ctx, folio, phys); + return 0; } __swap_writeout(ctx, folio, folio->swap); -- 2.54.0