Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Kefeng Wang <wangkefeng.wang@huawei.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: <linux-mm@kvack.org>, Chengming Zhou <chengming.zhou@linux.dev>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Kairui Song <kasong@tencent.com>, Nhat Pham <nphamcs@gmail.com>,
	Yosry Ahmed <yosryahmed@google.com>,
	Kefeng Wang <wangkefeng.wang@huawei.com>
Subject: [PATCH v3 3/3] mm: zswap: reuse zswap_invalidate() in zswap_store()
Date: Thu, 10 Sep 2026 20:35:44 +0800	[thread overview]
Message-ID: <20260910123544.818146-4-wangkefeng.wang@huawei.com> (raw)
In-Reply-To: <20260910123544.818146-1-wangkefeng.wang@huawei.com>

Reuse zswap_invalidate() in zswap_store() check_old path. Its
zswap_never_enabled() and xa_empty() guards avoid redundant xarray
lookups and deduplicate the per-slot free logic.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 mm/zswap.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/mm/zswap.c b/mm/zswap.c
index 132e97748ed2..e6edbaf97f0d 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -1546,19 +1546,8 @@ bool zswap_store(struct folio *folio)
 	 * offsets corresponding to each page of the folio. Otherwise,
 	 * writeback could overwrite the new data in the swapfile.
 	 */
-	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);
-		}
-	}
+	if (!ret)
+		zswap_invalidate(swp_type(swp), swp_offset(swp), nr_pages);
 
 	return ret;
 }
-- 
2.55.0



  parent reply	other threads:[~2026-09-10 12:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10 12:35 [PATCH v3 0/3] mm: zswap: optimize zswap invalidate and store Kefeng Wang
2026-09-10 12:35 ` [PATCH v3 1/3] mm: zswap: convert zswap_invalidate() to take a range Kefeng Wang
2026-09-10 14:08   ` Yosry Ahmed
2026-09-10 19:32   ` Johannes Weiner
2026-09-10 12:35 ` [PATCH v3 2/3] mm: zswap: skip xarray walk in zswap_invalidate() when zswap is unused Kefeng Wang
2026-09-10 14:08   ` Yosry Ahmed
2026-09-10 19:32   ` Johannes Weiner
2026-09-10 12:35 ` Kefeng Wang [this message]
2026-09-10 14:09   ` [PATCH v3 3/3] mm: zswap: reuse zswap_invalidate() in zswap_store() Yosry Ahmed
2026-09-10 19:33   ` Johannes Weiner

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=20260910123544.818146-4-wangkefeng.wang@huawei.com \
    --to=wangkefeng.wang@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=chengming.zhou@linux.dev \
    --cc=hannes@cmpxchg.org \
    --cc=kasong@tencent.com \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=yosryahmed@google.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