diff mbox series

[v13,08/18] mm/memcg: Convert mem_cgroup_charge() to take a folio

Message ID 20210712194551.91920-9-willy@infradead.org (mailing list archive)
State New
Headers show
Series Convert memcg to folios | expand

Commit Message

Matthew Wilcox July 12, 2021, 7:45 p.m. UTC
Convert all callers of mem_cgroup_charge() to call page_folio() on the
page they're currently passing in.  Many of them will be converted to
use folios themselves soon.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 include/linux/memcontrol.h |  6 +++---
 kernel/events/uprobes.c    |  3 ++-
 mm/filemap.c               |  2 +-
 mm/huge_memory.c           |  2 +-
 mm/khugepaged.c            |  4 ++--
 mm/ksm.c                   |  3 ++-
 mm/memcontrol.c            | 26 +++++++++++++-------------
 mm/memory.c                |  9 +++++----
 mm/migrate.c               |  2 +-
 mm/shmem.c                 |  2 +-
 mm/userfaultfd.c           |  2 +-
 11 files changed, 32 insertions(+), 29 deletions(-)

Comments

kernel test robot July 12, 2021, 10:22 p.m. UTC | #1
Hi "Matthew,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.14-rc1 next-20210712]
[cannot apply to hnaz-linux-mm/master tip/perf/core linux/master]
[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]

url:    https://github.com/0day-ci/linux/commits/Matthew-Wilcox-Oracle/Convert-memcg-to-folios/20210713-035650
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git e73f0f0ee7541171d89f2e2491130c7771ba58d3
config: nds32-allnoconfig (attached as .config)
compiler: nds32le-linux-gcc (GCC) 9.3.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/0day-ci/linux/commit/3aa23c53058c0abac2b7fd5d8c80f9b458a2665f
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Matthew-Wilcox-Oracle/Convert-memcg-to-folios/20210713-035650
        git checkout 3aa23c53058c0abac2b7fd5d8c80f9b458a2665f
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=nds32 

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

