mm/memcg: Convert mem_cgroup_move_account() to use a folio

This saves dozens of bytes of text by eliminating a lot of calls to
compound_head().
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 f70ad448
...@@ -5567,38 +5567,39 @@ static int mem_cgroup_move_account(struct page *page, ...@@ -5567,38 +5567,39 @@ static int mem_cgroup_move_account(struct page *page,
struct mem_cgroup *from, struct mem_cgroup *from,
struct mem_cgroup *to) struct mem_cgroup *to)
{ {
struct folio *folio = page_folio(page);
struct lruvec *from_vec, *to_vec; struct lruvec *from_vec, *to_vec;
struct pglist_data *pgdat; struct pglist_data *pgdat;
unsigned int nr_pages = compound ? thp_nr_pages(page) : 1; unsigned int nr_pages = compound ? folio_nr_pages(folio) : 1;
int nid, ret; int nid, ret;
VM_BUG_ON(from == to); VM_BUG_ON(from == to);
VM_BUG_ON_PAGE(PageLRU(page), page); VM_BUG_ON_FOLIO(folio_test_lru(folio), folio);
VM_BUG_ON(compound && !PageTransHuge(page)); VM_BUG_ON(compound && !folio_test_multi(folio));
/* /*
* Prevent mem_cgroup_migrate() from looking at * Prevent mem_cgroup_migrate() from looking at
* page's memory cgroup of its source page while we change it. * page's memory cgroup of its source page while we change it.
*/ */
ret = -EBUSY; ret = -EBUSY;
if (!trylock_page(page)) if (!folio_trylock(folio))
goto out; goto out;
ret = -EINVAL; ret = -EINVAL;
if (page_memcg(page) != from) if (folio_memcg(folio) != from)
goto out_unlock; goto out_unlock;
pgdat = page_pgdat(page); pgdat = folio_pgdat(folio);
from_vec = mem_cgroup_lruvec(from, pgdat); from_vec = mem_cgroup_lruvec(from, pgdat);
to_vec = mem_cgroup_lruvec(to, pgdat); to_vec = mem_cgroup_lruvec(to, pgdat);
lock_page_memcg(page); folio_memcg_lock(folio);
if (PageAnon(page)) { if (folio_test_anon(folio)) {
if (page_mapped(page)) { if (folio_mapped(folio)) {
__mod_lruvec_state(from_vec, NR_ANON_MAPPED, -nr_pages); __mod_lruvec_state(from_vec, NR_ANON_MAPPED, -nr_pages);
__mod_lruvec_state(to_vec, NR_ANON_MAPPED, nr_pages); __mod_lruvec_state(to_vec, NR_ANON_MAPPED, nr_pages);
if (PageTransHuge(page)) { if (folio_test_transhuge(folio)) {
__mod_lruvec_state(from_vec, NR_ANON_THPS, __mod_lruvec_state(from_vec, NR_ANON_THPS,
-nr_pages); -nr_pages);
__mod_lruvec_state(to_vec, NR_ANON_THPS, __mod_lruvec_state(to_vec, NR_ANON_THPS,
...@@ -5609,18 +5610,18 @@ static int mem_cgroup_move_account(struct page *page, ...@@ -5609,18 +5610,18 @@ static int mem_cgroup_move_account(struct page *page,
__mod_lruvec_state(from_vec, NR_FILE_PAGES, -nr_pages); __mod_lruvec_state(from_vec, NR_FILE_PAGES, -nr_pages);
__mod_lruvec_state(to_vec, NR_FILE_PAGES, nr_pages); __mod_lruvec_state(to_vec, NR_FILE_PAGES, nr_pages);
if (PageSwapBacked(page)) { if (folio_test_swapbacked(folio)) {
__mod_lruvec_state(from_vec, NR_SHMEM, -nr_pages); __mod_lruvec_state(from_vec, NR_SHMEM, -nr_pages);
__mod_lruvec_state(to_vec, NR_SHMEM, nr_pages); __mod_lruvec_state(to_vec, NR_SHMEM, nr_pages);
} }
if (page_mapped(page)) { if (folio_mapped(folio)) {
__mod_lruvec_state(from_vec, NR_FILE_MAPPED, -nr_pages); __mod_lruvec_state(from_vec, NR_FILE_MAPPED, -nr_pages);
__mod_lruvec_state(to_vec, NR_FILE_MAPPED, nr_pages); __mod_lruvec_state(to_vec, NR_FILE_MAPPED, nr_pages);
} }
if (PageDirty(page)) { if (folio_test_dirty(folio)) {
struct address_space *mapping = page_mapping(page); struct address_space *mapping = folio_mapping(folio);
if (mapping_can_writeback(mapping)) { if (mapping_can_writeback(mapping)) {
__mod_lruvec_state(from_vec, NR_FILE_DIRTY, __mod_lruvec_state(from_vec, NR_FILE_DIRTY,
...@@ -5631,7 +5632,7 @@ static int mem_cgroup_move_account(struct page *page, ...@@ -5631,7 +5632,7 @@ static int mem_cgroup_move_account(struct page *page,
} }
} }
if (PageWriteback(page)) { if (folio_test_writeback(folio)) {
__mod_lruvec_state(from_vec, NR_WRITEBACK, -nr_pages); __mod_lruvec_state(from_vec, NR_WRITEBACK, -nr_pages);
__mod_lruvec_state(to_vec, NR_WRITEBACK, nr_pages); __mod_lruvec_state(to_vec, NR_WRITEBACK, nr_pages);
} }
...@@ -5654,12 +5655,12 @@ static int mem_cgroup_move_account(struct page *page, ...@@ -5654,12 +5655,12 @@ static int mem_cgroup_move_account(struct page *page,
css_get(&to->css); css_get(&to->css);
css_put(&from->css); css_put(&from->css);
page->memcg_data = (unsigned long)to; folio->memcg_data = (unsigned long)to;
__folio_memcg_unlock(from); __folio_memcg_unlock(from);
ret = 0; ret = 0;
nid = page_to_nid(page); nid = folio_nid(folio);
local_irq_disable(); local_irq_disable();
mem_cgroup_charge_statistics(to, nr_pages); mem_cgroup_charge_statistics(to, nr_pages);
...@@ -5668,7 +5669,7 @@ static int mem_cgroup_move_account(struct page *page, ...@@ -5668,7 +5669,7 @@ static int mem_cgroup_move_account(struct page *page,
memcg_check_events(from, nid); memcg_check_events(from, nid);
local_irq_enable(); local_irq_enable();
out_unlock: out_unlock:
unlock_page(page); folio_unlock(folio);
out: out:
return ret; return ret;
} }
......
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