diff mbox series

[08/22] mm: Add folio_add_new_anon_rmap()

Message ID 20221231214610.2800682-9-willy@infradead.org (mailing list archive)
State New
Headers show
Series Get rid of first tail page fields | expand

Commit Message

Matthew Wilcox Dec. 31, 2022, 9:45 p.m. UTC
In contrast to other rmap functions, page_add_new_anon_rmap() is always
called with a freshly allocated page.  That means it can't be called with
a tail page.  Turn page_add_new_anon_rmap() into folio_add_new_anon_rmap()
and add a page_add_new_anon_rmap() wrapper.  Callers can be converted
individually.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/rmap.h |  2 ++
 mm/folio-compat.c    |  8 ++++++++
 mm/rmap.c            | 23 +++++++++++------------
 3 files changed, 21 insertions(+), 12 deletions(-)

Comments

kernel test robot Dec. 31, 2022, 11:29 p.m. UTC | #1
Hi Matthew,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.2-rc1]
[cannot apply to akpm-mm/mm-everything next-20221226]
[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/mm-Remove-folio_pincount_ptr-and-head_compound_pincount/20230101-054709
patch link:    https://lore.kernel.org/r/20221231214610.2800682-9-willy%40infradead.org
patch subject: [PATCH 08/22] mm: Add folio_add_new_anon_rmap()
config: powerpc-allnoconfig
compiler: powerpc-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/0cc724aed3b147aba93541bbf32dba2844155330
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Matthew-Wilcox-Oracle/mm-Remove-folio_pincount_ptr-and-head_compound_pincount/20230101-054709
        git checkout 0cc724aed3b147aba93541bbf32dba2844155330
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=powerpc olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=powerpc SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   mm/rmap.c:1292: warning: Function parameter or member 'folio' not described in 'folio_add_new_anon_rmap'
>> mm/rmap.c:1292: warning: expecting prototype for page_add_new_anon_rmap(). Prototype was for folio_add_new_anon_rmap() instead


vim +1292 mm/rmap.c

^1da177e4c3f41 Linus Torvalds          2005-04-16  1276  
43d8eac44f28d3 Randy Dunlap            2008-03-19  1277  /**
40f2bbf71161fa David Hildenbrand       2022-05-09  1278   * page_add_new_anon_rmap - add mapping to a new anonymous page
9617d95e6e9ffd Nicholas Piggin         2006-01-06  1279   * @page:	the page to add the mapping to
9617d95e6e9ffd Nicholas Piggin         2006-01-06  1280   * @vma:	the vm area in which the mapping is added
9617d95e6e9ffd Nicholas Piggin         2006-01-06  1281   * @address:	the user virtual address mapped
40f2bbf71161fa David Hildenbrand       2022-05-09  1282   *
40f2bbf71161fa David Hildenbrand       2022-05-09  1283   * If it's a compound page, it is accounted as a compound page. As the page
40f2bbf71161fa David Hildenbrand       2022-05-09  1284   * is new, it's assume to get mapped exclusively by a single process.
9617d95e6e9ffd Nicholas Piggin         2006-01-06  1285   *
9617d95e6e9ffd Nicholas Piggin         2006-01-06  1286   * Same as page_add_anon_rmap but must only be called on *new* pages.
9617d95e6e9ffd Nicholas Piggin         2006-01-06  1287   * This means the inc-and-test can be bypassed.
c97a9e10eaee32 Nicholas Piggin         2007-05-16  1288   * Page does not have to be locked.
9617d95e6e9ffd Nicholas Piggin         2006-01-06  1289   */
0cc724aed3b147 Matthew Wilcox (Oracle  2022-12-31  1290) void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma,
0cc724aed3b147 Matthew Wilcox (Oracle  2022-12-31  1291) 		unsigned long address)
9617d95e6e9ffd Nicholas Piggin         2006-01-06 @1292  {
d8dd5e979d09c7 Hugh Dickins            2022-11-09  1293  	int nr;
d281ee61451835 Kirill A. Shutemov      2016-01-15  1294  
81d1b09c6be66a Sasha Levin             2014-10-09  1295  	VM_BUG_ON_VMA(address < vma->vm_start || address >= vma->vm_end, vma);
0cc724aed3b147 Matthew Wilcox (Oracle  2022-12-31  1296) 	__folio_set_swapbacked(folio);
d8dd5e979d09c7 Hugh Dickins            2022-11-09  1297  
0cc724aed3b147 Matthew Wilcox (Oracle  2022-12-31  1298) 	if (likely(!folio_test_large(folio))) {
d8dd5e979d09c7 Hugh Dickins            2022-11-09  1299  		/* increment count (starts at -1) */
0cc724aed3b147 Matthew Wilcox (Oracle  2022-12-31  1300) 		atomic_set(&folio->_mapcount, 0);
d8dd5e979d09c7 Hugh Dickins            2022-11-09  1301  		nr = 1;
d8dd5e979d09c7 Hugh Dickins            2022-11-09  1302  	} else {
53f9263baba69f Kirill A. Shutemov      2016-01-15  1303  		/* increment count (starts at -1) */
0cc724aed3b147 Matthew Wilcox (Oracle  2022-12-31  1304) 		atomic_set(&folio->_entire_mapcount, 0);
0cc724aed3b147 Matthew Wilcox (Oracle  2022-12-31  1305) 		atomic_set(&folio->_nr_pages_mapped, COMPOUND_MAPPED);
0cc724aed3b147 Matthew Wilcox (Oracle  2022-12-31  1306) 		nr = folio_nr_pages(folio);
0cc724aed3b147 Matthew Wilcox (Oracle  2022-12-31  1307) 		__lruvec_stat_mod_folio(folio, NR_ANON_THPS, nr);
d281ee61451835 Kirill A. Shutemov      2016-01-15  1308  	}
d8dd5e979d09c7 Hugh Dickins            2022-11-09  1309  
0cc724aed3b147 Matthew Wilcox (Oracle  2022-12-31  1310) 	__lruvec_stat_mod_folio(folio, NR_ANON_MAPPED, nr);
0cc724aed3b147 Matthew Wilcox (Oracle  2022-12-31  1311) 	__page_set_anon_rmap(&folio->page, vma, address, 1);
9617d95e6e9ffd Nicholas Piggin         2006-01-06  1312  }
9617d95e6e9ffd Nicholas Piggin         2006-01-06  1313
kernel test robot Dec. 31, 2022, 11:59 p.m. UTC | #2
Hi Matthew,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.2-rc1]
[cannot apply to akpm-mm/mm-everything next-20221226]
[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/mm-Remove-folio_pincount_ptr-and-head_compound_pincount/20230101-054709
patch link:    https://lore.kernel.org/r/20221231214610.2800682-9-willy%40infradead.org
patch subject: [PATCH 08/22] mm: Add folio_add_new_anon_rmap()
config: m68k-randconfig-r034-20230101
compiler: m68k-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/0cc724aed3b147aba93541bbf32dba2844155330
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Matthew-Wilcox-Oracle/mm-Remove-folio_pincount_ptr-and-head_compound_pincount/20230101-054709
        git checkout 0cc724aed3b147aba93541bbf32dba2844155330
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

>> mm/folio-compat.c:127:6: warning: no previous prototype for 'page_add_new_anon_rmap' [-Wmissing-prototypes]
     127 | void page_add_new_anon_rmap(struct page *page, struct vm_area_struct *vma,
         |      ^~~~~~~~~~~~~~~~~~~~~~
   mm/folio-compat.c: In function 'page_add_new_anon_rmap':
>> mm/folio-compat.c:132:16: error: implicit declaration of function 'folio_add_new_anon_rmap'; did you mean 'page_add_new_anon_rmap'? [-Werror=implicit-function-declaration]
     132 |         return folio_add_new_anon_rmap((struct folio *)page, vma, address);
         |                ^~~~~~~~~~~~~~~~~~~~~~~
         |                page_add_new_anon_rmap
   mm/folio-compat.c:132:16: error: 'return' with a value, in function returning void [-Werror=return-type]
     132 |         return folio_add_new_anon_rmap((struct folio *)page, vma, address);
         |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   mm/folio-compat.c:127:6: note: declared here
     127 | void page_add_new_anon_rmap(struct page *page, struct vm_area_struct *vma,
         |      ^~~~~~~~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors


vim +132 mm/folio-compat.c

   126	
 > 127	void page_add_new_anon_rmap(struct page *page, struct vm_area_struct *vma,
   128			unsigned long address)
   129	{
   130		VM_BUG_ON_PAGE(PageTail(page), page);
   131	
 > 132		return folio_add_new_anon_rmap((struct folio *)page, vma, address);
diff mbox series

Patch

diff --git a/include/linux/rmap.h b/include/linux/rmap.h
index bd3504d11b15..aa682a2a93ce 100644
--- a/include/linux/rmap.h
+++ b/include/linux/rmap.h
@@ -194,6 +194,8 @@  void page_add_anon_rmap(struct page *, struct vm_area_struct *,
 		unsigned long address, rmap_t flags);
 void page_add_new_anon_rmap(struct page *, struct vm_area_struct *,
 		unsigned long address);
+void folio_add_new_anon_rmap(struct folio *, struct vm_area_struct *,
+		unsigned long address);
 void page_add_file_rmap(struct page *, struct vm_area_struct *,
 		bool compound);
 void page_remove_rmap(struct page *, struct vm_area_struct *,
diff --git a/mm/folio-compat.c b/mm/folio-compat.c
index 69ed25790c68..92f53adc0dd9 100644
--- a/mm/folio-compat.c
+++ b/mm/folio-compat.c
@@ -123,3 +123,11 @@  void putback_lru_page(struct page *page)
 {
 	folio_putback_lru(page_folio(page));
 }
+
+void page_add_new_anon_rmap(struct page *page, struct vm_area_struct *vma,
+		unsigned long address)
+{
+	VM_BUG_ON_PAGE(PageTail(page), page);
+
+	return folio_add_new_anon_rmap((struct folio *)page, vma, address);
+}
diff --git a/mm/rmap.c b/mm/rmap.c
index 71fbe4a65b93..3297b88b5698 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1287,29 +1287,28 @@  void page_add_anon_rmap(struct page *page, struct vm_area_struct *vma,
  * This means the inc-and-test can be bypassed.
  * Page does not have to be locked.
  */
-void page_add_new_anon_rmap(struct page *page,
-	struct vm_area_struct *vma, unsigned long address)
+void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma,
+		unsigned long address)
 {
 	int nr;
 
 	VM_BUG_ON_VMA(address < vma->vm_start || address >= vma->vm_end, vma);
-	__SetPageSwapBacked(page);
+	__folio_set_swapbacked(folio);
 
-	if (likely(!PageCompound(page))) {
+	if (likely(!folio_test_large(folio))) {
 		/* increment count (starts at -1) */
-		atomic_set(&page->_mapcount, 0);
+		atomic_set(&folio->_mapcount, 0);
 		nr = 1;
 	} else {
-		VM_BUG_ON_PAGE(!PageTransHuge(page), page);
 		/* increment count (starts at -1) */
-		atomic_set(compound_mapcount_ptr(page), 0);
-		atomic_set(subpages_mapcount_ptr(page), COMPOUND_MAPPED);
-		nr = thp_nr_pages(page);
-		__mod_lruvec_page_state(page, NR_ANON_THPS, nr);
+		atomic_set(&folio->_entire_mapcount, 0);
+		atomic_set(&folio->_nr_pages_mapped, COMPOUND_MAPPED);
+		nr = folio_nr_pages(folio);
+		__lruvec_stat_mod_folio(folio, NR_ANON_THPS, nr);
 	}
 
-	__mod_lruvec_page_state(page, NR_ANON_MAPPED, nr);
-	__page_set_anon_rmap(page, vma, address, 1);
+	__lruvec_stat_mod_folio(folio, NR_ANON_MAPPED, nr);
+	__page_set_anon_rmap(&folio->page, vma, address, 1);
 }
 
 /**