All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: zswap: avoid unnecessary xarray lookup in zswap_store()
@ 2026-09-09 12:35 Kefeng Wang
  2026-09-09 12:53 ` Kefeng Wang
  2026-09-09 14:52 ` Johannes Weiner
  0 siblings, 2 replies; 4+ messages in thread
From: Kefeng Wang @ 2026-09-09 12:35 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, Kefeng Wang, Chengming Zhou, Johannes Weiner,
	Kairui Song, Nhat Pham, Yosry Ahmed

zswap_store() falls through to check_old and walks the swap xarray
even when zswap is disabled. Add a zswap_never_enabled() early return
matching zswap_load(), and reuse zswap_invalidate() whose xa_empty()
check skips empty per-area trees to avoid unnecessary xarry lockup.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Chengming Zhou <chengming.zhou@linux.dev>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Kairui Song <kasong@tencent.com>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: Yosry Ahmed <yosryahmed@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 mm/zswap.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/mm/zswap.c b/mm/zswap.c
index 5d0d8bd72193..fc6c5e0db5e4 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -1488,6 +1488,9 @@ bool zswap_store(struct folio *folio)
 	VM_WARN_ON_ONCE(!folio_test_locked(folio));
 	VM_WARN_ON_ONCE(!folio_test_swapcache(folio));
 
+	if (zswap_never_enabled())
+		return false;
+
 	if (!zswap_enabled)
 		goto check_old;
 
@@ -1545,15 +1548,10 @@ bool zswap_store(struct folio *folio)
 	if (!ret) {
 		unsigned type = swp_type(swp);
 		pgoff_t offset = swp_offset(swp);
-		struct zswap_entry *entry;
-		struct xarray *tree;
-
-		for (index = 0; index < nr_pages; ++index) {
-			tree = swap_zswap_tree(swp_entry(type, offset + index));
-			entry = xa_erase(tree, offset + index);
-			if (entry)
-				zswap_entry_free(entry);
-		}
+
+		for (index = 0; index < nr_pages; ++index)
+			zswap_invalidate(swp_entry(type, offset + index));
+
 	}
 
 	return ret;
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-09-10  1:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-09 12:35 [PATCH] mm: zswap: avoid unnecessary xarray lookup in zswap_store() Kefeng Wang
2026-09-09 12:53 ` Kefeng Wang
2026-09-09 14:52 ` Johannes Weiner
2026-09-10  1:16   ` Kefeng Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.