[RFC PATCH 03/10] mm/swap: add redirect_xa field and ghost redirect helper declarations
From: Baoquan He
Date: Tue Jul 07 2026 - 04:33:12 EST
Add a 'struct xarray redirect_xa' to swap_info_struct (guarded by
CONFIG_ZSWAP) to persist ghost_offset -> phys_swp_entry_t mappings
across swap-cache PFN cycles.
Declare the ghost redirect helper functions in mm/swap.h.
All are no-ops when CONFIG_ZSWAP=n.
Signed-off-by: Baoquan He <baoquan.he@xxxxxxxxx>
---
include/linux/swap.h | 3 +++
mm/swap.h | 14 ++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/include/linux/swap.h b/include/linux/swap.h
index 9829a31a541e..a4d6851e0921 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -277,6 +277,9 @@ struct swap_info_struct {
struct work_struct reclaim_work; /* reclaim worker */
struct list_head discard_clusters; /* discard clusters list */
struct plist_node avail_list; /* entry in swap_avail_head */
+#ifdef CONFIG_ZSWAP
+ struct xarray redirect_xa; /* ghost offset â?? phys swp_entry_t */
+#endif
};
static inline swp_entry_t page_swap_entry(struct page *page)
diff --git a/mm/swap.h b/mm/swap.h
index 2d29e41d3323..bc51ee5dbf51 100644
--- a/mm/swap.h
+++ b/mm/swap.h
@@ -287,6 +287,20 @@ void swap_write_unplug(struct swap_iocb *sio);
int swap_writeout(struct folio *folio, struct swap_iocb **swap_plug);
int __swap_writepage(struct folio *folio, struct swap_iocb **swap_plug);
+/* Ghost swapfile redirect helpers (mm/swapfile.c) */
+#ifdef CONFIG_ZSWAP
+swp_entry_t ghost_redirect_to_phys(struct swap_info_struct *si,
+ pgoff_t offset);
+swp_entry_t alloc_phys_swap_slot(void);
+void free_phys_swap_slot(swp_entry_t phys_entry);
+#else
+static inline swp_entry_t ghost_redirect_to_phys(struct swap_info_struct *si,
+ pgoff_t offset)
+{ return (swp_entry_t){}; }
+static inline swp_entry_t alloc_phys_swap_slot(void) { return (swp_entry_t){}; }
+static inline void free_phys_swap_slot(swp_entry_t phys_entry) {}
+#endif
+
/* linux/mm/swap_state.c */
extern struct address_space swap_space __read_mostly;
static inline struct address_space *swap_address_space(swp_entry_t entry)
--
2.54.0