* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-03 18:02 [PATCH] mm/shmem: bypass swap readahead for zswap Usama Arif
@ 2026-12-03 19:49 ` Yosry Ahmed
2026-12-03 19:53 ` Nhat Pham
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Yosry Ahmed @ 2026-12-03 19:49 UTC (permalink / raw)
To: Usama Arif
Cc: Andrew Morton, hughd, david, baolin.wang, hannes, nphamcs,
chengming.zhou, chrisl, kasong, baohua, shikemeng, baoquan.he,
youngjun.park, alex, linux-mm, riel, shakeel.butt, kernel-team,
rkeilty, atish.patra, dgreid
On Thu, Dec 3, 2026 at 10:03 AM Usama Arif <usama.arif@linux.dev> wrote:
>
> Commit 7ed825f0f766 ("mm: bypass swap readahead for zswap") made
> do_swap_page() skip readahead for zswap entries, but
> shmem_swapin_folio() still only skips it for SWP_SYNCHRONOUS_IO
> devices.
>
> zswap decompresses in the faulting task, so readahead has no I/O to
> overlap and only slows the fault down. And since zswap loads are
> exclusive, pages read ahead but never used stay uncompressed in memory
> until reclaim compresses them again.
>
> Use swap_entry_synchronous() in shmem_swapin_folio(), like
> do_swap_page(). zswap entries then take the SWP_SYNCHRONOUS_IO path,
> which already uses order-0 folios once zswap has been enabled. Entries
> on the backing device keep cluster readahead.
>
> On productions hosts that run VM workloads backed by shmem guest memory
> with memfds and swaps only to zswap, about a third of shmem readahead pages
> were never used. In a QEMU guest with a 2 GB memfd in zswap and
> page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before
> this change and none after. The memcg grew 24 MiB less and the faults took
> 12% less time.
>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
Reviewed-by: Yosry Ahmed <yosry@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-03 18:02 [PATCH] mm/shmem: bypass swap readahead for zswap Usama Arif
2026-12-03 19:49 ` Yosry Ahmed
@ 2026-12-03 19:53 ` Nhat Pham
2026-12-03 19:57 ` Shakeel Butt
2026-12-03 20:03 ` Andrew Morton
3 siblings, 0 replies; 6+ messages in thread
From: Nhat Pham @ 2026-12-03 19:53 UTC (permalink / raw)
To: Usama Arif
Cc: Andrew Morton, hughd, david, baolin.wang, hannes, yosry,
chengming.zhou, chrisl, kasong, baohua, shikemeng, baoquan.he,
youngjun.park, alex, linux-mm, riel, shakeel.butt, kernel-team,
rkeilty, atish.patra, dgreid
On Thu, Dec 3, 2026 at 11:03 AM Usama Arif <usama.arif@linux.dev> wrote:
>
> Commit 7ed825f0f766 ("mm: bypass swap readahead for zswap") made
> do_swap_page() skip readahead for zswap entries, but
> shmem_swapin_folio() still only skips it for SWP_SYNCHRONOUS_IO
> devices.
>
> zswap decompresses in the faulting task, so readahead has no I/O to
> overlap and only slows the fault down. And since zswap loads are
> exclusive, pages read ahead but never used stay uncompressed in memory
> until reclaim compresses them again.
>
> Use swap_entry_synchronous() in shmem_swapin_folio(), like
> do_swap_page(). zswap entries then take the SWP_SYNCHRONOUS_IO path,
> which already uses order-0 folios once zswap has been enabled. Entries
> on the backing device keep cluster readahead.
>
> On productions hosts that run VM workloads backed by shmem guest memory
> with memfds and swaps only to zswap, about a third of shmem readahead pages
> were never used. In a QEMU guest with a 2 GB memfd in zswap and
> page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before
> this change and none after. The memcg grew 24 MiB less and the faults took
> 12% less time.
>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
Reviewed-by: Nhat Pham <nphamcs@gmail.com>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-03 18:02 [PATCH] mm/shmem: bypass swap readahead for zswap Usama Arif
2026-12-03 19:49 ` Yosry Ahmed
2026-12-03 19:53 ` Nhat Pham
@ 2026-12-03 19:57 ` Shakeel Butt
2026-12-03 20:03 ` Andrew Morton
3 siblings, 0 replies; 6+ messages in thread
From: Shakeel Butt @ 2026-12-03 19:57 UTC (permalink / raw)
To: Usama Arif
Cc: Andrew Morton, hughd, david, baolin.wang, hannes, yosry, nphamcs,
chengming.zhou, chrisl, kasong, baohua, shikemeng, baoquan.he,
youngjun.park, alex, linux-mm, riel, kernel-team, rkeilty,
atish.patra, dgreid
On Thu, Dec 03, 2026 at 10:02:53AM -0800, Usama Arif wrote:
> Commit 7ed825f0f766 ("mm: bypass swap readahead for zswap") made
> do_swap_page() skip readahead for zswap entries, but
> shmem_swapin_folio() still only skips it for SWP_SYNCHRONOUS_IO
> devices.
>
> zswap decompresses in the faulting task, so readahead has no I/O to
> overlap and only slows the fault down. And since zswap loads are
> exclusive, pages read ahead but never used stay uncompressed in memory
> until reclaim compresses them again.
>
> Use swap_entry_synchronous() in shmem_swapin_folio(), like
> do_swap_page(). zswap entries then take the SWP_SYNCHRONOUS_IO path,
> which already uses order-0 folios once zswap has been enabled. Entries
> on the backing device keep cluster readahead.
>
> On productions hosts that run VM workloads backed by shmem guest memory
> with memfds and swaps only to zswap, about a third of shmem readahead pages
> were never used. In a QEMU guest with a 2 GB memfd in zswap and
> page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before
> this change and none after. The memcg grew 24 MiB less and the faults took
> 12% less time.
>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
Acked-by Shakeel Butt <shakeel.butt@linux.dev>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-03 18:02 [PATCH] mm/shmem: bypass swap readahead for zswap Usama Arif
` (2 preceding siblings ...)
2026-12-03 19:57 ` Shakeel Butt
@ 2026-12-03 20:03 ` Andrew Morton
2026-12-03 20:07 ` Usama Arif
3 siblings, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2026-12-03 20:03 UTC (permalink / raw)
To: Usama Arif
Cc: hughd, david, baolin.wang, hannes, yosry, nphamcs, chengming.zhou,
chrisl, kasong, baohua, shikemeng, baoquan.he, youngjun.park,
alex, linux-mm, riel, shakeel.butt, kernel-team, rkeilty,
atish.patra, dgreid
On Thu, 3 Dec 2026 10:02:53 -0800 Usama Arif <usama.arif@linux.dev> wrote:
> Commit 7ed825f0f766 ("mm: bypass swap readahead for zswap")
That's in mm-unstable.
> made
> do_swap_page() skip readahead for zswap entries, but
> shmem_swapin_folio() still only skips it for SWP_SYNCHRONOUS_IO
> devices.
>
> zswap decompresses in the faulting task, so readahead has no I/O to
> overlap and only slows the fault down. And since zswap loads are
> exclusive, pages read ahead but never used stay uncompressed in memory
> until reclaim compresses them again.
>
> Use swap_entry_synchronous() in shmem_swapin_folio(), like
> do_swap_page(). zswap entries then take the SWP_SYNCHRONOUS_IO path,
> which already uses order-0 folios once zswap has been enabled. Entries
> on the backing device keep cluster readahead.
>
> On productions hosts that run VM workloads backed by shmem guest memory
> with memfds and swaps only to zswap, about a third of shmem readahead pages
> were never used. In a QEMU guest with a 2 GB memfd in zswap and
> page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before
> this change and none after. The memcg grew 24 MiB less and the faults took
> 12% less time.
>
> ...
>
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -2570,8 +2570,8 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
> /* Look it up and read it in.. */
> folio = swap_cache_get_folio(swap);
> if (!folio) {
> - if (data_race(si->flags & SWP_SYNCHRONOUS_IO)) {
> - /* Direct swapin skipping swap cache & readahead */
> + if (swap_entry_synchronous(si, swap)) {
> + /* Skip readahead: synchronous device or zswap */
> folio = shmem_swap_alloc_folio(inode, vmf, index,
> swap, order, gfp);
> } else {
So I'll add this as a squashable fix against Alexandre's "mm: bypass
swap readahead for zswap" if that's OK.
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-03 20:03 ` Andrew Morton
@ 2026-12-03 20:07 ` Usama Arif
0 siblings, 0 replies; 6+ messages in thread
From: Usama Arif @ 2026-12-03 20:07 UTC (permalink / raw)
To: Andrew Morton
Cc: hughd, david, baolin.wang, hannes, yosry, nphamcs, chengming.zhou,
chrisl, kasong, baohua, shikemeng, baoquan.he, youngjun.park,
alex, linux-mm, riel, shakeel.butt, kernel-team, rkeilty,
atish.patra, dgreid
On 03/12/2026 12:03, Andrew Morton wrote:
> On Thu, 3 Dec 2026 10:02:53 -0800 Usama Arif <usama.arif@linux.dev> wrote:
>
>> Commit 7ed825f0f766 ("mm: bypass swap readahead for zswap")
>
> That's in mm-unstable.
>
>> made
>> do_swap_page() skip readahead for zswap entries, but
>> shmem_swapin_folio() still only skips it for SWP_SYNCHRONOUS_IO
>> devices.
>>
>> zswap decompresses in the faulting task, so readahead has no I/O to
>> overlap and only slows the fault down. And since zswap loads are
>> exclusive, pages read ahead but never used stay uncompressed in memory
>> until reclaim compresses them again.
>>
>> Use swap_entry_synchronous() in shmem_swapin_folio(), like
>> do_swap_page(). zswap entries then take the SWP_SYNCHRONOUS_IO path,
>> which already uses order-0 folios once zswap has been enabled. Entries
>> on the backing device keep cluster readahead.
>>
>> On productions hosts that run VM workloads backed by shmem guest memory
>> with memfds and swaps only to zswap, about a third of shmem readahead pages
>> were never used. In a QEMU guest with a 2 GB memfd in zswap and
>> page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before
>> this change and none after. The memcg grew 24 MiB less and the faults took
>> 12% less time.
>>
>> ...
>>
>> --- a/mm/shmem.c
>> +++ b/mm/shmem.c
>> @@ -2570,8 +2570,8 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
>> /* Look it up and read it in.. */
>> folio = swap_cache_get_folio(swap);
>> if (!folio) {
>> - if (data_race(si->flags & SWP_SYNCHRONOUS_IO)) {
>> - /* Direct swapin skipping swap cache & readahead */
>> + if (swap_entry_synchronous(si, swap)) {
>> + /* Skip readahead: synchronous device or zswap */
>> folio = shmem_swap_alloc_folio(inode, vmf, index,
>> swap, order, gfp);
>> } else {
>
> So I'll add this as a squashable fix against Alexandre's "mm: bypass
> swap readahead for zswap" if that's OK.
Ah its not really a fix, it can go in separately.
Thanks!
Usama
^ permalink raw reply [flat|nested] 6+ messages in thread