Thread (14 messages) flat view 14 messages, 4 authors, 8d ago
COOLING8d

[PATCH v2 1/4] mm: zswap: pass type and offset to zswap_invalidate() directly

From: Kefeng Wang <hidden>
Date: 2026-09-10 09:55:02
Subsystem: memory management, memory management - swap, the rest, zswap compressed swap caching · Maintainers: Andrew Morton, Chris Li, Kairui Song, Linus Torvalds, Johannes Weiner, Yosry Ahmed, Nhat Pham

zswap_invalidate() takes a swp_entry_t only to unpack it right back
into type and offset.  Both callers already have those values, so
pass them directly and drop the swp_entry()/swp_type()/swp_offset()
round-trip.

Signed-off-by: Kefeng Wang <redacted>
---
 include/linux/zswap.h |  4 ++--
 mm/swapfile.c         |  2 +-
 mm/zswap.c            | 14 +++++++++-----
 3 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/include/linux/zswap.h b/include/linux/zswap.h
index 30c193a1207e..463bdee5c1e1 100644
--- a/include/linux/zswap.h
+++ b/include/linux/zswap.h
@@ -27,7 +27,7 @@ struct zswap_lruvec_state {
 unsigned long zswap_total_pages(void);
 bool zswap_store(struct folio *folio);
 int zswap_load(struct folio *folio);
-void zswap_invalidate(swp_entry_t swp);
+void zswap_invalidate(int type, pgoff_t offset);
 int zswap_swapon(int type, unsigned long nr_pages);
 void zswap_swapoff(int type);
 void zswap_memcg_offline_cleanup(struct mem_cgroup *memcg);
@@ -49,7 +49,7 @@ static inline int zswap_load(struct folio *folio)
 	return -ENOENT;
 }
 
-static inline void zswap_invalidate(swp_entry_t swp) {}
+static inline void zswap_invalidate(int type, pgoff_t offset) {}
 static inline int zswap_swapon(int type, unsigned long nr_pages)
 {
 	return 0;
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 05d3408396f9..ba71905e4d46 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1319,7 +1319,7 @@ static void swap_range_free(struct swap_info_struct *si, unsigned long offset,
 	unsigned int i;
 
 	for (i = 0; i < nr_entries; i++)
-		zswap_invalidate(swp_entry(si->type, offset + i));
+		zswap_invalidate(si->type, offset + i);
 
 	if (si->flags & SWP_BLKDEV)
 		swap_slot_free_notify =
diff --git a/mm/zswap.c b/mm/zswap.c
index a12b6452a225..420c405d0402 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -228,10 +228,15 @@ static bool zswap_has_pool;
 /* One swap address space for each 64M swap space */
 #define ZSWAP_ADDRESS_SPACE_SHIFT 14
 #define ZSWAP_ADDRESS_SPACE_PAGES (1 << ZSWAP_ADDRESS_SPACE_SHIFT)
+
+static inline struct xarray *zswap_tree(int type, pgoff_t offset)
+{
+	return &zswap_trees[type][offset >> ZSWAP_ADDRESS_SPACE_SHIFT];
+}
+
 static inline struct xarray *swap_zswap_tree(swp_entry_t swp)
 {
-	return &zswap_trees[swp_type(swp)][swp_offset(swp)
-		>> ZSWAP_ADDRESS_SPACE_SHIFT];
+	return zswap_tree(swp_type(swp), swp_offset(swp));
 }
 
 #define zswap_pool_debug(msg, p)			\
@@ -1659,10 +1664,9 @@ int zswap_load(struct folio *folio)
 	return 0;
 }
 
-void zswap_invalidate(swp_entry_t swp)
+void zswap_invalidate(int type, pgoff_t offset)
 {
-	pgoff_t offset = swp_offset(swp);
-	struct xarray *tree = swap_zswap_tree(swp);
+	struct xarray *tree = zswap_tree(type, offset);
 	struct zswap_entry *entry;
 
 	if (xa_empty(tree))
-- 
2.55.0

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help