* Re: [v2 11/16] mm: handle PMD swap entries in non-present PMD walkers
[not found] <20260602142537.198755-12-usama.arif@linux.dev>
@ 2026-06-12 6:45 ` Lance Yang
0 siblings, 0 replies; only message in thread
From: Lance Yang @ 2026-06-12 6:45 UTC (permalink / raw)
To: usama.arif
Cc: akpm, david, chrisl, kasong, ljs, ziy, ying.huang, baoquan.he,
willy, youngjun.park, hannes, riel, shakeel.butt, alex, kas,
baohua, dev.jain, baolin.wang, npache, liam, ryan.roberts, vbabka,
lance.yang, linux-kernel, nphamcs, shikemeng, kernel-team,
linux-mm
+Cc linux-mm
Please Cc linux-mm next time. Pretty clearly MM work ...
On Tue, Jun 02, 2026 at 07:24:19AM -0700, Usama Arif wrote:
[...]
>diff --git a/mm/mincore.c b/mm/mincore.c
>index e5d13eea9234..3fee8a7b9d9d 100644
>--- a/mm/mincore.c
>+++ b/mm/mincore.c
>@@ -172,7 +172,19 @@ static int mincore_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
>
> ptl = pmd_trans_huge_lock(pmd, vma);
> if (ptl) {
>- memset(vec, 1, nr);
>+ if (pmd_present(*pmd)) {
>+ memset(vec, 1, nr);
>+ } else {
>+ /*
>+ * Non-present PMD: migration, device-private, or PMD
>+ * swap entry. Route through mincore_swap() the same way
>+ * the PTE path does -- the swap entry covers all 512
>+ * slots, so the whole vec gets the same answer.
>+ */
>+ softleaf_t entry = softleaf_from_pmd(*pmd);
>+
>+ memset(vec, mincore_swap(entry, false), nr);
Looks buggy ...
That assumes one swap-cache lookup is enough for whole PMD-sized range.
I don't think that always holds ...
See do_huge_pmd_swap_page():
---8<---
folio = swap_cache_get_folio(swp_entry);
[...]
/*
* Folio should be PMD-sized; if not (e.g. split in swap cache),
* split the PMD swap entry and retry at PTE level.
*/
if (folio_nr_pages(folio) != HPAGE_PMD_NR) {
folio_unlock(folio);
folio_put(folio);
goto split_fallback;
}
---
it handles the case where swap_cache_get_folio() returns a folio that
is no longer PMD-sized. E.g. because it was split in the swap cache
while the PMD swap entry was installed. Then it split the PMD swap entry
and retries at PTE level :)
unuse_pmd_entry() has the same fallback. Can mincore hit that case?
Maybe the comment right above should say something like:
"
One lookup is enough for a PMD-sized swapcache folio. If the swapcache
was split, check the per-page swap slots.
"
Hopefully, I'm not missing something here :D
Cheers, Lance
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-06-12 6:46 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260602142537.198755-12-usama.arif@linux.dev>
2026-06-12 6:45 ` [v2 11/16] mm: handle PMD swap entries in non-present PMD walkers Lance Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox