From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C31A14718D6 for ; Thu, 10 Sep 2026 21:48:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789076891; cv=none; b=WXPnRGreGYjVC+EMzShVeMourA1UjCwN1LYRomJ4VM4Zk+RYgKnAlUx9Qw4io84jJNmuNhtfvn9cdU70KP0DmaKdqdQHnABi+tgXy55rP7En6Ax67FZReIti2kWc4CprVHX+B1HYm9qicd2WGuXKDipLke66BDwUt+Ts1pfCg3Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789076891; c=relaxed/simple; bh=JYgHglFbzGVShg4yNhOxC0f4H54fRLD+e6ZgsViv4mI=; h=Date:To:From:Subject:Message-Id; b=hp03FNFQx4VLxnXlLMzl9Qbic7Lk+FKnXLcsTNo885O9eGUH9KSq6WwpyG7n28JeaGFOW6X6QLHd1Q/u4XanXGpw4jfasbWHXk3+QwRdBBX3BiknTd0cJo87DABbtP+Ltx5cCh/8qVWJ08gRiRPFVDZn4GTVL1urrfqh66w1KRw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=dphZpl85; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="dphZpl85" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C7C01F000FF; Thu, 10 Sep 2026 21:48:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1789076889; bh=EdkPr3kCrYR9sYN4iB8t30I0CQmrSGeYmn8q6Uox2kE=; h=Date:To:From:Subject; b=dphZpl85E8KkXlZ/XKHYtTj9fs5kqsXtvxB+15zUvuSxpSe8FeVZVLQ/Ub7H2kCBX Ye6QVhExBk04doEYY+gxjTmRV9QavWxj03mWmj95tx7Pa0jS/D/+UnNLGDfHSSgBJa SE38VBOzNcgBo/ifA3U27d9RSsodH6AhGvGXAZfs= Date: Thu, 10 Sep 2026 14:48:08 -0700 To: mm-commits@vger.kernel.org,yosry@kernel.org,yosryahmed@google.com,nphamcs@gmail.com,kasong@tencent.com,hannes@cmpxchg.org,chengming.zhou@linux.dev,wangkefeng.wang@huawei.com,akpm@linux-foundation.org From: Andrew Morton Subject: + mm-zswap-convert-zswap_invalidate-to-take-a-range.patch added to mm-new branch Message-Id: <20260910214809.5C7C01F000FF@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The patch titled Subject: mm: zswap: convert zswap_invalidate() to take a range has been added to the -mm mm-new branch. Its filename is mm-zswap-convert-zswap_invalidate-to-take-a-range.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-zswap-convert-zswap_invalidate-to-take-a-range.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Kefeng Wang Subject: mm: zswap: convert zswap_invalidate() to take a range Date: Thu, 10 Sep 2026 20:35:42 +0800 Patch series "mm: zswap: optimize zswap invalidate and store", v3. This series range-ifies zswap_invalidate() to skip xarray lookups when zswap is unused, and reuses it in zswap_store() to eliminate redundant per-slot lookups and open-coded logic. This patch (of 3): zswap_invalidate() takes a swp_entry_t only to unpack it right back into type and offset, and both callers already have those values in hand. Pass type, offset, and nr_entries directly so swap_range_free() can invalidate an entire range in one call instead of looping in the caller. Link: https://lore.kernel.org/20260910123544.818146-1-wangkefeng.wang@huawei.com Link: https://lore.kernel.org/20260910123544.818146-2-wangkefeng.wang@huawei.com Signed-off-by: Kefeng Wang Suggested-by: Johannes Weiner Acked-by: Yosry Ahmed Reviewed-by: Johannes Weiner Cc: Chengming Zhou Cc: Kairui Song Cc: Nhat Pham Cc: Yosry Ahmed Signed-off-by: Andrew Morton --- include/linux/zswap.h | 8 ++++++-- mm/swapfile.c | 4 +--- mm/zswap.c | 29 +++++++++++++++++++---------- 3 files changed, 26 insertions(+), 15 deletions(-) --- a/include/linux/zswap.h~mm-zswap-convert-zswap_invalidate-to-take-a-range +++ a/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, unsigned long nr_entries); 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,11 @@ static inline int zswap_load(struct foli return -ENOENT; } -static inline void zswap_invalidate(swp_entry_t swp) {} +static inline void zswap_invalidate(int type, pgoff_t offset, + unsigned long nr_entries) +{ +} + static inline int zswap_swapon(int type, unsigned long nr_pages) { return 0; --- a/mm/swapfile.c~mm-zswap-convert-zswap_invalidate-to-take-a-range +++ a/mm/swapfile.c @@ -1316,10 +1316,8 @@ static void swap_range_free(struct swap_ { unsigned long end = offset + nr_entries - 1; void (*swap_slot_free_notify)(struct block_device *, unsigned long); - unsigned int i; - for (i = 0; i < nr_entries; i++) - zswap_invalidate(swp_entry(si->type, offset + i)); + zswap_invalidate(si->type, offset, nr_entries); if (si->flags & SWP_BLKDEV) swap_slot_free_notify = --- a/mm/zswap.c~mm-zswap-convert-zswap_invalidate-to-take-a-range +++ a/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,18 +1664,22 @@ int zswap_load(struct folio *folio) return 0; } -void zswap_invalidate(swp_entry_t swp) +void zswap_invalidate(int type, pgoff_t offset, unsigned long nr_entries) { - pgoff_t offset = swp_offset(swp); - struct xarray *tree = swap_zswap_tree(swp); struct zswap_entry *entry; + struct xarray *tree; + unsigned long i; - if (xa_empty(tree)) - return; + for (i = 0; i < nr_entries; i++) { + tree = zswap_tree(type, offset + i); - entry = xa_erase(tree, offset); - if (entry) - zswap_entry_free(entry); + if (xa_empty(tree)) + continue; + + entry = xa_erase(tree, offset + i); + if (entry) + zswap_entry_free(entry); + } } int zswap_swapon(int type, unsigned long nr_pages) _ Patches currently in -mm which might be from wangkefeng.wang@huawei.com are xfs-remove-dead-kswapd-flag-inheritance-from-btree-split-worker.patch iomap-simplify-writepages-reclaim-guard.patch mm-replace-pf_kswapd-flag-with-kthread_func-check.patch mm-replace-pf_kcompactd-flag-with-kthread_func-check.patch mm-zswap-convert-zswap_invalidate-to-take-a-range.patch mm-zswap-skip-xarray-walk-in-zswap_invalidate-when-zswap-is-unused.patch mm-zswap-reuse-zswap_invalidate-in-zswap_store.patch