]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: convert page_to_pgoff() to page_pgoff()
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Sat, 5 Oct 2024 20:01:12 +0000 (21:01 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 1 Nov 2024 04:29:01 +0000 (21:29 -0700)
Patch series "page->index removals in mm", v2.

As part of shrinking struct page, we need to stop using page->index.  This
patchset gets rid of most of the remaining references to page->index in
mm, as well as increasing the number of functions which take a const
folio/page pointer.  It shrinks the text segment of mm by a few hundred
bytes in my test config, probably mostly from removing calls to
compound_head() in page_to_pgoff().

This patch (of 7):

Change the function signature to pass in the folio as all three callers
have it.  This removes a reference to page->index, which we're trying to
get rid of.  And add kernel-doc.

Link: https://lkml.kernel.org/r/20241005200121.3231142-1-willy@infradead.org
Link: https://lkml.kernel.org/r/20241005200121.3231142-2-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/mm.h
include/linux/pagemap.h
mm/memory-failure.c
mm/rmap.c

index 8f5394d75ce23302a6c5e77bfe5b99c5423a8a88..46d0654df3bd880377286b4dc99bcd6f38c6a3d5 100644 (file)
@@ -1895,7 +1895,7 @@ static inline unsigned long page_to_section(const struct page *page)
  *
  * Return: The Page Frame Number of the first page in the folio.
  */
-static inline unsigned long folio_pfn(struct folio *folio)
+static inline unsigned long folio_pfn(const struct folio *folio)
 {
        return page_to_pfn(&folio->page);
 }
index 68a5f1ff3301c6cfba823cab8a418d9ca6f25893..bcf0865a38ae346f45a0409067ac3f7feeebf6d9 100644 (file)
@@ -1011,22 +1011,25 @@ static inline struct folio *read_mapping_folio(struct address_space *mapping,
        return read_cache_folio(mapping, index, NULL, file);
 }
 
-/*
- * Get the offset in PAGE_SIZE (even for hugetlb pages).
+/**
+ * page_pgoff - Calculate the logical page offset of this page.
+ * @folio: The folio containing this page.
+ * @page: The page which we need the offset of.
+ *
+ * For file pages, this is the offset from the beginning of the file
+ * in units of PAGE_SIZE.  For anonymous pages, this is the offset from
+ * the beginning of the anon_vma in units of PAGE_SIZE.  This will
+ * return nonsense for KSM pages.
+ *
+ * Context: Caller must have a reference on the folio or otherwise
+ * prevent it from being split or freed.
+ *
+ * Return: The offset in units of PAGE_SIZE.
  */
-static inline pgoff_t page_to_pgoff(struct page *page)
+static inline pgoff_t page_pgoff(const struct folio *folio,
+               const struct page *page)
 {
-       struct page *head;
-
-       if (likely(!PageTransTail(page)))
-               return page->index;
-
-       head = compound_head(page);
-       /*
-        *  We don't initialize ->index for tail pages: calculate based on
-        *  head page
-        */
-       return head->index + page - head;
+       return folio->index + folio_page_idx(folio, page);
 }
 
 /*
index 96ce31e5a203be3e1e952cad59bf33e964135b5e..58a3d80961a488b7e3799a797768a60ba9642e3c 100644 (file)
@@ -617,7 +617,7 @@ static void collect_procs_anon(struct folio *folio, struct page *page,
        if (av == NULL) /* Not actually mapped anymore */
                return;
 
-       pgoff = page_to_pgoff(page);
+       pgoff = page_pgoff(folio, page);
        rcu_read_lock();
        for_each_process(tsk) {
                struct vm_area_struct *vma;
@@ -653,7 +653,7 @@ static void collect_procs_file(struct folio *folio, struct page *page,
 
        i_mmap_lock_read(mapping);
        rcu_read_lock();
-       pgoff = page_to_pgoff(page);
+       pgoff = page_pgoff(folio, page);
        for_each_process(tsk) {
                struct task_struct *t = task_early_kill(tsk, force_early);
                unsigned long addr;
index 73d5998677d40f65f574c7385133915ecd85959f..013f91d932248c52673c171cb16669cbe92130d8 100644 (file)
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1277,7 +1277,7 @@ static void __page_check_anon_rmap(struct folio *folio, struct page *page,
         */
        VM_BUG_ON_FOLIO(folio_anon_vma(folio)->root != vma->anon_vma->root,
                        folio);
-       VM_BUG_ON_PAGE(page_to_pgoff(page) != linear_page_index(vma, address),
+       VM_BUG_ON_PAGE(page_pgoff(folio, page) != linear_page_index(vma, address),
                       page);
 }