}
#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:
*
* - 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)
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);
goto out;
css_get(&memcg->css);
- commit_charge(page, memcg);
+ commit_charge(folio, memcg);
local_irq_disable();
mem_cgroup_charge_statistics(memcg, nr_pages);
*/
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);
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())
}
css_get(&memcg->css);
- commit_charge(newpage, memcg);
+ commit_charge(newfolio, memcg);
local_irq_save(flags);
mem_cgroup_charge_statistics(memcg, nr_pages);