Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Baoquan He <baoquan.he@linux.dev>
To: linux-mm@kvack.org
Cc: akpm@linux-foundation.org, chrisl@kernel.org, kasong@tencent.com,
	shikemeng@huaweicloud.com, nphamcs@gmail.com, baohua@kernel.org,
	youngjun.park@lge.com, hannes@cmpxchg.org, yosry@kernel.org,
	chengming.zhou@linux.dev, linux-kernel@vger.kernel.org,
	Baoquan He <baoquan.he@linux.dev>
Subject: [RFC PATCH 07/10] mm/page_io: forward ghost swap reads to physical device via Redirect
Date: Tue,  7 Jul 2026 16:26:09 +0800	[thread overview]
Message-ID: <20260707082614.95030-8-baoquan.he@linux.dev> (raw)
In-Reply-To: <20260707082614.95030-1-baoquan.he@linux.dev>

When swap_read_folio() encounters a ghost swap entry (SWP_GHOST),
check if there is a Redirect mapping to a physical swap slot via
ghost_redirect_to_phys().  If a physical backing exists, forward
the I/O to that device:

1. Query the redirect_xa / swap table for the physical swp_entry_t.
2. Temporarily redirect folio->swap to the physical entry so the
   existing swap_read_folio_bdev_{sync,async} / swap_read_folio_fs
   path computes the correct sector from the physical offset.
3. Restore folio->swap to the original ghost entry after I/O.

This completes the backend-switching round trip:
- Swapout: PTE -> ghost entry -> zswap_store -> Pointer(zswap_entry)
- Writeback: Pointer -> decompress -> write to phys -> Redirect(phys)
- Swapin:  PTE -> ghost entry -> Redirect -> read from phys device

Signed-off-by: Baoquan He <baoquan.he@linux.dev>
---
 mm/page_io.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/mm/page_io.c b/mm/page_io.c
index 96e776f9a503..b87b46f05b2f 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -697,6 +697,39 @@ void swap_read_folio(struct folio *folio, struct swap_iocb **plug, void *zentry)
 		goto finish;
 
 	if (unlikely(sis->flags & SWP_GHOST)) {
+		swp_entry_t phys_entry;
+		struct swap_info_struct *phys_si;
+
+		/*
+		 * Ghost swap entry: check if there's a Redirect to a
+		 * physical swap slot.  If so, read from the physical
+		 * device instead.
+		 */
+		phys_entry = ghost_redirect_to_phys(sis, swp_offset(folio->swap));
+		if (phys_entry.val) {
+			phys_si = __swap_entry_to_info(phys_entry);
+			if (phys_si && phys_si->bdev) {
+				swp_entry_t saved = folio->swap;
+
+				/*
+				 * Temporarily point the folio to the
+				 * physical entry so the bdev read path
+				 * computes the correct sector.
+				 */
+				folio->swap = phys_entry;
+				zswap_folio_swapin(folio);
+				if (data_race(phys_si->flags & SWP_FS_OPS))
+					swap_read_folio_fs(folio, plug);
+				else if (phys_si->flags & SWP_SYNCHRONOUS_IO)
+					swap_read_folio_bdev_sync(folio,
+								  phys_si);
+				else
+					swap_read_folio_bdev_async(folio,
+								   phys_si);
+				folio->swap = saved;
+				goto finish;
+			}
+		}
 		folio_unlock(folio);
 		goto finish;
 	}
-- 
2.54.0



  parent reply	other threads:[~2026-07-07  8:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07  8:26 [RFC PATCH 00/10] mm/swap: ghost swapfile with backend switching via Redirect entries Baoquan He
2026-07-07  8:26 ` [RFC PATCH 01/10] mm: ghost swapfile support for zswap Baoquan He
2026-07-07  8:26 ` [RFC PATCH 02/10] mm/swap_table: add Redirect entry encoding for ghost swap backend switching Baoquan He
2026-07-07  8:26 ` [RFC PATCH 03/10] mm/swap: add redirect_xa field and ghost redirect helper declarations Baoquan He
2026-07-07  8:26 ` [RFC PATCH 04/10] mm/swapfile: implement ghost redirect helpers and free-path cascade Baoquan He
2026-07-07  8:26 ` [RFC PATCH 05/10] mm/swap_state: restore Redirect entry when swap cache folio is removed Baoquan He
2026-07-07  8:26 ` [RFC PATCH 06/10] mm/zswap: implement ghost-to-physical writeback for backend switching Baoquan He
2026-07-07  8:26 ` Baoquan He [this message]
2026-07-07  8:26 ` [RFC PATCH 08/10] mm/swapfile: manage ghost cluster_info via lazy vmalloc Baoquan He
2026-07-07  8:26 ` [RFC PATCH 09/10] mm/swapfile: implement swap_ghost_extend_max() for dynamic growth Baoquan He
2026-07-07 22:36   ` Nhat Pham
2026-07-07  8:26 ` [RFC PATCH 10/10] mm/swapfile: add sysfs interface for ghost swap extension Baoquan He
2026-07-07  8:56 ` [RFC PATCH 00/10] mm/swap: ghost swapfile with backend switching via Redirect entries Baoquan He
2026-07-07 21:23 ` Nhat Pham
2026-07-07 21:25   ` Nhat Pham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260707082614.95030-8-baoquan.he@linux.dev \
    --to=baoquan.he@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=chengming.zhou@linux.dev \
    --cc=chrisl@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=kasong@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=shikemeng@huaweicloud.com \
    --cc=yosry@kernel.org \
    --cc=youngjun.park@lge.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox