The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Usama Arif <usama.arif@linux.dev>
To: Yosry Ahmed <yosry@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	david@kernel.org, chrisl@kernel.org, kasong@tencent.com,
	ljs@kernel.org, ziy@nvidia.com, linux-mm@kvack.org,
	ying.huang@linux.alibaba.com, Baoquan He <baoquan.he@linux.dev>,
	willy@infradead.org, youngjun.park@lge.com, hannes@cmpxchg.org,
	riel@surriel.com, shakeel.butt@linux.dev, alex@ghiti.fr,
	kas@kernel.org, baohua@kernel.org, dev.jain@arm.com,
	baolin.wang@linux.alibaba.com, npache@redhat.com,
	"Liam R. Howlett" <liam@infradead.org>,
	ryan.roberts@arm.com, Vlastimil Babka <vbabka@kernel.org>,
	lance.yang@linux.dev, linux-kernel@vger.kernel.org,
	nphamcs@gmail.com, shikemeng@huaweicloud.com,
	kernel-team@meta.com
Subject: Re: [PATCH v4 00/11] mm: PMD-level swap entries for anonymous THPs
Date: Mon, 13 Jul 2026 17:17:57 +0100	[thread overview]
Message-ID: <03a20b9a-2984-4666-832d-0e35df919a7d@linux.dev> (raw)
In-Reply-To: <CAO9r8zP586AFSeNKuaUVZgkPb-mKuLGbQ8m5_od_-GLg7bu90w@mail.gmail.com>



On 13/07/2026 16:56, Yosry Ahmed wrote:
> On Mon, Jul 13, 2026 at 6:36 AM Usama Arif <usama.arif@linux.dev> wrote:
>>
>> This is the PMD swap entry core series. The preparatory PMD softleaf [1]
>> cleanup series has been merged in akpm/mm-new, so this series is now
>> based directly on akpm/mm-new.
>>
>> When reclaim swaps out a PMD-mapped anonymous THP today, the PMD is
>> split into HPAGE_PMD_NR PTE-level swap entries via TTU_SPLIT_HUGE_PMD
>> before unmap.  This series introduces a PMD-level swap entry so the
>> huge mapping can survive the swap round-trip and do_huge_pmd_swap_page()
>> can restore the PMD mapping directly on swap-in, without waiting for
>> khugepaged to collapse the range later.
>>
>> The PMD swap entry is a compact page-table encoding for HPAGE_PMD_NR
>> consecutive swap slots.  swap_map accounting remains per-slot and is
>> unchanged.  Importantly, a PMD swap entry does not promise that the swap
>> cache always contains one PMD-sized folio.  While the cache is empty or
>> contains one PMD-sized folio, PMD-level handling can proceed.  Once the
>> cache has split/per-slot state, users either inspect the individual
>> slots directly (mincore) or split the PMD swap entry and retry through
>> the PTE path (fault, swapoff, MADV_WILLNEED, UFFDIO_MOVE).  Likewise,
>> if any slot is still backed by zswap's per-page store, PMD-order
>> swap-in consumers split and let the PTE path load the range page by page;
>> an all-on-disk range can still be read back as one PMD-sized folio.
>>
>> The series is ordered so every consumer can handle PMD swap entries
>> before the swap-out producer starts installing them.  The swap-out patch
>> is the last functional change.
>>
>> Patch breakdown:
>>
>>   1. mm: add PMD swap entry detection support
>>      Add pmd_is_swap_entry(), teach the softleaf layer that PMD swap
>>      entries are valid PMD softleaf entries, and add per-arch
>>      pmd_swp_*exclusive helpers.
>>
>>   2. mm: add PMD swap entry splitting support
>>      Teach __split_huge_pmd_locked() to split a PMD swap entry into
>>      HPAGE_PMD_NR PTE swap entries.  This is the common fallback path
>>      whenever PMD-level handling is unsafe or unavailable.
>>
>>   3. mm: handle PMD swap entries in fork path
>>      Copy a PMD swap entry in fork via one
>>      swap_dup_entries_direct(HPAGE_PMD_NR) operation, with the same
>>      swapoff/mmlist preparation rules used by PTE entries.
>>
>>   4. mm: zswap: add range lookup for large-folio swapin
>>      Teach zswap_load() to let all-on-disk large folio reads proceed to
>>      the backing swap device, and add zswap_range_has_entry() so PMD
>>      swap-entry consumers can split only when a specific range has
>>      per-page zswap state.
>>
>>   5. mm: swap in PMD swap entries as whole THPs during swapoff
>>      Add swap_pmd_cache_lookup() and use it from swapoff.  Empty cache
>>      and PMD-sized cache state can be handled at PMD order; split cache
>>      state, zswap-backed slots, allocation/read failure, or non-uptodate
>>      folios split the PMD and fall back to unuse_pte_range().
>>
>>   6. mm: handle PMD swap entries in non-present PMD walkers
>>      Teach zap, mprotect, soft-dirty, uffd-wp, smaps, mincore,
>>      mempolicy, khugepaged, HMM, and madvise walkers about PMD swap
>>      entries.  mincore reports PMD-sized cache state directly and checks
>>      per-page slots after the cache has split.
>>
>>   7. mm: handle PMD swap entries in MADV_WILLNEED
>>      Let MADV_WILLNEED prefetch a PMD swap entry at PMD order when safe,
>>      treat an already cached PMD-sized folio as complete, and split/retry
>>      through PTEs for split cache state, zswap-backed slots, or races
>>      with per-slot cache population.
>>
>>   8. mm: handle PMD swap entries in UFFDIO_MOVE
>>      Move PMD swap entries whole when the covered range is empty or
>>      backed by one PMD-sized folio.  Split/per-slot cache state returns
>>      -EAGAIN after splitting so retry can use the PTE move path and
>>      update per-page rmap metadata.
>>
>>   9. mm: handle PMD swap entry faults on swap-in
>>      Add do_huge_pmd_swap_page().  It maps a PMD-sized cached folio
>>      directly, or allocates/reads at PMD order when the cache is empty
>>      and the range has no zswap entries.  Split cache state, zswap-backed
>>      slots, and PMD-order resource failures fall back to the PTE path.
>>
>>  10. mm: install PMD swap entries on swap-out
>>      Stop forcing TTU_SPLIT_HUGE_PMD for PMD-mappable swapcache folios
>>      and install one PMD swap entry instead.  Zswap still stores the THP
>>      as per-page compressed entries; PMD-order swap-in consumers preserve
>>      a PMD-sized cached folio or read an all-on-disk range as a whole THP,
>>      and split before reading per-page zswap state.
>>
>>  11. selftests/mm: add PMD swap entry tests
>>      Add pmd_swap selftests covering swap-out/in, fork, fork+COW,
>>      repeated cycles, write fault, munmap, mprotect, mremap, pagemap,
>>      mincore, MADV_FREE, MADV_WILLNEED, UFFDIO_MOVE, and swapoff.
>>
>> Notes on zswap:
>>
>>   Native PMD-order zswap load/store is intentionally left for a follow-up.
>>   Alexandre Ghiti is currently working this.
>>   This series can still preserve PMD swap entries while zswap is enabled:
>>   zswap stores the THP as order-0 entries, and PMD-order swap-in
>>   consumers split any range that has zswap entries before reading it.  If
>>   zswap has written the whole range back to disk, or the swap cache still
>>   contains one PMD-sized folio, PMD-level handling can proceed.
> 
> So in the swapout path, a single PMD swap entry is created, but
> order-0 pages are compressed and stored independently in zswap? Just
> checking I understood this correctly.

