[PATCHv2 1/5] mm/page_vma_mapped: Track if the page is mapped across page table boundary

Kiryl Shutsemau posted 5 patches 1 week, 5 days ago
There is a newer version of this series
[PATCHv2 1/5] mm/page_vma_mapped: Track if the page is mapped across page table boundary
Posted by Kiryl Shutsemau 1 week, 5 days ago
From: Kiryl Shutsemau <kas@kernel.org>

Add a PVMW_PGTABLE_CROSSSED flag that page_vma_mapped_walk() will set if
the page is mapped across page table boundary. Unlike other PVMW_*
flags, this one is result of page_vma_mapped_walk() and not set by the
caller.

folio_referenced_one() will use it detect if it safe to mlock the folio.

Signed-off-by: Kiryl Shutsemau <kas@kernel.org>
---
 include/linux/rmap.h | 5 +++++
 mm/page_vma_mapped.c | 1 +
 2 files changed, 6 insertions(+)

diff --git a/include/linux/rmap.h b/include/linux/rmap.h
index 6cd020eea37a..04797cea3205 100644
--- a/include/linux/rmap.h
+++ b/include/linux/rmap.h
@@ -928,6 +928,11 @@ struct page *make_device_exclusive(struct mm_struct *mm, unsigned long addr,
 /* Look for migration entries rather than present PTEs */
 #define PVMW_MIGRATION		(1 << 1)
 
+/* Result flags */
+
+/* The page is mapped across page boundary */
+#define PVMW_PGTABLE_CROSSSED	(1 << 16)
+
 struct page_vma_mapped_walk {
 	unsigned long pfn;
 	unsigned long nr_pages;
diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c
index e981a1a292d2..a184b88743c3 100644
--- a/mm/page_vma_mapped.c
+++ b/mm/page_vma_mapped.c
@@ -309,6 +309,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)
 				}
 				pte_unmap(pvmw->pte);
 				pvmw->pte = NULL;
+				pvmw->flags |= PVMW_PGTABLE_CROSSSED;
 				goto restart;
 			}
 			pvmw->pte++;
-- 
2.50.1
Re: [PATCHv2 1/5] mm/page_vma_mapped: Track if the page is mapped across page table boundary
Posted by Shakeel Butt 1 week, 5 days ago
On Fri, Sep 19, 2025 at 01:40:32PM +0100, Kiryl Shutsemau wrote:
> From: Kiryl Shutsemau <kas@kernel.org>
> 
> Add a PVMW_PGTABLE_CROSSSED flag that page_vma_mapped_walk() will set if
> the page is mapped across page table boundary. Unlike other PVMW_*
> flags, this one is result of page_vma_mapped_walk() and not set by the
> caller.
> 
> folio_referenced_one() will use it detect if it safe to mlock the folio.
> 
> Signed-off-by: Kiryl Shutsemau <kas@kernel.org>

Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>

> ---
>  include/linux/rmap.h | 5 +++++
>  mm/page_vma_mapped.c | 1 +
>  2 files changed, 6 insertions(+)
> 
> diff --git a/include/linux/rmap.h b/include/linux/rmap.h
> index 6cd020eea37a..04797cea3205 100644
> --- a/include/linux/rmap.h
> +++ b/include/linux/rmap.h
> @@ -928,6 +928,11 @@ struct page *make_device_exclusive(struct mm_struct *mm, unsigned long addr,
>  /* Look for migration entries rather than present PTEs */
>  #define PVMW_MIGRATION		(1 << 1)
>  
> +/* Result flags */
> +
> +/* The page is mapped across page boundary */

I think you meant "page table boundary" in above comment.

> +#define PVMW_PGTABLE_CROSSSED	(1 << 16)
> +
>  struct page_vma_mapped_walk {
>  	unsigned long pfn;
>  	unsigned long nr_pages;
> diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c
> index e981a1a292d2..a184b88743c3 100644
> --- a/mm/page_vma_mapped.c
> +++ b/mm/page_vma_mapped.c
> @@ -309,6 +309,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)
>  				}
>  				pte_unmap(pvmw->pte);
>  				pvmw->pte = NULL;
> +				pvmw->flags |= PVMW_PGTABLE_CROSSSED;
>  				goto restart;
>  			}
>  			pvmw->pte++;
> -- 
> 2.50.1
>
Re: [PATCHv2 1/5] mm/page_vma_mapped: Track if the page is mapped across page table boundary
Posted by Kiryl Shutsemau 1 week, 2 days ago
On Fri, Sep 19, 2025 at 01:25:36PM -0700, Shakeel Butt wrote:
> On Fri, Sep 19, 2025 at 01:40:32PM +0100, Kiryl Shutsemau wrote:
> > From: Kiryl Shutsemau <kas@kernel.org>
> > 
> > Add a PVMW_PGTABLE_CROSSSED flag that page_vma_mapped_walk() will set if
> > the page is mapped across page table boundary. Unlike other PVMW_*
> > flags, this one is result of page_vma_mapped_walk() and not set by the
> > caller.
> > 
> > folio_referenced_one() will use it detect if it safe to mlock the folio.
> > 
> > Signed-off-by: Kiryl Shutsemau <kas@kernel.org>
> 
> Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>
> 
> > ---
> >  include/linux/rmap.h | 5 +++++
> >  mm/page_vma_mapped.c | 1 +
> >  2 files changed, 6 insertions(+)
> > 
> > diff --git a/include/linux/rmap.h b/include/linux/rmap.h
> > index 6cd020eea37a..04797cea3205 100644
> > --- a/include/linux/rmap.h
> > +++ b/include/linux/rmap.h
> > @@ -928,6 +928,11 @@ struct page *make_device_exclusive(struct mm_struct *mm, unsigned long addr,
> >  /* Look for migration entries rather than present PTEs */
> >  #define PVMW_MIGRATION		(1 << 1)
> >  
> > +/* Result flags */
> > +
> > +/* The page is mapped across page boundary */
> 
> I think you meant "page table boundary" in above comment.

Right. Will fix in the v3.

-- 
  Kiryl Shutsemau / Kirill A. Shutemov