From: Usama Arif <usama.arif@linux.dev>
To: "David Hildenbrand (Arm)" <david@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
chrisl@kernel.org, kasong@tencent.com, ljs@kernel.org,
ziy@nvidia.com, linux-mm@kvack.org
Cc: 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, Nico Pache <nico.pache@linux.dev>,
"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, yosry@kernel.org,
kernel-team@meta.com
Subject: Re: [PATCH v6 02/12] mm: add PMD swap entry detection support
Date: Wed, 19 Aug 2026 13:31:08 +0100 [thread overview]
Message-ID: <5baead5e-b9e9-4850-9ce3-e48a2e5db2ca@linux.dev> (raw)
In-Reply-To: <69e8469c-aa7f-4141-be3c-796c9cf11f2f@kernel.org>
On 18/08/2026 15:40, David Hildenbrand (Arm) wrote:
> On 8/18/26 15:09, Usama Arif wrote:
>> Currently when a PMD-mapped THP is swapped out, the PMD is always
>> split into HPAGE_PMD_NR PTE-level swap entries. To preserve huge
>> page information across swap cycles, later patches will install a
>> single PMD-level swap entry instead. Add the infrastructure to detect
>> those entries.
>>
>> Teach the softleaf layer to recognise PMD swap entries:
>> pmd_is_swap_entry() detects them and softleaf_is_valid_pmd_entry()
>> accepts them as a valid non-present type. Because swap entries do not
>> encode a PFN, make pmd_softleaf_to_folio() warn and return NULL for them
>> instead of passing the swap offset to softleaf_to_folio(). Clear the
>> exclusive overlay bit in softleaf_from_pmd() before decoding, matching
>> how soft_dirty and uffd bits are already stripped.
>>
>> Add pmd_swp_mkexclusive(), pmd_swp_exclusive(), and
>> pmd_swp_clear_exclusive() helpers to each architecture that supports
>> PMD softleaf entries (x86, arm64, s390, riscv, loongarch, powerpc),
>> mirroring the existing PTE swap exclusive helpers in each arch's
>> pgtable.h.
>
> Ah, for migration entries we still use a dedicated migratetype. I actually have
> on my todo list to move to PTE bits as well.
>
> (likely the _swp_ part should then be renamed to indicate that this is for
> softdirty entries, not just swap entries)
>
Agreed. I kept the pmd_swp_* spelling to mirror the existing pte_swp_* API.
Renaming the broader softleaf API is independent of this series. Maybe I can
add it as a followup?
>> Provide generic no-op PMD swap exclusive fallbacks for
>> architectures without PMD softleaf support, matching the generic PMD
>> swap soft-dirty fallbacks.
>
> No softleaf implies to migration and no swap, so this would work.
>
> You should extend mm/debug_vm_pgtable.c in a separate commit to test what
> pte_swap_exclusive_tests() tests for PMDs.
>
I have added this in my series, and will include it in the next revision, Thanks!
>>
>> Signed-off-by: Usama Arif <usama.arif@linux.dev>
>> ---
>> arch/arm64/include/asm/pgtable.h | 6 +++++
>> arch/loongarch/include/asm/pgtable.h | 19 ++++++++++++++
>> arch/powerpc/include/asm/book3s/64/pgtable.h | 17 +++++++++++++
>> arch/riscv/include/asm/pgtable.h | 15 +++++++++++
>> arch/s390/include/asm/pgtable.h | 17 +++++++++++++
>> arch/x86/include/asm/pgtable.h | 17 +++++++++++++
>
> I'm sorry for asking you to compete with Kiryll's series by creating one patch
> for each architecture that directly jumps at arch maintainers :)
>
I have now split the architecture helpers into separate patches, followed by generic
support for the next revision. I think I will need split patch 7 and patch 12 into
several independent patches as well? This will significantly grow the patch count
which is what I was trying to avoid as I feel that makes it more daunting to review
(atleast for me), but I will try and keep it under 57 patches to not beat Kiryl :)
> [...]
>
>> #ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
>> static inline pte_t pte_swp_mksoft_dirty(pte_t pte)
>> {
>> diff --git a/include/linux/leafops.h b/include/linux/leafops.h
>> index 7c13c58a5e218..4a6c52974b305 100644
>> --- a/include/linux/leafops.h
>> +++ b/include/linux/leafops.h
>> @@ -102,6 +102,8 @@ static inline softleaf_t softleaf_from_pmd(pmd_t pmd)
>> pmd = pmd_swp_clear_soft_dirty(pmd);
>> if (pmd_swp_uffd(pmd))
>> pmd = pmd_swp_clear_uffd(pmd);
>> + if (pmd_swp_exclusive(pmd))
>> + pmd = pmd_swp_clear_exclusive(pmd);
>
> Can't we just unconditionally clear these flags?
>
> pmd = pmd_swp_clear_uffd(pmd);
> pmd = pmd_swp_clear_exclusive(pmd);
>
> Avoids these rather unnecessary conditionals unless I am missing something.
>
Yes, we can, will do in next revision.
>
>> arch_entry = __pmd_to_swp_entry(pmd);
>>
>> /* Temporary until swp_entry_t eliminated. */
>> @@ -634,18 +636,30 @@ static inline bool pmd_is_migration_entry(pmd_t pmd)
>> */
>> static inline bool softleaf_is_valid_pmd_entry(softleaf_t entry)
>> {
>> - /* Only device private, migration entries valid for PMD. */
>> + /* Device private, migration, and swap entries valid for PMD. */
>
> Can we just drop that comment? I mean, it's as clear as it gets in the code
> immediately below :)
>
Will do in next revision.
Thanks for the reviews!
>> return softleaf_is_device_private(entry) ||
>> - softleaf_is_migration(entry);
>> + softleaf_is_migration(entry) ||
>> + softleaf_is_swap(entry);
>> +}
>> +
>
next prev parent reply other threads:[~2026-08-19 12:31 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 13:09 [PATCH v6 00/12] mm: PMD-level swap entries for anonymous THPs Usama Arif
2026-08-18 13:09 ` [PATCH v6 01/12] mm: rename pmd_to_softleaf_folio() to pmd_softleaf_to_folio() Usama Arif
2026-08-18 14:24 ` David Hildenbrand (Arm)
2026-08-18 18:36 ` Lorenzo Stoakes (ARM)
2026-08-18 18:38 ` Zi Yan
2026-08-19 14:32 ` Kiryl Shutsemau
2026-08-18 13:09 ` [PATCH v6 02/12] mm: add PMD swap entry detection support Usama Arif
2026-08-18 14:40 ` David Hildenbrand (Arm)
2026-08-18 18:42 ` Lorenzo Stoakes (ARM)
2026-08-19 12:33 ` Usama Arif
2026-08-19 16:05 ` David Hildenbrand (Arm)
2026-08-19 12:31 ` Usama Arif [this message]
2026-08-19 14:42 ` Kiryl Shutsemau
2026-08-19 16:00 ` David Hildenbrand (Arm)
2026-08-18 13:09 ` [PATCH v6 03/12] mm: add PMD swap entry splitting support Usama Arif
2026-08-18 17:53 ` David Hildenbrand (Arm)
2026-08-19 12:39 ` Usama Arif
2026-08-19 16:05 ` David Hildenbrand (Arm)
2026-08-19 15:16 ` Kiryl Shutsemau
2026-08-19 16:04 ` David Hildenbrand (Arm)
2026-08-19 15:13 ` Kiryl Shutsemau
2026-08-18 13:09 ` [PATCH v6 04/12] mm: handle PMD swap entries in fork path Usama Arif
2026-08-19 15:46 ` Kiryl Shutsemau
2026-08-18 13:09 ` [PATCH v6 05/12] mm: zswap: add range lookup for large-folio swapin Usama Arif
2026-08-18 18:28 ` Yosry Ahmed
2026-08-19 12:50 ` Usama Arif
2026-08-18 13:09 ` [PATCH v6 06/12] mm: swap in PMD swap entries as whole THPs during swapoff Usama Arif
2026-08-19 5:38 ` Lance Yang
2026-08-19 12:52 ` Usama Arif
2026-08-18 13:09 ` [PATCH v6 07/12] mm: handle PMD swap entries in non-present PMD walkers Usama Arif
2026-08-18 13:09 ` [PATCH v6 08/12] mm: handle PMD swap entries in MADV_WILLNEED Usama Arif
2026-08-18 13:09 ` [PATCH v6 09/12] mm: handle PMD swap entries in UFFDIO_MOVE Usama Arif
2026-08-18 13:09 ` [PATCH v6 10/12] mm: handle PMD swap entry faults on swap-in Usama Arif
2026-08-18 13:09 ` [PATCH v6 11/12] mm: install PMD swap entries on swap-out Usama Arif
2026-08-18 13:09 ` [PATCH v6 12/12] selftests/mm: add PMD swap entry tests Usama Arif
2026-08-19 10:10 ` Lance Yang
2026-08-19 12:56 ` Usama Arif
2026-08-19 13:04 ` [PATCH v6 00/12] mm: PMD-level swap entries for anonymous THPs Usama Arif
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=5baead5e-b9e9-4850-9ce3-e48a2e5db2ca@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=nico.pache@linux.dev \
--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