Yes that is correct, swapout installs PMD swap entry in try_to_unmap_one().
When the swapped-out THP reaches zswap, current zswap still stores it as
independent order-0 entries keyed by the individual swap slots. On
PMD-order swap-in, we only proceed as a THP if the swap cache still has
one PMD-sized folio, or if none of the covered slots is present in zswap
and the whole range can be read from disk. If any slot is still backed by
zswap, we split the PMD swap entry and retry through the normal PTE path.


      reply	other threads:[~2026-07-13 16:18 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-13 13:35 [PATCH v4 00/11] mm: PMD-level swap entries for anonymous THPs Usama Arif
2026-07-13 13:35 ` [PATCH v4 01/11] mm: add PMD swap entry detection support Usama Arif
2026-07-13 13:35 ` [PATCH v4 02/11] mm: add PMD swap entry splitting support Usama Arif
2026-07-13 13:35 ` [PATCH v4 03/11] mm: handle PMD swap entries in fork path Usama Arif
2026-07-13 13:35 ` [PATCH v4 04/11] mm: zswap: add range lookup for large-folio swapin Usama Arif
2026-07-13 16:02   ` Yosry Ahmed
2026-07-13 16:29     ` Usama Arif
2026-07-13 16:55       ` Yosry Ahmed
2026-07-13 13:35 ` [PATCH v4 05/11] mm: swap in PMD swap entries as whole THPs during swapoff Usama Arif
2026-07-13 13:35 ` [PATCH v4 06/11] mm: handle PMD swap entries in non-present PMD walkers Usama Arif
2026-07-13 13:35 ` [PATCH v4 07/11] mm: handle PMD swap entries in MADV_WILLNEED Usama Arif
2026-07-13 13:35 ` [PATCH v4 08/11] mm: handle PMD swap entries in UFFDIO_MOVE Usama Arif
2026-07-13 13:35 ` [PATCH v4 09/11] mm: handle PMD swap entry faults on swap-in Usama Arif
2026-07-13 13:35 ` [PATCH v4 10/11] mm: install PMD swap entries on swap-out Usama Arif
2026-07-13 13:35 ` [PATCH v4 11/11] selftests/mm: add PMD swap entry tests Usama Arif
2026-07-13 15:56 ` [PATCH v4 00/11] mm: PMD-level swap entries for anonymous THPs Yosry Ahmed
2026-07-13 16:17   ` Usama Arif [this message]

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=03a20b9a-2984-4666-832d-0e35df919a7d@linux.dev \
    --to=usama.arif@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=alex@ghiti.fr \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=baoquan.he@linux.dev \
    --cc=chrisl@kernel.org \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=hannes@cmpxchg.org \
    --cc=kas@kernel.org \
    --cc=kasong@tencent.com \
    --cc=kernel-team@meta.com \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=npache@redhat.com \
    --cc=nphamcs@gmail.com \
    --cc=riel@surriel.com \
    --cc=ryan.roberts@arm.com \
    --cc=shakeel.butt@linux.dev \
    --cc=shikemeng@huaweicloud.com \
    --cc=vbabka@kernel.org \
    --cc=willy@infradead.org \
    --cc=ying.huang@linux.alibaba.com \
    --cc=yosry@kernel.org \
    --cc=youngjun.park@lge.com \
    --cc=ziy@nvidia.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