lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGsJ_4y9sQd9x-kOqPZzaNPTtSOhFSYzFdjiRsJFjT2myYEK7w@mail.gmail.com>
Date: Mon, 17 Nov 2025 16:27:38 +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>, 
	Yosry Ahmed <yosry.ahmed@...ux.dev>, David Hildenbrand <david@...nel.org>, 
	Johannes Weiner <hannes@...xchg.org>, Youngjun Park <youngjun.park@....com>, 
	Hugh Dickins <hughd@...gle.com>, Baolin Wang <baolin.wang@...ux.alibaba.com>, 
	Ying Huang <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 v2 02/19] mm, swap: split swap cache preparation loop into
 a standalone helper

On Mon, Nov 17, 2025 at 2:12 AM Kairui Song <ryncsn@...il.com> wrote:
>
> From: Kairui Song <kasong@...cent.com>
>
> To prepare for the removal of swap cache bypass swapin, introduce a new
> helper that accepts an allocated and charged fresh folio, prepares the
> folio, the swap map, and then adds the folio to the swap cache.
>
> This doesn't change how swap cache works yet, we are still depending on
> the SWAP_HAS_CACHE in the swap map for synchronization. But all
> synchronization hacks are now all in this single helper.
>
> No feature change.
>
> Signed-off-by: Kairui Song <kasong@...cent.com>

Overall,
Reviewed-by: Barry Song <baohua@...nel.org>
with a few minor nits.

> ---
>  mm/swap_state.c | 197 +++++++++++++++++++++++++++++++-------------------------
>  1 file changed, 109 insertions(+), 88 deletions(-)
>
> diff --git a/mm/swap_state.c b/mm/swap_state.c
> index 08252eaef32f..7b93704fcbe7 100644
> --- a/mm/swap_state.c
> +++ b/mm/swap_state.c
> @@ -402,6 +402,97 @@ void swap_update_readahead(struct folio *folio, struct vm_area_struct *vma,
>         }
>  }
>
> +/**
> + * __swap_cache_prepare_and_add - Prepare the folio and add it to swap cache.
> + * @entry: swap entry to be bound to the folio.
> + * @folio: folio to be added.
> + * @gfp: memory allocation flags for charge, can be 0 if @charged if true.
> + * @charged: if the folio is already charged.
> + * @skip_if_exists: if the slot is in a cached state, return NULL.
> + *                  This is an old workaround that will be removed shortly.
> + *
> + * Update the swap_map and add folio as swap cache, typically before swapin.
> + * All swap slots covered by the folio must have a non-zero swap count.
> + *
> + * Context: Caller must protect the swap device with reference count or locks.
> + * Return: Returns the folio being added on success. Returns the existing
> + * folio if @entry is cached. Returns NULL if raced with swapin or swapoff.

Not a native speaker, but I wonder if adding *already* would make the
comment clearer, for example: "Returns the existing folio if @entry is
already cached."

BTW, returning NULL may not be the best option. Returning an ERR_PTR
seems more specific?

Thanks
Barry

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