diff mbox series

[v2,02/46] mm: Add folio_rmapping()

Message ID 20210622121551.3398730-3-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series Folio-enabling the page cache | expand

Commit Message

Matthew Wilcox June 22, 2021, 12:15 p.m. UTC
Convert __page_rmapping to folio_rmapping and move it to mm/internal.h.
It's only a couple of instructions (load and mask), so it's definitely
going to be cheaper to inline it than call it.  Leave page_rmapping
out of line.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 mm/internal.h |  7 +++++++
 mm/util.c     | 20 ++++----------------
 2 files changed, 11 insertions(+), 16 deletions(-)

Comments

Christoph Hellwig June 23, 2021, 7:56 a.m. UTC | #1
> +static inline void *folio_rmapping(struct folio *folio)

This name, just like the old one is not exaclty descriptive.  I guess the
r stands for raw somehow?  As a casual contributor to the fringes of the
MM I would have no idea when to use it.

All this of course also applies to the existing (__)page_rmapping, but
maybe this is a good time to sort it out.

>  
>  struct anon_vma *page_anon_vma(struct page *page)
>  {
> +	struct folio *folio = page_folio(page);
> +	unsigned long mapping = (unsigned long)folio->mapping;
>  
>  	if ((mapping & PAGE_MAPPING_FLAGS) != PAGE_MAPPING_ANON)
>  		return NULL;
> +	return folio_rmapping(folio);

It feelds kinda silly to not just open code folio_rmapping here
given that we alredy went half the way.
Matthew Wilcox June 24, 2021, 3:51 p.m. UTC | #2
On Wed, Jun 23, 2021 at 09:56:58AM +0200, Christoph Hellwig wrote:
> > +static inline void *folio_rmapping(struct folio *folio)
> 
> This name, just like the old one is not exaclty descriptive.  I guess the
> r stands for raw somehow?  As a casual contributor to the fringes of the
> MM I would have no idea when to use it.
> 
> All this of course also applies to the existing (__)page_rmapping, but
> maybe this is a good time to sort it out.

Yes, good point.  I don't like the name rmapping either, since
we already have rmap which has nothing to do with this.  I'll
leave page_rmapping() alone for now; no need to add that churn.
I think they all become calls to folio_raw_mapping() later.

> >  
> >  struct anon_vma *page_anon_vma(struct page *page)
> >  {
> > +	struct folio *folio = page_folio(page);
> > +	unsigned long mapping = (unsigned long)folio->mapping;
> >  
> >  	if ((mapping & PAGE_MAPPING_FLAGS) != PAGE_MAPPING_ANON)
> >  		return NULL;
> > +	return folio_rmapping(folio);
> 
> It feelds kinda silly to not just open code folio_rmapping here
> given that we alredy went half the way. 

Yeah, I thought about that too.  Done:

-       return folio_rmapping(folio);
+       return (void *)(mapping - PAGE_MAPPING_ANON);
diff mbox series

Patch

diff --git a/mm/internal.h b/mm/internal.h
index 76ddcf55012c..3e70121c71c7 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -34,6 +34,13 @@ 
 
 void page_writeback_init(void);
 
+static inline void *folio_rmapping(struct folio *folio)
+{
+	unsigned long mapping = (unsigned long)folio->mapping;
+
+	return (void *)(mapping & ~PAGE_MAPPING_FLAGS);
+}
+
 vm_fault_t do_swap_page(struct vm_fault *vmf);
 void folio_rotate_reclaimable(struct folio *folio);
 
diff --git a/mm/util.c b/mm/util.c
index a8766e7f1b7f..0ba3a56c2c90 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -635,21 +635,10 @@  void kvfree_sensitive(const void *addr, size_t len)
 }
 EXPORT_SYMBOL(kvfree_sensitive);
 
-static inline void *__page_rmapping(struct page *page)
-{
-	unsigned long mapping;
-
-	mapping = (unsigned long)page->mapping;
-	mapping &= ~PAGE_MAPPING_FLAGS;
-
-	return (void *)mapping;
-}
-
 /* Neutral page->mapping pointer to address_space or anon_vma or other */
 void *page_rmapping(struct page *page)
 {
-	page = compound_head(page);
-	return __page_rmapping(page);
+	return folio_rmapping(page_folio(page));
 }
 
 /**
@@ -680,13 +669,12 @@  EXPORT_SYMBOL(folio_mapped);
 
 struct anon_vma *page_anon_vma(struct page *page)
 {
-	unsigned long mapping;
+	struct folio *folio = page_folio(page);
+	unsigned long mapping = (unsigned long)folio->mapping;
 
-	page = compound_head(page);
-	mapping = (unsigned long)page->mapping;
 	if ((mapping & PAGE_MAPPING_FLAGS) != PAGE_MAPPING_ANON)
 		return NULL;
-	return __page_rmapping(page);
+	return folio_rmapping(folio);
 }
 
 /**