Skip to content

Commit

Permalink
mm: memcontrol: remove unnecessary PCG_MEMSW memory+swap charge flag
Browse files Browse the repository at this point in the history
Now that mem_cgroup_swapout() fully uncharges the page, every page that is
still in use when reaching mem_cgroup_uncharge() is known to carry both
the memory and the memory+swap charge.  Simplify the uncharge path and
remove the PCG_MEMSW page flag accordingly.

Signed-off-by: Johannes Weiner <[email protected]>
Cc: Hugh Dickins <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Reviewed-by: Vladimir Davydov <[email protected]>
Acked-by: KAMEZAWA Hiroyuki <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
hnaz authored and torvalds committed Dec 11, 2014
1 parent 7bdd143 commit 18eca2e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
1 change: 0 additions & 1 deletion include/linux/page_cgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ enum {
/* flags for mem_cgroup */
PCG_USED = 0x01, /* This page is charged to a memcg */
PCG_MEM = 0x02, /* This page holds a memory charge */
PCG_MEMSW = 0x04, /* This page holds a memory+swap charge */
};

struct pglist_data;
Expand Down
34 changes: 12 additions & 22 deletions mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -2614,7 +2614,7 @@ static void commit_charge(struct page *page, struct mem_cgroup *memcg,
* have the page locked
*/
pc->mem_cgroup = memcg;
pc->flags = PCG_USED | PCG_MEM | (do_swap_account ? PCG_MEMSW : 0);
pc->flags = PCG_USED | PCG_MEM;

if (lrucare)
unlock_page_lru(page, isolated);
Expand Down Expand Up @@ -5793,7 +5793,6 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry)
if (!PageCgroupUsed(pc))
return;

VM_BUG_ON_PAGE(!(pc->flags & PCG_MEMSW), page);
memcg = pc->mem_cgroup;

oldid = swap_cgroup_record(entry, mem_cgroup_id(memcg));
Expand Down Expand Up @@ -5989,17 +5988,16 @@ void mem_cgroup_cancel_charge(struct page *page, struct mem_cgroup *memcg)
}

static void uncharge_batch(struct mem_cgroup *memcg, unsigned long pgpgout,
unsigned long nr_mem, unsigned long nr_memsw,
unsigned long nr_anon, unsigned long nr_file,
unsigned long nr_huge, struct page *dummy_page)
{
unsigned long nr_pages = nr_anon + nr_file;
unsigned long flags;

if (!mem_cgroup_is_root(memcg)) {
if (nr_mem)
page_counter_uncharge(&memcg->memory, nr_mem);
if (nr_memsw)
page_counter_uncharge(&memcg->memsw, nr_memsw);
page_counter_uncharge(&memcg->memory, nr_pages);
if (do_swap_account)
page_counter_uncharge(&memcg->memsw, nr_pages);
memcg_oom_recover(memcg);
}

Expand All @@ -6008,23 +6006,21 @@ static void uncharge_batch(struct mem_cgroup *memcg, unsigned long pgpgout,
__this_cpu_sub(memcg->stat->count[MEM_CGROUP_STAT_CACHE], nr_file);
__this_cpu_sub(memcg->stat->count[MEM_CGROUP_STAT_RSS_HUGE], nr_huge);
__this_cpu_add(memcg->stat->events[MEM_CGROUP_EVENTS_PGPGOUT], pgpgout);
__this_cpu_add(memcg->stat->nr_page_events, nr_anon + nr_file);
__this_cpu_add(memcg->stat->nr_page_events, nr_pages);
memcg_check_events(memcg, dummy_page);
local_irq_restore(flags);

if (!mem_cgroup_is_root(memcg))
css_put_many(&memcg->css, max(nr_mem, nr_memsw));
css_put_many(&memcg->css, nr_pages);
}

static void uncharge_list(struct list_head *page_list)
{
struct mem_cgroup *memcg = NULL;
unsigned long nr_memsw = 0;
unsigned long nr_anon = 0;
unsigned long nr_file = 0;
unsigned long nr_huge = 0;
unsigned long pgpgout = 0;
unsigned long nr_mem = 0;
struct list_head *next;
struct page *page;

Expand All @@ -6051,10 +6047,9 @@ static void uncharge_list(struct list_head *page_list)

if (memcg != pc->mem_cgroup) {
if (memcg) {
uncharge_batch(memcg, pgpgout, nr_mem, nr_memsw,
nr_anon, nr_file, nr_huge, page);
pgpgout = nr_mem = nr_memsw = 0;
nr_anon = nr_file = nr_huge = 0;
uncharge_batch(memcg, pgpgout, nr_anon, nr_file,
nr_huge, page);
pgpgout = nr_anon = nr_file = nr_huge = 0;
}
memcg = pc->mem_cgroup;
}
Expand All @@ -6070,18 +6065,14 @@ static void uncharge_list(struct list_head *page_list)
else
nr_file += nr_pages;

if (pc->flags & PCG_MEM)
nr_mem += nr_pages;
if (pc->flags & PCG_MEMSW)
nr_memsw += nr_pages;
pc->flags = 0;

pgpgout++;
} while (next != page_list);

if (memcg)
uncharge_batch(memcg, pgpgout, nr_mem, nr_memsw,
nr_anon, nr_file, nr_huge, page);
uncharge_batch(memcg, pgpgout, nr_anon, nr_file,
nr_huge, page);
}

/**
Expand Down Expand Up @@ -6166,7 +6157,6 @@ void mem_cgroup_migrate(struct page *oldpage, struct page *newpage,
return;

VM_BUG_ON_PAGE(!(pc->flags & PCG_MEM), oldpage);
VM_BUG_ON_PAGE(do_swap_account && !(pc->flags & PCG_MEMSW), oldpage);

if (lrucare)
lock_page_lru(oldpage, &isolated);
Expand Down

0 comments on commit 18eca2e

Please sign in to comment.