diff mbox series

[3/6] mm: Convert page_to_pgoff() to page_pgoff()

Message ID 20240723153503.1669586-4-willy@infradead.org (mailing list archive)
State New
Headers show
Series page->index removals in mm | expand

Commit Message

Matthew Wilcox July 23, 2024, 3:34 p.m. UTC
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.  Also move page_pgoff() to mm/internal.h as
code outside mm has no business calling it.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/pagemap.h | 18 ------------------
 mm/internal.h           |  6 ++++++
 mm/memory-failure.c     |  4 ++--
 mm/rmap.c               |  2 +-
 4 files changed, 9 insertions(+), 21 deletions(-)

Comments

kernel test robot July 24, 2024, 7:24 a.m. UTC | #1
Hi Matthew,

kernel test robot noticed the following build errors:

[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on linus/master next-20240724]
[cannot apply to tip/x86/mm dennis-percpu/for-next v6.10]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Matthew-Wilcox-Oracle/bootmem-Stop-using-page-index/20240723-233932
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20240723153503.1669586-4-willy%40infradead.org
patch subject: [PATCH 3/6] mm: Convert page_to_pgoff() to page_pgoff()
config: x86_64-allnoconfig (https://download.01.org/0day-ci/archive/20240724/202407241549.hEuWenpa-lkp@intel.com/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240724/202407241549.hEuWenpa-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202407241549.hEuWenpa-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from mm/filemap.c:51:
>> mm/internal.h:899:39: error: passing 'const struct folio *' to parameter of type 'struct folio *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
     899 |         return folio->index + folio_page_idx(folio, page);
         |                                              ^~~~~
   include/linux/mm.h:216:62: note: expanded from macro 'folio_page_idx'
     216 | #define folio_page_idx(folio, p)        (page_to_pfn(p) - folio_pfn(folio))
         |                                                                     ^~~~~
   include/linux/mm.h:1877:53: note: passing argument to parameter 'folio' here
    1877 | static inline unsigned long folio_pfn(struct folio *folio)
         |                                                     ^
   1 error generated.
--
   In file included from mm/rmap.c:85:
>> mm/internal.h:899:39: error: passing 'const struct folio *' to parameter of type 'struct folio *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
     899 |         return folio->index + folio_page_idx(folio, page);
         |                                              ^~~~~
   include/linux/mm.h:216:62: note: expanded from macro 'folio_page_idx'
     216 | #define folio_page_idx(folio, p)        (page_to_pfn(p) - folio_pfn(folio))
         |                                                                     ^~~~~
   include/linux/mm.h:1877:53: note: passing argument to parameter 'folio' here
    1877 | static inline unsigned long folio_pfn(struct folio *folio)
         |                                                     ^
   mm/rmap.c:796:40: error: passing 'const struct folio *' to parameter of type 'struct folio *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
     796 |         pgoff = folio->index + folio_page_idx(folio, page);
         |                                               ^~~~~
   include/linux/mm.h:216:62: note: expanded from macro 'folio_page_idx'
     216 | #define folio_page_idx(folio, p)        (page_to_pfn(p) - folio_pfn(folio))
         |                                                                     ^~~~~
   include/linux/mm.h:1877:53: note: passing argument to parameter 'folio' here
    1877 | static inline unsigned long folio_pfn(struct folio *folio)
         |                                                     ^
   2 errors generated.


vim +899 mm/internal.h

   895	
   896	static inline pgoff_t page_pgoff(const struct folio *folio,
   897			const struct page *page)
   898	{
 > 899		return folio->index + folio_page_idx(folio, page);
   900	}
   901
diff mbox series

Patch

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 483a191bb4df..1f295ef7d10d 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -913,24 +913,6 @@  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).
- */
-static inline pgoff_t page_to_pgoff(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 byte-offset into filesystem object for page.
  */
diff --git a/mm/internal.h b/mm/internal.h
index e511708b2be0..8dfd9527ac1e 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -919,6 +919,12 @@  void mlock_drain_remote(int cpu);
 
 extern pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma);
 
+static inline pgoff_t page_pgoff(const struct folio *folio,
+		const struct page *page)
+{
+	return folio->index + folio_page_idx(folio, page);
+}
+
 /**
  * vma_address - Find the virtual address a page range is mapped at
  * @vma: The vma which maps this object.
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 581d3e5c9117..572c742ecf48 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -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;
diff --git a/mm/rmap.c b/mm/rmap.c
index 886bf67ba382..ba1920291ac6 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1266,7 +1266,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);
 }