All of lore.kernel.org
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Alexandre Ghiti <alex@ghiti.fr>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, Barry Song <baohua@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: Sun, 29 Nov 2026 11:27:50 +0100	[thread overview]
Message-ID: <56cabcdc-a228-4e57-b8f2-8a007335a897@kernel.org> (raw)
In-Reply-To: <20261127142357.1112193-1-alex@ghiti.fr>

On 11/27/26 15:23, 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.
> 
> The common case is zswap: zswap_load() drops its compressed copy and
> dirties the folio, so every zswap read fault leaves such a folio behind.
> Without zswap, it only happens when reclaim bailed out after adding the
> folio to the swap cache but before writing it out, or when the swap
> write failed.
> 
> Such folios add up, and they are expensive to free at exit: on a large
> production workload, the exit time doubled when zswap was enabled. A
> third of the increase comes from the folios left in the swap cache,
> each costing about 3x a resident page to tear down; the rest comes from
> freeing the zswap entries.
> 
> So free the swap cache of a dirty folio as well: folio_free_swap() only
> releases the slot once no other page table references it. The only cost
> is a new slot allocation on the folio's next reclaim, which write faults
> already pay.
> 
> On the production workload, this patch removed that third: the exit time
> decreased by about 15%. On a simple microbenchmark, 4 GiB of anonymous
> memory in a memcg pushed to swap, read back, then SIGKILLed in a QEMU
> guest (mean +- stddev of 9 runs):
> 
>                      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>
> ---

Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>

I'll wait for more review before picking this up.

-- 
Cheers,

David

  reply	other threads:[~2026-11-29 10:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 14:23 [PATCH v2] mm: free the swap slot of a dirty swapin folio Alexandre Ghiti
2026-11-29 10:27 ` David Hildenbrand (Arm) [this message]
2026-11-30 18:36 ` Joshua Hahn
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=56cabcdc-a228-4e57-b8f2-8a007335a897@kernel.org \
    --to=david@kernel.org \
    --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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.