[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGsJ_4zW92dnCk6qUF9fKe+=b0dORLrBjuQC5mjq_nbTK4aT4g@mail.gmail.com>
Date: Fri, 7 Nov 2025 05:02:59 +0800
From: Barry Song <21cnbao@...il.com>
To: Kairui Song <ryncsn@...il.com>
Cc: linux-mm@...ck.org, Andrew Morton <akpm@...ux-foundation.org>,
Baoquan He <bhe@...hat.com>, Chris Li <chrisl@...nel.org>, Nhat Pham <nphamcs@...il.com>,
Johannes Weiner <hannes@...xchg.org>, Yosry Ahmed <yosry.ahmed@...ux.dev>,
David Hildenbrand <david@...hat.com>, Youngjun Park <youngjun.park@....com>,
Hugh Dickins <hughd@...gle.com>, Baolin Wang <baolin.wang@...ux.alibaba.com>,
"Huang, Ying" <ying.huang@...ux.alibaba.com>, Kemeng Shi <shikemeng@...weicloud.com>,
Lorenzo Stoakes <lorenzo.stoakes@...cle.com>,
"Matthew Wilcox (Oracle)" <willy@...radead.org>, linux-kernel@...r.kernel.org,
Kairui Song <kasong@...cent.com>
Subject: Re: [PATCH 16/19] mm, swap: check swap table directly for checking cache
On Thu, Oct 30, 2025 at 12:00 AM Kairui Song <ryncsn@...il.com> wrote:
>
> From: Kairui Song <kasong@...cent.com>
>
> Instead of looking at the swap map, check swap table directly to tell
> if a swap slot is cached. Prepares for the removal of SWAP_HAS_CACHE.
>
> Signed-off-by: Kairui Song <kasong@...cent.com>
> ---
> mm/swap.h | 11 ++++++++---
> mm/swap_state.c | 16 ++++++++++++++++
> mm/swapfile.c | 55 +++++++++++++++++++++++++++++--------------------------
> mm/userfaultfd.c | 10 +++-------
> 4 files changed, 56 insertions(+), 36 deletions(-)
>
> diff --git a/mm/swap.h b/mm/swap.h
> index 03694ffa662f..73f07bcea5f0 100644
> --- a/mm/swap.h
> +++ b/mm/swap.h
> @@ -275,6 +275,7 @@ void __swapcache_clear_cached(struct swap_info_struct *si,
> * swap entries in the page table, similar to locking swap cache folio.
> * - See the comment of get_swap_device() for more complex usage.
> */
> +bool swap_cache_check_folio(swp_entry_t entry);
> struct folio *swap_cache_get_folio(swp_entry_t entry);
> void *swap_cache_get_shadow(swp_entry_t entry);
> void swap_cache_del_folio(struct folio *folio);
> @@ -335,8 +336,6 @@ static inline int swap_zeromap_batch(swp_entry_t entry, int max_nr,
>
> static inline int non_swapcache_batch(swp_entry_t entry, int max_nr)
> {
> - struct swap_info_struct *si = __swap_entry_to_info(entry);
> - pgoff_t offset = swp_offset(entry);
> int i;
>
> /*
> @@ -345,8 +344,9 @@ static inline int non_swapcache_batch(swp_entry_t entry, int max_nr)
> * be in conflict with the folio in swap cache.
> */
> for (i = 0; i < max_nr; i++) {
> - if ((si->swap_map[offset + i] & SWAP_HAS_CACHE))
> + if (swap_cache_check_folio(entry))
> return i;
> + entry.val++;
> }
>
> return i;
> @@ -449,6 +449,11 @@ static inline int swap_writeout(struct folio *folio,
> return 0;
> }
>
> +static inline bool swap_cache_check_folio(swp_entry_t entry)
> +{
> + return false;
> +}
> +
> static inline struct folio *swap_cache_get_folio(swp_entry_t entry)
> {
> return NULL;
> diff --git a/mm/swap_state.c b/mm/swap_state.c
> index 85d9f99c384f..41d4fa056203 100644
> --- a/mm/swap_state.c
> +++ b/mm/swap_state.c
> @@ -103,6 +103,22 @@ struct folio *swap_cache_get_folio(swp_entry_t entry)
> return NULL;
> }
>
> +/**
> + * swap_cache_check_folio - Check if a swap slot has cache.
> + * @entry: swap entry indicating the slot.
> + *
> + * Context: Caller must ensure @entry is valid and protect the swap
> + * device with reference count or locks.
> + */
> +bool swap_cache_check_folio(swp_entry_t entry)
> +{
> + unsigned long swp_tb;
> +
> + swp_tb = swap_table_get(__swap_entry_to_cluster(entry),
> + swp_cluster_offset(entry));
> + return swp_tb_is_folio(swp_tb);
> +}
> +
The name swap_cache_check_folio() sounds a bit odd to me — what we’re
actually doing is checking whether the swapcache contains (or is)
a folio, i.e., whether there’s a folio hit in the swapcache.
The word "check" could misleadingly suggest verifying the folio’s health
or validity instead.
what about swap_cache_has_folio() or simply:
struct folio *__swap_cache_get_folio(swp_entry_t entry);
This would return the folio without taking the lock, or NULL if not found?
Thanks
Barry
Powered by blists - more mailing lists