mm/memcg: Convert uncharge_page() to uncharge_folio()

Use a folio rather than a page to ensure that we're only operating on
base or head pages, and not tail pages.
Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDavid Howells <dhowells@redhat.com>
Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
parent 8f425e4e
...@@ -6794,24 +6794,23 @@ static void uncharge_batch(const struct uncharge_gather *ug) ...@@ -6794,24 +6794,23 @@ static void uncharge_batch(const struct uncharge_gather *ug)
memcg_check_events(ug->memcg, ug->nid); memcg_check_events(ug->memcg, ug->nid);
local_irq_restore(flags); local_irq_restore(flags);
/* drop reference from uncharge_page */ /* drop reference from uncharge_folio */
css_put(&ug->memcg->css); css_put(&ug->memcg->css);
} }
static void uncharge_page(struct page *page, struct uncharge_gather *ug) static void uncharge_folio(struct folio *folio, struct uncharge_gather *ug)
{ {
struct folio *folio = page_folio(page); long nr_pages;
unsigned long nr_pages;
struct mem_cgroup *memcg; struct mem_cgroup *memcg;
struct obj_cgroup *objcg; struct obj_cgroup *objcg;
bool use_objcg = PageMemcgKmem(page); bool use_objcg = folio_memcg_kmem(folio);
VM_BUG_ON_PAGE(PageLRU(page), page); VM_BUG_ON_FOLIO(folio_test_lru(folio), folio);
/* /*
* Nobody should be changing or seriously looking at * Nobody should be changing or seriously looking at
* page memcg or objcg at this point, we have fully * folio memcg or objcg at this point, we have fully
* exclusive access to the page. * exclusive access to the folio.
*/ */
if (use_objcg) { if (use_objcg) {
objcg = __folio_objcg(folio); objcg = __folio_objcg(folio);
...@@ -6833,19 +6832,19 @@ static void uncharge_page(struct page *page, struct uncharge_gather *ug) ...@@ -6833,19 +6832,19 @@ static void uncharge_page(struct page *page, struct uncharge_gather *ug)
uncharge_gather_clear(ug); uncharge_gather_clear(ug);
} }
ug->memcg = memcg; ug->memcg = memcg;
ug->nid = page_to_nid(page); ug->nid = folio_nid(folio);
/* pairs with css_put in uncharge_batch */ /* pairs with css_put in uncharge_batch */
css_get(&memcg->css); css_get(&memcg->css);
} }
nr_pages = compound_nr(page); nr_pages = folio_nr_pages(folio);
if (use_objcg) { if (use_objcg) {
ug->nr_memory += nr_pages; ug->nr_memory += nr_pages;
ug->nr_kmem += nr_pages; ug->nr_kmem += nr_pages;
page->memcg_data = 0; folio->memcg_data = 0;
obj_cgroup_put(objcg); obj_cgroup_put(objcg);
} else { } else {
/* LRU pages aren't accounted at the root level */ /* LRU pages aren't accounted at the root level */
...@@ -6853,7 +6852,7 @@ static void uncharge_page(struct page *page, struct uncharge_gather *ug) ...@@ -6853,7 +6852,7 @@ static void uncharge_page(struct page *page, struct uncharge_gather *ug)
ug->nr_memory += nr_pages; ug->nr_memory += nr_pages;
ug->pgpgout++; ug->pgpgout++;
page->memcg_data = 0; folio->memcg_data = 0;
} }
css_put(&memcg->css); css_put(&memcg->css);
...@@ -6874,7 +6873,7 @@ void __mem_cgroup_uncharge(struct page *page) ...@@ -6874,7 +6873,7 @@ void __mem_cgroup_uncharge(struct page *page)
return; return;
uncharge_gather_clear(&ug); uncharge_gather_clear(&ug);
uncharge_page(page, &ug); uncharge_folio(page_folio(page), &ug);
uncharge_batch(&ug); uncharge_batch(&ug);
} }
...@@ -6888,11 +6887,11 @@ void __mem_cgroup_uncharge(struct page *page) ...@@ -6888,11 +6887,11 @@ void __mem_cgroup_uncharge(struct page *page)
void __mem_cgroup_uncharge_list(struct list_head *page_list) void __mem_cgroup_uncharge_list(struct list_head *page_list)
{ {
struct uncharge_gather ug; struct uncharge_gather ug;
struct page *page; struct folio *folio;
uncharge_gather_clear(&ug); uncharge_gather_clear(&ug);
list_for_each_entry(page, page_list, lru) list_for_each_entry(folio, page_list, lru)
uncharge_page(page, &ug); uncharge_folio(folio, &ug);
if (ug.memcg) if (ug.memcg)
uncharge_batch(&ug); uncharge_batch(&ug);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment