From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: xu.xin16@zte.com.cn
Cc: akpm@linux-foundation.org, david@kernel.org, liam@infradead.org,
vbabka@kernel.org, rppt@kernel.org, surenb@google.com,
mhocko@suse.com, jannh@google.com, pfalcato@suse.de,
willy@infradead.org, jack@suse.cz, linmiaohe@huawei.com,
nao.horiguchi@gmail.com, riel@surriel.com, harry@kernel.org,
lance.yang@linux.dev, kees@kernel.org, ziy@nvidia.com,
baolin.wang@linux.alibaba.com, npache@redhat.com,
ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org,
usama.arif@linux.dev, matthew.brost@intel.com,
joshua.hahnjy@gmail.com, rakie.kim@sk.com, byungchul@sk.com,
gourry@gourry.net, ying.huang@linux.alibaba.com,
apopple@nvidia.com, peterx@redhat.com, chengming.zhou@linux.dev,
arnd@arndb.de, 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 01/15] mm/vma: introduce VMA virtual page offset field and add helpers
Date: Mon, 20 Jul 2026 08:14:08 +0100 [thread overview]
Message-ID: <al3KlYMbmeR6iDX8@lucifer> (raw)
In-Reply-To: <202607191155425057lNrNOYTi44E_jmidmtkn@zte.com.cn>
On Sun, Jul 19, 2026 at 11:55:42AM +0800, xu.xin16@zte.com.cn wrote:
> > This patch establishes fields within the vm_area_struct type to store the
> > virtual page offset of VMAs.
> >
> > The virtual page offset of a VMA is equal to vma->vm_start >> PAGE_SHIFT if
> > they are unfaulted or were not remapped, otherwise it is equal to this
> > value at the point of first fault.
> >
> > Currently, anonymous folios belonging to CoW'd MAP_PRIVATE-mapped
> > file-backed VMAs are tracked by their file offset. By adding virtual offset
> > as a property of VMAs, we can now track them by their virtual page offset
> > instead.
> >
> > By tracking this, we provide the means by which to eliminate this
> > inconsistency, and more importantly lay the foundations for future work for
> > the scalable CoW anonymous rmap rework.
> >
> > This patch simply adds the fields and some simple helpers. Subsequent
> > patches will update mm code to make use of these fields correctly.
> >
> > The fields chosen are packed in the VMA such that, for 64-bit kernel
> > builds, no additional space is taken up.
>
> It is not necessarily true that no additional memory will be consumed, as it
> depends on whether the baseline kernel has CONFIG_PER_VMA_LOCK enabled.
We are moving to this being permanently enabled.
> Moreover, in the future evolution of mm, maintaining this benefit would
> require that the layout of struct vm_area_struct before __vm_virt_pgoff_lo
> remains unchanged, which seems impractical.
It isn't, we are very careful with this struct.
>
> My personal suggestion is: maybe we could simply add an unsigned long field,
> say vm_virt_pgoff, without worrying about the increased memory footprint for
> now. Additionally, it would be helpful to add some comments clarifying the
> difference between this new field and the existing vm_pgoff, to aid understanding.
Nope that'd add 64 bytes per VMA for a typical usage which can add up to a lot.
>
> Thanks,
> Xu Xin
>
> >
> > The first field is present on cacheline 0 containing key VMA fields, and
> > the second on cacheline 3, which contains file-backed reverse mapping
> > fields.
> >
> >
> > Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> > ---
> > include/linux/mm.h | 59 +++++++++++++++++++++++++++++++++++++++++
> > include/linux/mm_types.h | 4 +++
> > mm/vma.h | 14 ++++++++++
> > mm/vma_init.c | 1 +
> > tools/testing/vma/include/dup.h | 26 ++++++++++++++++++
> > 5 files changed, 104 insertions(+)
> >
> > +static inline pgoff_t vma_last_virt_pgoff(const struct vm_area_struct *vma)
> > +{
> > + return vma_end_virt_pgoff(vma) - 1;
> > +}
> > +
> > static inline unsigned long vma_desc_size(const struct vm_area_desc *desc)
> > {
> > return desc->end - desc->start;
> > diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> > index 939b5ea8c9e0..2710628059b1 100644
> > --- a/include/linux/mm_types.h
> > +++ b/include/linux/mm_types.h
> > @@ -967,6 +967,7 @@ struct vm_area_struct {
> > */
> > unsigned int vm_lock_seq;
> > #endif
> > + unsigned int __vm_virt_pgoff_lo; /* Low 32-bits of virtual pgoff. */
> > /*
> > * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma
> > * list, after a COW of one of the file pages. A MAP_SHARED vma
> > @@ -1041,6 +1042,9 @@ struct vm_area_struct {
> > #ifdef CONFIG_DEBUG_LOCK_ALLOC
> > struct lockdep_map vmlock_dep_map;
> > #endif
> > +#endif
> > +#ifdef CONFIG_64BIT
> > + unsigned int __vm_virt_pgoff_hi; /* High 32-bits of virtual pgoff. */
> > #endif
> >
Cheers, Lorenzo
next prev parent reply other threads:[~2026-07-20 7:14 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 18:19 [PATCH 00/15] mm/rmap: index MAP_PRIVATE file-backed folios by virt pgoff Lorenzo Stoakes (ARM)
2026-07-17 18:19 ` [PATCH 01/15] mm/vma: introduce VMA virtual page offset field and add helpers Lorenzo Stoakes (ARM)
2026-07-19 3:55 ` xu.xin16
2026-07-20 7:14 ` Lorenzo Stoakes (ARM) [this message]
2026-07-20 7:38 ` xu.xin16
2026-07-20 13:47 ` Lorenzo Stoakes (ARM)
2026-07-17 18:19 ` [PATCH 02/15] mm: introduce linear_virt_page_index() Lorenzo Stoakes (ARM)
2026-07-17 18:19 ` [PATCH 03/15] mm: abstract vma_address() and introduce vma_anon_address() Lorenzo Stoakes (ARM)
2026-07-17 18:19 ` [PATCH 04/15] mm: update print_bad_page_map() to show virtual page index Lorenzo Stoakes (ARM)
2026-07-17 18:19 ` [PATCH 05/15] mm: introduce and use vma_filebacked_address() Lorenzo Stoakes (ARM)
2026-07-17 18:19 ` [PATCH 06/15] mm: propagate VMA virtual page offset on map, remap, split + merge Lorenzo Stoakes (ARM)
2026-07-17 18:19 ` [PATCH 07/15] mm/rmap: track whether the page VMA mapped walk is anonymous Lorenzo Stoakes (ARM)
2026-07-18 14:51 ` Lorenzo Stoakes (ARM)
2026-07-17 18:19 ` [PATCH 08/15] mm: introduce and use linear_folio_page_index() Lorenzo Stoakes (ARM)
2026-07-17 18:19 ` [PATCH 09/15] mm/rmap: use virt pgoff for MAP_PRIVATE file-backed anon folios Lorenzo Stoakes (ARM)
2026-07-17 18:19 ` [PATCH 10/15] tools/testing/vma: expand VMA merge tests to assert virt pgoff Lorenzo Stoakes (ARM)
2026-07-17 18:19 ` [PATCH 11/15] tools/testing/selftests/mm: test virtual page offset merge behaviour Lorenzo Stoakes (ARM)
2026-07-17 18:19 ` [PATCH 12/15] mm/vma: only permit MAP_PRIVATE /dev/zero to be mapped anonymous Lorenzo Stoakes (ARM)
2026-07-17 18:19 ` [PATCH 13/15] mm/vma: make MAP_PRIVATE-mapped /dev/zero mappings truly anonymous Lorenzo Stoakes (ARM)
2026-07-17 18:19 ` [PATCH 14/15] tools/testing/vma: add test to assert MAP_PRIVATE-/dev/zero is anon Lorenzo Stoakes (ARM)
2026-07-17 18:19 ` [PATCH 15/15] tools/testing/selftests/mm: add MAP_PRIVATE-/dev/zero merge tests Lorenzo Stoakes (ARM)
2026-07-18 6:47 ` [syzbot ci] Re: mm/rmap: index MAP_PRIVATE file-backed folios by virt pgoff syzbot ci
2026-07-18 14:40 ` Lorenzo Stoakes (ARM)
2026-07-20 13:45 ` [PATCH 00/15] " 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=al3KlYMbmeR6iDX8@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