All errors (new ones prefixed by >>):

   In file included from include/linux/dax.h:6,
                    from mm/filemap.c:15:
   include/linux/mm.h:1380:42: warning: 'struct folio' declared inside parameter list will not be visible outside of this definition or declaration
    1380 | static inline int folio_nid(const struct folio *folio)
         |                                          ^~~~~
   include/linux/mm.h: In function 'folio_nid':
   include/linux/mm.h:1382:27: error: dereferencing pointer to incomplete type 'const struct folio'
    1382 |  return page_to_nid(&folio->page);
         |                           ^~
   In file included from include/linux/swap.h:9,
                    from mm/filemap.c:23:
   include/linux/memcontrol.h: At top level:
   include/linux/memcontrol.h:1120:53: warning: 'struct folio' declared inside parameter list will not be visible outside of this definition or declaration
    1120 | static inline struct mem_cgroup *folio_memcg(struct folio *folio)
         |                                                     ^~~~~
   include/linux/memcontrol.h:1141:44: warning: 'struct folio' declared inside parameter list will not be visible outside of this definition or declaration
    1141 | static inline bool folio_memcg_kmem(struct folio *folio)
         |                                            ^~~~~
   include/linux/memcontrol.h:1193:44: warning: 'struct folio' declared inside parameter list will not be visible outside of this definition or declaration
    1193 | static inline int mem_cgroup_charge(struct folio *folio,
         |                                            ^~~~~
   mm/filemap.c: In function '__add_to_page_cache_locked':
>> mm/filemap.c:875:29: error: implicit declaration of function 'page_folio'; did you mean 'page_endio'? [-Werror=implicit-function-declaration]
     875 |   error = mem_cgroup_charge(page_folio(page), NULL, gfp);
         |                             ^~~~~~~~~~
         |                             page_endio
   mm/filemap.c:875:29: warning: passing argument 1 of 'mem_cgroup_charge' makes pointer from integer without a cast [-Wint-conversion]
     875 |   error = mem_cgroup_charge(page_folio(page), NULL, gfp);
         |                             ^~~~~~~~~~~~~~~~
         |                             |
         |                             int
   In file included from include/linux/swap.h:9,
                    from mm/filemap.c:23:
   include/linux/memcontrol.h:1193:51: note: expected 'struct folio *' but argument is of type 'int'
    1193 | static inline int mem_cgroup_charge(struct folio *folio,
         |                                     ~~~~~~~~~~~~~~^~~~~
   cc1: some warnings being treated as errors
--
   In file included from include/linux/security.h:33,
                    from include/linux/fs_context.h:14,
                    from include/linux/fs_parser.h:11,
                    from include/linux/ramfs.h:5,
                    from mm/shmem.c:28:
   include/linux/mm.h:1380:42: warning: 'struct folio' declared inside parameter list will not be visible outside of this definition or declaration
    1380 | static inline int folio_nid(const struct folio *folio)
         |                                          ^~~~~
   include/linux/mm.h: In function 'folio_nid':
   include/linux/mm.h:1382:27: error: dereferencing pointer to incomplete type 'const struct folio'
    1382 |  return page_to_nid(&folio->page);
         |                           ^~
   In file included from include/linux/swap.h:9,
                    from mm/shmem.c:35:
   include/linux/memcontrol.h: At top level:
   include/linux/memcontrol.h:1120:53: warning: 'struct folio' declared inside parameter list will not be visible outside of this definition or declaration
    1120 | static inline struct mem_cgroup *folio_memcg(struct folio *folio)
         |                                                     ^~~~~
   include/linux/memcontrol.h:1141:44: warning: 'struct folio' declared inside parameter list will not be visible outside of this definition or declaration
    1141 | static inline bool folio_memcg_kmem(struct folio *folio)
         |                                            ^~~~~
   include/linux/memcontrol.h:1193:44: warning: 'struct folio' declared inside parameter list will not be visible outside of this definition or declaration
    1193 | static inline int mem_cgroup_charge(struct folio *folio,
         |                                            ^~~~~
   mm/shmem.c: In function 'shmem_add_to_page_cache':
>> mm/shmem.c:688:29: error: implicit declaration of function 'page_folio'; did you mean 'page_endio'? [-Werror=implicit-function-declaration]
     688 |   error = mem_cgroup_charge(page_folio(page), charge_mm, gfp);
         |                             ^~~~~~~~~~
         |                             page_endio
   mm/shmem.c:688:29: warning: passing argument 1 of 'mem_cgroup_charge' makes pointer from integer without a cast [-Wint-conversion]
     688 |   error = mem_cgroup_charge(page_folio(page), charge_mm, gfp);
         |                             ^~~~~~~~~~~~~~~~
         |                             |
         |                             int
   In file included from include/linux/swap.h:9,
                    from mm/shmem.c:35:
   include/linux/memcontrol.h:1193:51: note: expected 'struct folio *' but argument is of type 'int'
    1193 | static inline int mem_cgroup_charge(struct folio *folio,
         |                                     ~~~~~~~~~~~~~~^~~~~
   cc1: some warnings being treated as errors
--
   In file included from mm/memory.c:43:
   include/linux/mm.h:1380:42: warning: 'struct folio' declared inside parameter list will not be visible outside of this definition or declaration
    1380 | static inline int folio_nid(const struct folio *folio)
         |                                          ^~~~~
   include/linux/mm.h: In function 'folio_nid':
   include/linux/mm.h:1382:27: error: dereferencing pointer to incomplete type 'const struct folio'
    1382 |  return page_to_nid(&folio->page);
         |                           ^~
   In file included from include/linux/swap.h:9,
                    from mm/memory.c:50:
   include/linux/memcontrol.h: At top level:
   include/linux/memcontrol.h:1120:53: warning: 'struct folio' declared inside parameter list will not be visible outside of this definition or declaration
    1120 | static inline struct mem_cgroup *folio_memcg(struct folio *folio)
         |                                                     ^~~~~
   include/linux/memcontrol.h:1141:44: warning: 'struct folio' declared inside parameter list will not be visible outside of this definition or declaration
    1141 | static inline bool folio_memcg_kmem(struct folio *folio)
         |                                            ^~~~~
   include/linux/memcontrol.h:1193:44: warning: 'struct folio' declared inside parameter list will not be visible outside of this definition or declaration
    1193 | static inline int mem_cgroup_charge(struct folio *folio,
         |                                            ^~~~~
   mm/memory.c: In function 'page_copy_prealloc':
>> mm/memory.c:993:24: error: implicit declaration of function 'page_folio'; did you mean 'page_endio'? [-Werror=implicit-function-declaration]
     993 |  if (mem_cgroup_charge(page_folio(new_page), src_mm, GFP_KERNEL)) {
         |                        ^~~~~~~~~~
         |                        page_endio
   mm/memory.c:993:24: warning: passing argument 1 of 'mem_cgroup_charge' makes pointer from integer without a cast [-Wint-conversion]
     993 |  if (mem_cgroup_charge(page_folio(new_page), src_mm, GFP_KERNEL)) {
         |                        ^~~~~~~~~~~~~~~~~~~~
         |                        |
         |                        int
   In file included from include/linux/swap.h:9,
                    from mm/memory.c:50:
   include/linux/memcontrol.h:1193:51: note: expected 'struct folio *' but argument is of type 'int'
    1193 | static inline int mem_cgroup_charge(struct folio *folio,
         |                                     ~~~~~~~~~~~~~~^~~~~
   mm/memory.c: In function 'wp_page_copy':
   mm/memory.c:3022:24: warning: passing argument 1 of 'mem_cgroup_charge' makes pointer from integer without a cast [-Wint-conversion]
    3022 |  if (mem_cgroup_charge(page_folio(new_page), mm, GFP_KERNEL))
         |                        ^~~~~~~~~~~~~~~~~~~~
         |                        |
         |                        int
   In file included from include/linux/swap.h:9,
                    from mm/memory.c:50:
   include/linux/memcontrol.h:1193:51: note: expected 'struct folio *' but argument is of type 'int'
    1193 | static inline int mem_cgroup_charge(struct folio *folio,
         |                                     ~~~~~~~~~~~~~~^~~~~
   mm/memory.c: In function 'do_anonymous_page':
   mm/memory.c:3771:24: warning: passing argument 1 of 'mem_cgroup_charge' makes pointer from integer without a cast [-Wint-conversion]
    3771 |  if (mem_cgroup_charge(page_folio(page), vma->vm_mm, GFP_KERNEL))
         |                        ^~~~~~~~~~~~~~~~
         |                        |
         |                        int
   In file included from include/linux/swap.h:9,
                    from mm/memory.c:50:
   include/linux/memcontrol.h:1193:51: note: expected 'struct folio *' but argument is of type 'int'
    1193 | static inline int mem_cgroup_charge(struct folio *folio,
         |                                     ~~~~~~~~~~~~~~^~~~~
   mm/memory.c: In function 'do_cow_fault':
   mm/memory.c:4186:24: warning: passing argument 1 of 'mem_cgroup_charge' makes pointer from integer without a cast [-Wint-conversion]
    4186 |  if (mem_cgroup_charge(page_folio(vmf->cow_page), vma->vm_mm,
         |                        ^~~~~~~~~~~~~~~~~~~~~~~~~
         |                        |
         |                        int
   In file included from include/linux/swap.h:9,
                    from mm/memory.c:50:
   include/linux/memcontrol.h:1193:51: note: expected 'struct folio *' but argument is of type 'int'
    1193 | static inline int mem_cgroup_charge(struct folio *folio,
         |                                     ~~~~~~~~~~~~~~^~~~~
   cc1: some warnings being treated as errors


vim +875 mm/filemap.c

   855	
   856	noinline int __add_to_page_cache_locked(struct page *page,
   857						struct address_space *mapping,
   858						pgoff_t offset, gfp_t gfp,
   859						void **shadowp)
   860	{
   861		XA_STATE(xas, &mapping->i_pages, offset);
   862		int huge = PageHuge(page);
   863		int error;
   864		bool charged = false;
   865	
   866		VM_BUG_ON_PAGE(!PageLocked(page), page);
   867		VM_BUG_ON_PAGE(PageSwapBacked(page), page);
   868		mapping_set_update(&xas, mapping);
   869	
   870		get_page(page);
   871		page->mapping = mapping;
   872		page->index = offset;
   873	
   874		if (!huge) {
 > 875			error = mem_cgroup_charge(page_folio(page), NULL, gfp);
   876			if (error)
   877				goto error;
   878			charged = true;
   879		}
   880	
   881		gfp &= GFP_RECLAIM_MASK;
   882	
   883		do {
   884			unsigned int order = xa_get_order(xas.xa, xas.xa_index);
   885			void *entry, *old = NULL;
   886	
   887			if (order > thp_order(page))
   888				xas_split_alloc(&xas, xa_load(xas.xa, xas.xa_index),
   889						order, gfp);
   890			xas_lock_irq(&xas);
   891			xas_for_each_conflict(&xas, entry) {
   892				old = entry;
   893				if (!xa_is_value(entry)) {
   894					xas_set_err(&xas, -EEXIST);
   895					goto unlock;
   896				}
   897			}
   898	
   899			if (old) {
   900				if (shadowp)
   901					*shadowp = old;
   902				/* entry may have been split before we acquired lock */
   903				order = xa_get_order(xas.xa, xas.xa_index);
   904				if (order > thp_order(page)) {
   905					xas_split(&xas, old, order);
   906					xas_reset(&xas);
   907				}
   908			}
   909	
   910			xas_store(&xas, page);
   911			if (xas_error(&xas))
   912				goto unlock;
   913	
   914			mapping->nrpages++;
   915	
   916			/* hugetlb pages do not participate in page cache accounting */
   917			if (!huge)
   918				__inc_lruvec_page_state(page, NR_FILE_PAGES);
   919	unlock:
   920			xas_unlock_irq(&xas);
   921		} while (xas_nomem(&xas, gfp));
   922	
   923		if (xas_error(&xas)) {
   924			error = xas_error(&xas);
   925			if (charged)
   926				mem_cgroup_uncharge(page);
   927			goto error;
   928		}
   929	
   930		trace_mm_filemap_add_to_page_cache(page);
   931		return 0;
   932	error:
   933		page->mapping = NULL;
   934		/* Leave page->index set: truncation relies upon it */
   935		put_page(page);
   936		return error;
   937	}
   938	ALLOW_ERROR_INJECTION(__add_to_page_cache_locked, ERRNO);
   939	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index f40c4e0b0431..0c3b386660a8 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -704,7 +704,7 @@  static inline bool mem_cgroup_below_min(struct mem_cgroup *memcg)
 		page_counter_read(&memcg->memory);
 }
 
-int mem_cgroup_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask);
+int mem_cgroup_charge(struct folio *, struct mm_struct *, gfp_t);
 int mem_cgroup_swapin_charge_page(struct page *page, struct mm_struct *mm,
 				  gfp_t gfp, swp_entry_t entry);
 void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry);
@@ -1190,8 +1190,8 @@  static inline bool mem_cgroup_below_min(struct mem_cgroup *memcg)
 	return false;
 }
 
-static inline int mem_cgroup_charge(struct page *page, struct mm_struct *mm,
-				    gfp_t gfp_mask)
+static inline int mem_cgroup_charge(struct folio *folio,
+		struct mm_struct *mm, gfp_t gfp)
 {
 	return 0;
 }
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index af24dc3febbe..6357c3580d07 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -167,7 +167,8 @@  static int __replace_page(struct vm_area_struct *vma, unsigned long addr,
 				addr + PAGE_SIZE);
 
 	if (new_page) {
-		err = mem_cgroup_charge(new_page, vma->vm_mm, GFP_KERNEL);
+		err = mem_cgroup_charge(page_folio(new_page), vma->vm_mm,
+					GFP_KERNEL);
 		if (err)
 			return err;
 	}
diff --git a/mm/filemap.c b/mm/filemap.c
index 8e6c69db5559..44498bfe7b45 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -872,7 +872,7 @@  noinline int __add_to_page_cache_locked(struct page *page,
 	page->index = offset;
 
 	if (!huge) {
-		error = mem_cgroup_charge(page, NULL, gfp);
+		error = mem_cgroup_charge(page_folio(page), NULL, gfp);
 		if (error)
 			goto error;
 		charged = true;
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index afff3ac87067..ecb1fb1f5f3e 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -603,7 +603,7 @@  static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf,
 
 	VM_BUG_ON_PAGE(!PageCompound(page), page);
 
-	if (mem_cgroup_charge(page, vma->vm_mm, gfp)) {
+	if (mem_cgroup_charge(page_folio(page), vma->vm_mm, gfp)) {
 		put_page(page);
 		count_vm_event(THP_FAULT_FALLBACK);
 		count_vm_event(THP_FAULT_FALLBACK_CHARGE);
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index b0412be08fa2..8f6d7fdea9f4 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -1087,7 +1087,7 @@  static void collapse_huge_page(struct mm_struct *mm,
 		goto out_nolock;
 	}
 
-	if (unlikely(mem_cgroup_charge(new_page, mm, gfp))) {
+	if (unlikely(mem_cgroup_charge(page_folio(new_page), mm, gfp))) {
 		result = SCAN_CGROUP_CHARGE_FAIL;
 		goto out_nolock;
 	}
@@ -1658,7 +1658,7 @@  static void collapse_file(struct mm_struct *mm,
 		goto out;
 	}
 
-	if (unlikely(mem_cgroup_charge(new_page, mm, gfp))) {
+	if (unlikely(mem_cgroup_charge(page_folio(new_page), mm, gfp))) {
 		result = SCAN_CGROUP_CHARGE_FAIL;
 		goto out;
 	}
diff --git a/mm/ksm.c b/mm/ksm.c
index 3fa9bc8a67cf..23d36b59f997 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -2580,7 +2580,8 @@  struct page *ksm_might_need_to_copy(struct page *page,
 		return page;		/* let do_swap_page report the error */
 
 	new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, address);
-	if (new_page && mem_cgroup_charge(new_page, vma->vm_mm, GFP_KERNEL)) {
+	if (new_page &&
+	    mem_cgroup_charge(page_folio(new_page), vma->vm_mm, GFP_KERNEL)) {
 		put_page(new_page);
 		new_page = NULL;
 	}
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index f64869c0e06e..ebad42c55f76 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -6681,10 +6681,9 @@  void mem_cgroup_calculate_protection(struct mem_cgroup *root,
 			atomic_long_read(&parent->memory.children_low_usage)));
 }
 
-static int __mem_cgroup_charge(struct page *page, struct mem_cgroup *memcg,
+static int __mem_cgroup_charge(struct folio *folio, struct mem_cgroup *memcg,
 			       gfp_t gfp)
 {
-	struct folio *folio = page_folio(page);
 	unsigned int nr_pages = folio_nr_pages(folio);
 	int ret;
 
@@ -6697,27 +6696,27 @@  static int __mem_cgroup_charge(struct page *page, struct mem_cgroup *memcg,
 
 	local_irq_disable();
 	mem_cgroup_charge_statistics(memcg, nr_pages);
-	memcg_check_events(memcg, page_to_nid(page));
+	memcg_check_events(memcg, folio_nid(folio));
 	local_irq_enable();
 out:
 	return ret;
 }
 
 /**
- * mem_cgroup_charge - charge a newly allocated page to a cgroup
- * @page: page to charge
- * @mm: mm context of the victim
- * @gfp_mask: reclaim mode
+ * mem_cgroup_charge - Charge a newly allocated folio to a cgroup.
+ * @folio: Folio to charge.
+ * @mm: mm context of the allocating task.
+ * @gfp: reclaim mode
  *
- * Try to charge @page to the memcg that @mm belongs to, reclaiming
- * pages according to @gfp_mask if necessary. if @mm is NULL, try to
+ * Try to charge @folio to the memcg that @mm belongs to, reclaiming
+ * pages according to @gfp if necessary.  If @mm is NULL, try to
  * charge to the active memcg.
  *
- * Do not use this for pages allocated for swapin.
+ * Do not use this for folios allocated for swapin.
  *
  * Returns 0 on success. Otherwise, an error code is returned.
  */
-int mem_cgroup_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask)
+int mem_cgroup_charge(struct folio *folio, struct mm_struct *mm, gfp_t gfp)
 {
 	struct mem_cgroup *memcg;
 	int ret;
@@ -6726,7 +6725,7 @@  int mem_cgroup_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask)
 		return 0;
 
 	memcg = get_mem_cgroup_from_mm(mm);
-	ret = __mem_cgroup_charge(page, memcg, gfp_mask);
+	ret = __mem_cgroup_charge(folio, memcg, gfp);
 	css_put(&memcg->css);
 
 	return ret;
@@ -6747,6 +6746,7 @@  int mem_cgroup_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask)
 int mem_cgroup_swapin_charge_page(struct page *page, struct mm_struct *mm,
 				  gfp_t gfp, swp_entry_t entry)
 {
+	struct folio *folio = page_folio(page);
 	struct mem_cgroup *memcg;
 	unsigned short id;
 	int ret;
@@ -6761,7 +6761,7 @@  int mem_cgroup_swapin_charge_page(struct page *page, struct mm_struct *mm,
 		memcg = get_mem_cgroup_from_mm(mm);
 	rcu_read_unlock();
 
-	ret = __mem_cgroup_charge(page, memcg, gfp);
+	ret = __mem_cgroup_charge(folio, memcg, gfp);
 
 	css_put(&memcg->css);
 	return ret;
diff --git a/mm/memory.c b/mm/memory.c
index 2f111f9b3dbc..614418e26e2c 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -990,7 +990,7 @@  page_copy_prealloc(struct mm_struct *src_mm, struct vm_area_struct *vma,
 	if (!new_page)
 		return NULL;
 
-	if (mem_cgroup_charge(new_page, src_mm, GFP_KERNEL)) {
+	if (mem_cgroup_charge(page_folio(new_page), src_mm, GFP_KERNEL)) {
 		put_page(new_page);
 		return NULL;
 	}
@@ -3019,7 +3019,7 @@  static vm_fault_t wp_page_copy(struct vm_fault *vmf)
 		}
 	}
 
-	if (mem_cgroup_charge(new_page, mm, GFP_KERNEL))
+	if (mem_cgroup_charge(page_folio(new_page), mm, GFP_KERNEL))
 		goto oom_free_new;
 	cgroup_throttle_swaprate(new_page, GFP_KERNEL);
 
@@ -3768,7 +3768,7 @@  static vm_fault_t do_anonymous_page(struct vm_fault *vmf)
 	if (!page)
 		goto oom;
 
-	if (mem_cgroup_charge(page, vma->vm_mm, GFP_KERNEL))
+	if (mem_cgroup_charge(page_folio(page), vma->vm_mm, GFP_KERNEL))
 		goto oom_free_page;
 	cgroup_throttle_swaprate(page, GFP_KERNEL);
 
@@ -4183,7 +4183,8 @@  static vm_fault_t do_cow_fault(struct vm_fault *vmf)
 	if (!vmf->cow_page)
 		return VM_FAULT_OOM;
 
-	if (mem_cgroup_charge(vmf->cow_page, vma->vm_mm, GFP_KERNEL)) {
+	if (mem_cgroup_charge(page_folio(vmf->cow_page), vma->vm_mm,
+				GFP_KERNEL)) {
 		put_page(vmf->cow_page);
 		return VM_FAULT_OOM;
 	}
diff --git a/mm/migrate.c b/mm/migrate.c
index 23cbd9de030b..01c05d7f9d6a 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -2811,7 +2811,7 @@  static void migrate_vma_insert_page(struct migrate_vma *migrate,
 
 	if (unlikely(anon_vma_prepare(vma)))
 		goto abort;
-	if (mem_cgroup_charge(page, vma->vm_mm, GFP_KERNEL))
+	if (mem_cgroup_charge(page_folio(page), vma->vm_mm, GFP_KERNEL))
 		goto abort;
 
 	/*
diff --git a/mm/shmem.c b/mm/shmem.c
index 70d9ce294bb4..3931fed5c8d8 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -685,7 +685,7 @@  static int shmem_add_to_page_cache(struct page *page,
 	page->index = index;
 
 	if (!PageSwapCache(page)) {
-		error = mem_cgroup_charge(page, charge_mm, gfp);
+		error = mem_cgroup_charge(page_folio(page), charge_mm, gfp);
 		if (error) {
 			if (PageTransHuge(page)) {
 				count_vm_event(THP_FILE_FALLBACK);
diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
index 0e2132834bc7..5d0f55f3c0ed 100644
--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -164,7 +164,7 @@  static int mcopy_atomic_pte(struct mm_struct *dst_mm,
 	__SetPageUptodate(page);
 
 	ret = -ENOMEM;
-	if (mem_cgroup_charge(page, dst_mm, GFP_KERNEL))
+	if (mem_cgroup_charge(page_folio(page), dst_mm, GFP_KERNEL))
 		goto out_release;
 
 	ret = mfill_atomic_install_pte(dst_mm, dst_pmd, dst_vma, dst_addr,