From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
"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>, Jann Horn <jannh@google.com>,
Pedro Falcato <pfalcato@suse.de>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
Jan Kara <jack@suse.cz>, Miaohe Lin <linmiaohe@huawei.com>,
Naoya Horiguchi <nao.horiguchi@gmail.com>,
Rik van Riel <riel@surriel.com>, Harry Yoo <harry@kernel.org>,
Lance Yang <lance.yang@linux.dev>, Kees Cook <kees@kernel.org>,
Zi Yan <ziy@nvidia.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Nico Pache <npache@redhat.com>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>,
Usama Arif <usama.arif@linux.dev>,
Matthew Brost <matthew.brost@intel.com>,
Joshua Hahn <joshua.hahnjy@gmail.com>,
Rakie Kim <rakie.kim@sk.com>, Byungchul Park <byungchul@sk.com>,
Gregory Price <gourry@gourry.net>,
Ying Huang <ying.huang@linux.alibaba.com>,
Alistair Popple <apopple@nvidia.com>,
Peter Xu <peterx@redhat.com>, Xu Xin <xu.xin16@zte.com.cn>,
Chengming Zhou <chengming.zhou@linux.dev>,
Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v3 08/15] mm: introduce and use linear_folio_page_index()
Date: Wed, 5 Aug 2026 10:02:32 +0100 [thread overview]
Message-ID: <anL8EawRefur2cc2@lucifer> (raw)
In-Reply-To: <784eab3a-2b37-476c-a6fc-7fb6e27b6c66@kernel.org>
On Wed, Aug 05, 2026 at 09:26:59AM +0200, David Hildenbrand (Arm) wrote:
> On 8/3/26 16:30, Lorenzo Stoakes (ARM) wrote:
> > On Mon, Aug 03, 2026 at 01:27:09PM +0200, David Hildenbrand (Arm) wrote:
> >> On 7/29/26 18:48, Lorenzo Stoakes (ARM) wrote:
> >>> This function is, for now, a placeholder; it will be used in future to
> >>> determine whether to use the anonymous page index or not, based on whether
> >>> the folio is anonymous or not.
> >>>
> >>> Currently it simply wraps linear_page_index(), so this does not change
> >>> behaviour.
> >>>
> >>> We update callers that will, once the change is introduced to track
> >>> anonymous folios by anonymous page offset if MAP_PRIVATE file-backed, need
> >>> to determine which index to use based on folio type.
> >>>
> >>> No functional change intended.
> >>>
> >>> Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> >>> ---
> >>> include/linux/pagemap.h | 18 ++++++++++++++++++
> >>> mm/huge_memory.c | 3 ++-
> >>> mm/migrate.c | 6 ++++--
> >>> mm/userfaultfd.c | 6 ++++--
> >>> 4 files changed, 28 insertions(+), 5 deletions(-)
> >>>
> >>> diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
> >>> index 259177544b03..6eb8d811ba4c 100644
> >>> --- a/include/linux/pagemap.h
> >>> +++ b/include/linux/pagemap.h
> >>> @@ -1143,6 +1143,24 @@ static inline pgoff_t linear_anon_page_index(const struct vm_area_struct *vma,
> >>> return pgoff;
> >>> }
> >>>
> >>> +/**
> >>> + * linear_folio_page_index() - Determine the absolute page offset of
> >>> + * @address within @vma from @folio.
> >>> + * @folio: The folio whose linear page index is sought.
> >>> + * @vma: The VMA in which @address resides.
> >>> + * @address: The address whose absolute page offset is required.
> >>> + *
> >>> + * For compatibility, currently identical to linear_page_index().
> >>> + *
> >>> + * Returns: The absolute page offset of @address within @vma.
> >>> + */
> >>> +static inline pgoff_t linear_folio_page_index(const struct folio *folio,
> >>> + const struct vm_area_struct *vma,
> >>> + const unsigned long address)
> >>> +{
> >>> + return linear_page_index(vma, address);
> >>> +}
> >>
> >>
> >> I found this to be rather confusing, given that we now have a "folio" helper that
> >> receives a folio and a "page" helper that doesn't receive a page ...
> >
> > This is just to avoid having to duplicate the if (folio_test_anon()) { ... }
> > else { ... } stuff.
> >
> > Agreed it's a bit confusing!
> >
> > Really you are figuring things out from (vma, address) - 'what is the correct
> > page offset based on the VMA'.
> >
> > And yeah it seems migrate can do it via PFN as you suggest, it really is
> > just trying to find the page offset in the folio.
> >
> > But...
> >
> >>
> >> I guess the problem is the "page" in "linear_page_index", as it
> >> reminds of legacy page->index.
> >>
> >>
> >> I wonder if it would be better to have a linear_folio_index() and
> >> force that address points at the start of the folio.
> >>
> >> Looking below, this is exactly what we want for all except one case:
> >
> > ...I don't think this is true.
> >
> > The uffd code uses this too in move_present_ptes():
> >
> > src_folio->index = linear_folio_page_index(src_folio, dst_vma,
> > dst_addr);
> >
> > And it's now _updating_ the source folio index to the offset in the destination
> > VMA, so it doesn't even relate to the source folio's offset at all?
> >
> > (move_swap_pte() calls linear_folio_page_index() but obviously has to be
> > anon, so that can just use linear_anon_page_index() there instead, will
> > update.)
> >
> > With your change we can just eliminate the linear_folio_page_index()
> > function and open-code the uffd case.
>
> The would be even better!
>
> >
> > It's a bit of a special case anyway and is neatly the one place where you
> > actually don't know if it's anon or file-backed (well anon or shmem
> > specifically I think).
> >
> >>
> >>
> >>> /* pgoff is invalid for ksm pages, but they are never large */
> >>> - if (folio_test_large(folio) && !folio_test_hugetlb(folio))
> >>> - idx = linear_page_index(vma, pvmw.address) - pvmw.pgoff;
> >>> + if (folio_test_large(folio) && !folio_test_hugetlb(folio)) {
> >>> + idx += linear_folio_page_index(folio, vma, pvmw.address);
> >>> + idx -= pvmw.pgoff;
> >>> + }
> >>> new = folio_page(folio, idx);
> >>
> >> I think we could avoid this index work entirely by using the pfn, which is much
> >> clearer to me, and similar to how we handle it during other rmap operations.
> >>
> >> diff --git a/mm/migrate.c b/mm/migrate.c
> >> index 222c8c15f782f..686351d353203 100644
> >> --- a/mm/migrate.c
> >> +++ b/mm/migrate.c
> >> @@ -362,17 +362,12 @@ static bool remove_migration_pte(struct folio *folio,
> >> struct page *new;
> >> unsigned long idx = 0;
> >>
> >> - /* pgoff is invalid for ksm pages, but they are never large */
> >> - if (folio_test_large(folio) && !folio_test_hugetlb(folio))
> >> - idx = linear_page_index(vma, pvmw.address) - pvmw.pgoff;
> >> - new = folio_page(folio, idx);
> >> -
> >> #ifdef CONFIG_ARCH_HAS_PMD_SOFTLEAVES
> >> /* PMD-mapped THP migration entry */
> >> if (!pvmw.pte) {
> >> VM_BUG_ON_FOLIO(folio_test_hugetlb(folio) ||
> >> !folio_test_pmd_mappable(folio), folio);
> >> - remove_migration_pmd(&pvmw, new);
> >> + remove_migration_pmd(&pvmw, folio_page(folio, idx));
> >
> > I think we'd need the idx code below to go above where the idx code is now
> > as otherwise this will be incorrect right?
> >
> > But then again, if it's a PMD softleaf it'd have to be aligned right, so
> > couldn't we just update that function to be passed a folio instead and
> > avoid the idx here at all?
>
> Right, that's what I mentioned below
>
> "remove_migration_pmd() will work for now. Later it should just receive the folio
> and do the same thing through softleaf_from_pmd() -> softleaf_to_pfn().
>
> >
> >> continue;
> >> }
> >> #endif
> >> @@ -385,10 +380,14 @@ static bool remove_migration_pte(struct folio *folio,
> >> try_to_map_unused_to_zeropage(&pvmw, folio, old_pte, idx))
> >> continue;
> >>
> >> + entry = softleaf_from_pte(old_pte);
> >> + if (folio_test_large(folio) && !folio_test_hugetlb(folio))
> >> + idx = softleaf_to_pfn(entry) - folio_pfn(rmap_walk_arg->folio);
> >
> > Could actually be softleaf_to_pfn(entry) - pvmw.pfn even?
>
> Given that DEFINE_FOLIO_VMA_WALK() sets
>
> .pfn = folio_pfn(_folio);
>
> I think so.
>
> >
> >> + new = folio_page(folio, idx);
> >> +
> >> folio_get(folio);
> >> pte = mk_pte(new, READ_ONCE(vma->vm_page_prot));
> >>
> >> - entry = softleaf_from_pte(old_pte);
> >> if (!softleaf_is_migration_young(entry))
> >> pte = pte_mkold(pte);
> >> if (folio_test_dirty(folio) && softleaf_is_migration_dirty(entr
> >>
> >>
> >> remove_migration_pmd() will work for now. Later it should just receive the folio
> >> and do the same thing through softleaf_from_pmd() -> softleaf_to_pfn().
> >
> > Ah you already addressed it. But since this would move the idx code above,
> > I think I should just change it to accept a folio instead?
> >
> > Or for less churn &folio->page...
> Right, whatever you prefer.
Awesome will do all that on respin :)
Thanks for the review, this is actually really improving the series :>)
>
>
>
> --
> Cheers,
>
> David
--
Cheers, Lorenzo
next prev parent reply other threads:[~2026-08-05 9:02 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 16:48 [PATCH v3 00/15] mm/rmap: index MAP_PRIVATE file-backed folios by anonymous pgoff Lorenzo Stoakes (ARM)
2026-07-29 16:48 ` [PATCH v3 01/15] mm/vma: introduce VMA anon page offset field and add helpers Lorenzo Stoakes (ARM)
2026-07-29 17:11 ` Lorenzo Stoakes (ARM)
2026-07-30 3:32 ` Gregory Price
2026-08-03 9:28 ` David Hildenbrand (Arm)
2026-08-03 9:46 ` Lorenzo Stoakes (ARM)
2026-08-03 9:58 ` David Hildenbrand (Arm)
2026-08-03 10:13 ` Lorenzo Stoakes (ARM)
2026-07-29 16:48 ` [PATCH v3 02/15] mm: introduce linear_anon_page_index() Lorenzo Stoakes (ARM)
2026-07-30 6:28 ` Gregory Price
2026-08-03 9:34 ` David Hildenbrand (Arm)
2026-08-03 10:10 ` Lorenzo Stoakes (ARM)
2026-07-29 16:48 ` [PATCH v3 03/15] mm: abstract vma_address() and introduce vma_anon_address() Lorenzo Stoakes (ARM)
2026-07-30 4:58 ` Gregory Price
2026-07-30 6:39 ` Gregory Price
2026-07-30 10:16 ` Lorenzo Stoakes (ARM)
2026-08-03 9:37 ` David Hildenbrand (Arm)
2026-07-29 16:48 ` [PATCH v3 04/15] mm: update print_bad_page_map() to show anonymous page index Lorenzo Stoakes (ARM)
2026-07-30 6:32 ` Gregory Price
2026-08-03 9:39 ` David Hildenbrand (Arm)
2026-08-03 10:19 ` Lorenzo Stoakes (ARM)
2026-08-05 8:30 ` Gregory Price
2026-08-05 9:01 ` Lorenzo Stoakes (ARM)
2026-08-03 9:39 ` David Hildenbrand (Arm)
2026-07-29 16:48 ` [PATCH v3 05/15] mm: introduce and use vma_filebacked_address() Lorenzo Stoakes (ARM)
2026-08-03 9:54 ` David Hildenbrand (Arm)
2026-08-03 10:15 ` Lorenzo Stoakes (ARM)
2026-07-29 16:48 ` [PATCH v3 06/15] mm: propagate VMA anonymous page offset on map, remap, split + merge Lorenzo Stoakes (ARM)
2026-08-03 10:52 ` David Hildenbrand (Arm)
2026-08-03 13:46 ` Lorenzo Stoakes (ARM)
2026-08-05 7:35 ` David Hildenbrand (Arm)
2026-08-05 8:59 ` Lorenzo Stoakes (ARM)
2026-08-05 9:19 ` David Hildenbrand (Arm)
2026-08-05 9:29 ` Lorenzo Stoakes (ARM)
2026-07-29 16:48 ` [PATCH v3 07/15] mm/rmap: track whether the page VMA mapped pgoff is anonymous Lorenzo Stoakes (ARM)
2026-08-03 10:57 ` David Hildenbrand (Arm)
2026-08-03 13:51 ` Lorenzo Stoakes (ARM)
2026-08-03 14:02 ` David Hildenbrand (Arm)
2026-08-03 14:32 ` Lorenzo Stoakes (ARM)
2026-08-05 7:17 ` David Hildenbrand (Arm)
2026-08-05 7:25 ` Lorenzo Stoakes (ARM)
2026-07-29 16:48 ` [PATCH v3 08/15] mm: introduce and use linear_folio_page_index() Lorenzo Stoakes (ARM)
2026-08-03 11:27 ` David Hildenbrand (Arm)
2026-08-03 14:30 ` Lorenzo Stoakes (ARM)
2026-08-05 7:26 ` David Hildenbrand (Arm)
2026-08-05 9:02 ` Lorenzo Stoakes (ARM) [this message]
2026-07-29 16:48 ` [PATCH v3 09/15] mm/rmap: use anon pgoff to track MAP_PRIVATE file-backed anon folios Lorenzo Stoakes (ARM)
2026-08-03 11:32 ` David Hildenbrand (Arm)
2026-08-03 14:30 ` Lorenzo Stoakes (ARM)
2026-07-29 16:48 ` [PATCH v3 10/15] tools/testing/vma: expand VMA merge tests to assert anon pgoff Lorenzo Stoakes (ARM)
2026-07-29 16:48 ` [PATCH v3 11/15] tools/testing/selftests/mm: test anonymous page offset merge behaviour Lorenzo Stoakes (ARM)
2026-07-29 16:48 ` [PATCH v3 12/15] mm/vma: only permit MAP_PRIVATE /dev/zero to be mapped anonymous Lorenzo Stoakes (ARM)
2026-07-29 16:48 ` [PATCH v3 13/15] mm/vma: make MAP_PRIVATE-mapped /dev/zero mappings truly anonymous Lorenzo Stoakes (ARM)
2026-07-29 16:48 ` [PATCH v3 14/15] tools/testing/vma: add test to assert MAP_PRIVATE-/dev/zero is anon Lorenzo Stoakes (ARM)
2026-07-29 16:48 ` [PATCH v3 15/15] tools/testing/selftests/mm: add MAP_PRIVATE-/dev/zero merge tests Lorenzo Stoakes (ARM)
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=anL8EawRefur2cc2@lucifer \
--to=ljs@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=arnd@arndb.de \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=byungchul@sk.com \
--cc=chengming.zhou@linux.dev \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=gourry@gourry.net \
--cc=gregkh@linuxfoundation.org \
--cc=harry@kernel.org \
--cc=jack@suse.cz \
--cc=jannh@google.com \
--cc=joshua.hahnjy@gmail.com \
--cc=kees@kernel.org \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linmiaohe@huawei.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=matthew.brost@intel.com \
--cc=mhocko@suse.com \
--cc=nao.horiguchi@gmail.com \
--cc=npache@redhat.com \
--cc=peterx@redhat.com \
--cc=pfalcato@suse.de \
--cc=rakie.kim@sk.com \
--cc=riel@surriel.com \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=surenb@google.com \
--cc=usama.arif@linux.dev \
--cc=vbabka@kernel.org \
--cc=willy@infradead.org \
--cc=xu.xin16@zte.com.cn \
--cc=ying.huang@linux.alibaba.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