summaryrefslogtreecommitdiff
path: root/mm/memcontrol.c
diff options
context:
space:
mode:
authorMatthew Wilcox (Oracle) <willy@infradead.org>2021-04-29 21:07:12 +0300
committerMatthew Wilcox (Oracle) <willy@infradead.org>2021-09-27 16:27:31 +0300
commit118f2875490b027218594db9e2effb52cebc7693 (patch)
tree3cde2eb680572d7e2459291d119f0b0d356c0fe1 /mm/memcontrol.c
parent1b7e4464d43a488e383843bf96ec62d12393bff1 (diff)
downloadlinux-118f2875490b027218594db9e2effb52cebc7693.tar.xz
mm/memcg: Convert commit_charge() to take a folio
The memcg_data is only set on the head page, so enforce that by typing it as a folio. Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Acked-by: Michal Hocko <mhocko@suse.com> Reviewed-by: David Howells <dhowells@redhat.com> Acked-by: Vlastimil Babka <vbabka@suse.cz>
Diffstat (limited to 'mm/memcontrol.c')
-rw-r--r--mm/memcontrol.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 1385ac6f688e..e352225970d2 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2711,9 +2711,9 @@ static void cancel_charge(struct mem_cgroup *memcg, unsigned int nr_pages)
}
#endif
-static void commit_charge(struct page *page, struct mem_cgroup *memcg)
+static void commit_charge(struct folio *folio, struct mem_cgroup *memcg)
{
- VM_BUG_ON_PAGE(page_memcg(page), page);
+ VM_BUG_ON_FOLIO(folio_memcg(folio), folio);
/*
* Any of the following ensures page's memcg stability:
*
@@ -2722,7 +2722,7 @@ static void commit_charge(struct page *page, struct mem_cgroup *memcg)
* - lock_page_memcg()
* - exclusive reference
*/
- page->memcg_data = (unsigned long)memcg;
+ folio->memcg_data = (unsigned long)memcg;
}
static struct mem_cgroup *get_mem_cgroup_from_objcg(struct obj_cgroup *objcg)
@@ -6662,7 +6662,8 @@ void mem_cgroup_calculate_protection(struct mem_cgroup *root,
static int charge_memcg(struct page *page, struct mem_cgroup *memcg, gfp_t gfp)
{
- unsigned int nr_pages = thp_nr_pages(page);
+ struct folio *folio = page_folio(page);
+ long nr_pages = folio_nr_pages(folio);
int ret;
ret = try_charge(memcg, gfp, nr_pages);
@@ -6670,7 +6671,7 @@ static int charge_memcg(struct page *page, struct mem_cgroup *memcg, gfp_t gfp)
goto out;
css_get(&memcg->css);
- commit_charge(page, memcg);
+ commit_charge(folio, memcg);
local_irq_disable();
mem_cgroup_charge_statistics(memcg, nr_pages);
@@ -6922,21 +6923,21 @@ void __mem_cgroup_uncharge_list(struct list_head *page_list)
*/
void mem_cgroup_migrate(struct page *oldpage, struct page *newpage)
{
+ struct folio *newfolio = page_folio(newpage);
struct mem_cgroup *memcg;
- unsigned int nr_pages;
+ long nr_pages = folio_nr_pages(newfolio);
unsigned long flags;
VM_BUG_ON_PAGE(!PageLocked(oldpage), oldpage);
- VM_BUG_ON_PAGE(!PageLocked(newpage), newpage);
- VM_BUG_ON_PAGE(PageAnon(oldpage) != PageAnon(newpage), newpage);
- VM_BUG_ON_PAGE(PageTransHuge(oldpage) != PageTransHuge(newpage),
- newpage);
+ VM_BUG_ON_FOLIO(!folio_test_locked(newfolio), newfolio);
+ VM_BUG_ON_FOLIO(PageAnon(oldpage) != folio_test_anon(newfolio), newfolio);
+ VM_BUG_ON_FOLIO(compound_nr(oldpage) != nr_pages, newfolio);
if (mem_cgroup_disabled())
return;
/* Page cache replacement: new page already charged? */
- if (page_memcg(newpage))
+ if (folio_memcg(newfolio))
return;
memcg = page_memcg(oldpage);
@@ -6945,8 +6946,6 @@ void mem_cgroup_migrate(struct page *oldpage, struct page *newpage)
return;
/* Force-charge the new page. The old one will be freed soon */
- nr_pages = thp_nr_pages(newpage);
-
if (!mem_cgroup_is_root(memcg)) {
page_counter_charge(&memcg->memory, nr_pages);
if (do_memsw_account())
@@ -6954,7 +6953,7 @@ void mem_cgroup_migrate(struct page *oldpage, struct page *newpage)
}
css_get(&memcg->css);
- commit_charge(newpage, memcg);
+ commit_charge(newfolio, memcg);
local_irq_save(flags);
mem_cgroup_charge_statistics(memcg, nr_pages);