mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joshua Hahn <joshua.hahnjy@gmail.com>
To: Alexandre Ghiti <alex@ghiti.fr>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org,  linux-kernel@vger.kernel.org,
	Barry Song <baohua@kernel.org>,
	 David Hildenbrand <david@kernel.org>,
	Kairui Song <kasong@tencent.com>, Chris Li <chrisl@kernel.org>,
	 Nhat Pham <nphamcs@gmail.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	 Yosry Ahmed <yosry@kernel.org>,
	Chengming Zhou <chengming.zhou@linux.dev>,
	 Baoquan He <baoquan.he@linux.dev>,
	Kemeng Shi <shikemeng@huaweicloud.com>,
	 Youngjun Park <youngjun.park@lge.com>,
	"Liam R . Howlett" <liam@infradead.org>,
	 Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>,
	 Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>
Subject: Re: [PATCH v2] mm: free the swap slot of a dirty swapin folio
Date: Mon, 30 Nov 2026 10:36:42 -0800	[thread overview]
Message-ID: <aw3AUYhqsYnYUejg@devbig011.atn3.facebook.com> (raw)
In-Reply-To: <20261127142357.1112193-1-alex@ghiti.fr>

On Fri, Nov 27, 2026 at 03:23:27PM +0100, Alexandre Ghiti wrote:
> do_swap_page() frees the swap cache of an exclusive folio on a write
> fault only. But when the folio is already dirty, the copy in its swap
> slot is stale: the slot only reserves swap space until the folio is
> reclaimed again or its owner exits, and the folio has to be written out
> again anyway.

[... snip ...]

>                      base            patched
>   exit time    989 +- 24 ms       502 +- 28 ms   (-49%)
> 
> The cost is paid by folios that keep cycling between zswap and memory:
> each reclaim allocates a new slot and adds the folio to the swap cache
> again. On a kernel build in a 600 MiB memcg (-j4, defconfig), this is
> not measurable (mean +- stddev of 5 runs on bare metal):
> 
>                        base            patched
>   time (s)        592.4 +- 1.1      592.4 +- 0.9    (+0.0%)
>   sys (s)         256.6 +- 1.5      257.5 +- 1.4    (+0.3%)
> 
> In the worst case, random reads over 4 GiB of anonymous memory in a
> 3 GiB memcg, so that about half the reads are zswap read faults and the
> task spends all its time in the kernel, throughput drops by 1.1-1.4%
> (mean +- stddev of 5 runs on bare metal):
> 
>                        base            patched
>   reads/s, 1 thread   37310 +- 182     36889 +- 77     (-1.1%)
>   reads/s, 8 threads 291937 +- 802    287954 +- 373    (-1.4%)
> 
> Signed-off-by: Alexandre Ghiti <alex@ghiti.fr>

Hi Alex,

Thank you for the patch! This patch makes sense and looks good to me.
The numbers are also really great!

Sorry to do this, but I just have one nit below...

> ---
> 
> Changes in v2:
>     - Free the swap cache of a dirty folio even when not exclusive (David)
>     - Make the comment and the changelog generic, zswap being the common
>       case (David, Nhat)
>     
> v1: https://lore.kernel.org/all/20261126094318.244973-1-alex@ghiti.fr/
> 
>  mm/memory.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/memory.c b/mm/memory.c
> index d477a4f986bc..c83c67cb759b 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -4711,9 +4711,12 @@ static inline bool should_try_to_free_swap(struct swap_info_struct *si,
>  		return true;
>  
>  	/*
> -	 * Free the swapcache only if we are the exclusive user and
> -	 * this is a write fault.
> +	 * Free the swapcache if the folio is already dirty, or if we will dirty it
> +	 * immediately afterwards by writing to it.
>  	 */

I'm not sure this comment really helps explain why being dirty matters
here, which I think is the interesting insight captured by your commit
message. The idea is that dirty folio == swap slot is stale, right?

What about:

	/*
	 * Free the swapcache if the folio is dirty (it has diverged from its
	 * swap slot) or if an exclusive write will make it diverge.
	 */

Let me know what you think. Regardless I think the change is good, so
please feel free to add:
Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>

Thanks again Alex! Have a great day,
Joshua

> +	if (folio_test_dirty(folio))
> +		return true;
> +
>  	return (fault_flags & FAULT_FLAG_WRITE) && exclusive;
>  }
>  
> -- 
> 2.53.1-Meta
> 
> 

  parent reply	other threads:[~2026-11-30 18:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 14:23 Alexandre Ghiti
2026-11-29 10:27 ` David Hildenbrand (Arm)
2026-11-30 18:36 ` Joshua Hahn [this message]
2026-11-30 19:11 ` Nhat Pham

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=aw3AUYhqsYnYUejg@devbig011.atn3.facebook.com \
    --to=joshua.hahnjy@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex@ghiti.fr \
    --cc=baohua@kernel.org \
    --cc=baoquan.he@linux.dev \
    --cc=chengming.zhou@linux.dev \
    --cc=chrisl@kernel.org \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=kasong@tencent.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=nphamcs@gmail.com \
    --cc=rppt@kernel.org \
    --cc=shikemeng@huaweicloud.com \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=yosry@kernel.org \
    --cc=youngjun.park@lge.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

all inboxes | Powered by JetHome®