diff mbox series

[v14,052/138] mm: Add folio_raw_mapping()

Message ID 20210715033704.692967-53-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series Memory folios | expand

Commit Message

Matthew Wilcox July 15, 2021, 3:35 a.m. UTC
Convert __page_rmapping to folio_raw_mapping 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

David Howells Aug. 10, 2021, 8:42 p.m. UTC | #1
Matthew Wilcox (Oracle) <willy@infradead.org> wrote:

> Convert __page_rmapping to folio_raw_mapping 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>

I assume you're going to call it from another source file at some point,
otherwise this is unnecessary.

Apart from that,

Reviewed-by: David Howells <dhowells@redhat.com>
Vlastimil Babka Aug. 11, 2021, 1:59 p.m. UTC | #2
On 7/15/21 5:35 AM, Matthew Wilcox (Oracle) wrote:
> Convert __page_rmapping to folio_raw_mapping 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.

Maybe mention the page_anon_vma() in changelog too?

> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>

Acked-by: Vlastimil Babka <vbabka@suse.cz>
Matthew Wilcox Aug. 14, 2021, 4:51 p.m. UTC | #3
On Tue, Aug 10, 2021 at 09:42:13PM +0100, David Howells wrote:
> Matthew Wilcox (Oracle) <willy@infradead.org> wrote:
> 
> > Convert __page_rmapping to folio_raw_mapping 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>
> 
> I assume you're going to call it from another source file at some point,
> otherwise this is unnecessary.

Yes, it gets called from mm/ksm.c in a later patch in this series.
__page_rmapping() assumes it's being passed a head page and
folio_raw_mapping() asserts that.  Eventually, page_rmapping() can
go away (and maybe it should have been moved to folio-compat.c),
but I'm not inclined to do that now.

> Apart from that,
> 
> Reviewed-by: David Howells <dhowells@redhat.com>
>
Matthew Wilcox Aug. 14, 2021, 5:06 p.m. UTC | #4
On Wed, Aug 11, 2021 at 03:59:06PM +0200, Vlastimil Babka wrote:
> On 7/15/21 5:35 AM, Matthew Wilcox (Oracle) wrote:
> > Convert __page_rmapping to folio_raw_mapping 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.
> 
> Maybe mention the page_anon_vma() in changelog too?

Convert __page_rmapping to folio_raw_mapping 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.  Change page_anon_vma() to not call folio_raw_mapping() --
it's more efficient to do the subtraction than the mask.
diff mbox series

Patch

diff --git a/mm/internal.h b/mm/internal.h
index 1a8851b73031..fa31a7f0ed79 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -34,6 +34,13 @@ 
 
 void page_writeback_init(void);
 
+static inline void *folio_raw_mapping(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 e8c12350b3eb..d0aa1d9c811e 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_raw_mapping(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 (void *)(mapping - PAGE_MAPPING_ANON);
 }
 
 /**