Re: [PATCH v2 00/15] mm/rmap: index MAP_PRIVATE file-backed folios by virt pgoff

From: Lorenzo Stoakes (ARM)

Date: Tue Jul 28 2026 - 09:53:03 EST


On Mon, Jul 27, 2026 at 04:59:54PM +0100, Matthew Wilcox wrote:
> On Mon, Jul 27, 2026 at 04:57:01PM +0100, Lorenzo Stoakes (ARM) wrote:
> > On Mon, Jul 27, 2026 at 04:44:06PM +0200, David Hildenbrand (Arm) wrote:
> > > On 7/20/26 16:38, Lorenzo Stoakes (ARM) wrote:
> > > > In memory management we've managed to manufacture a great deal of confusion
> > > > around the concept of anonymous memory. We have:
> > > >
> > > > 1. 'Pure anon' memory - anonymous VMAs whose folios are anonymous and
> > > > swap-backed (thus for reclaim purposes, treated as anonymous). These are
> > > > simple enough.
> > > >
> > > > 2. shmem - file-backed VMAs, file-backed folios (from rmap perspective) so
> > > > present in the page cache and mapped by an address_space object, but
> > > > whose folios are also swap-backed (thus treated as anonymous for reclaim
> > > > purposes).
> > > >
> > > > 3. MAP_PRIVATE-mapped /dev/zero - a strange beast whose VMAs have
> > > > vma->vm_file set, but whose mmap_prepare callback clears vma->vm_ops to
> > > > satisfy vma_is_anonymous(), which results in VMAs that were mmap()'d
> > > > referencing a file, but are in every other sense anonymous, including the
> > > > folios.
> > > >
> > > > 4. Other MAP_PRIVATE-file backed mappings - These possess file-backed VMAs
> > > > and have file-backed folios until CoW'd, at which point those CoW'd
> > > > folios are anonymous.
> > > >
> > > > This series fixes issues 3 and 4.
> > > >
> > > > In order for us to traverse VMAs using the reverse mapping, we require two
> > > > fields - folio->mapping and folio->index. The first tells the rmap code
> > > > where to look for VMAs, and the second tells it at which offset the folio
> > > > starts within the referenced object.
> > > >
> > > > For anonymous folios, folio->mapping points at an anon_vma object. For
> > > > file-backed folios, it points at an address_space. And:
> > > >
> > > > * For file-backed folios folio->index is simply the page offset of the start
> > > > of the folio within the file.
> > > >
> > > > * For anonymous folios belonging to pure anon mappings, folio->index is
> > > > equal to the virtual page offset of the folio.
> > > >
> > > > * For anonymous folios belonging to file-backed mappings (i.e. CoW'd folios
> > > > of a MAP_PRIVATE file-backed mapping), folio->index is equal to the file
> > > > page offset.
> > > >
> > > > This series establishes a new virtual page offset property of VMAs to
> > > > allow us to map anonymous folios at their virtual page offset, consistent
> > > > with pure anon.
> > >
> > > As raised off-list, I consider the "virtual page offset" concept hard to grasp.
> > >
> > > Maybe it's just me :)
> > >
> > > Skimming over the code, I read "vmg->anon_pgoff", which is pretty intuitive to
> > > me. Similarly vma_start_anon_pgoff() / vmg_end_anon_pgoff().
> > >
> > > Could we similarly just call this "anon_pgoff" / "(linear) anon page index"
> > > even on the VMA level.
> >
> > Yeah, I had originally done this.
> >
> > I renamed it because I worried that people might be confused by references to
> > anon for file-backed VMA mappings.
> >
> > But I think probably you're right that referring to it as virtual page offset
> > adds even more confusion vs. simply calling it anon. Will respin accordingly.
>
> Would the term "logical page offset" be helpful?
>
> I already use this in my description of folios:
>
> * A folio is a physically, virtually and logically contiguous set
> * of bytes. It is a power-of-two in size, and it is aligned to that
> * same power-of-two. It is at least as large as %PAGE_SIZE. If it is
> * in the page cache, it is at a file offset which is a multiple of that
> * power-of-two. It may be mapped into userspace at an address which is
> * at an arbitrary page offset, but its kernel virtual address is aligned
> * to its size.
>

Thanks, I was kinda getting at this sort of thing, and I did think 'virtual page
offset' was a fairly common term of art, but as often with these things you go
and look to check later and realise that maybe it's not :P

I think overall it's probably easier to go to anon everywhere, I'll eyeball it
when done and make sure it's sane though!

Cheers, Lorenzo