[patch] mm: memcontrol: use per-cpu caches for uncharging

From: Johannes Weiner
Date: Tue Sep 02 2014 - 18:11:39 EST


---
mm/memcontrol.c | 28 ++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index ec4dcf1b9562..cb79ecff399d 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2365,6 +2365,7 @@ static void drain_stock(struct memcg_stock_pcp *stock)
res_counter_uncharge(&old->res, bytes);
if (do_swap_account)
res_counter_uncharge(&old->memsw, bytes);
+ memcg_oom_recover(old);
stock->nr_pages = 0;
}
stock->cached = NULL;
@@ -2405,6 +2406,13 @@ static void refill_stock(struct mem_cgroup *memcg, unsigned int nr_pages)
stock->cached = memcg;
}
stock->nr_pages += nr_pages;
+ if (stock->nr_pages > CHARGE_BATCH * 4) {
+ res_counter_uncharge(&memcg->res, CHARGE_BATCH);
+ if (do_swap_account)
+ res_counter_uncharge(&memcg->memsw, CHARGE_BATCH);
+ memcg_oom_recover(memcg);
+ stock->nr_pages -= CHARGE_BATCH;
+ }
put_cpu_var(memcg_stock);
}

@@ -6509,12 +6517,20 @@ static void uncharge_batch(struct mem_cgroup *memcg, unsigned long pgpgout,
{
unsigned long flags;

- if (nr_mem)
- res_counter_uncharge(&memcg->res, nr_mem * PAGE_SIZE);
- if (nr_memsw)
- res_counter_uncharge(&memcg->memsw, nr_memsw * PAGE_SIZE);
-
- memcg_oom_recover(memcg);
+ /*
+ * The percpu caches count both memory and memsw charges in a
+ * single conuter, but there might be less memsw charges when
+ * some of the pages have been swapped out.
+ */
+ if (nr_mem == nr_memsw)
+ refill_stock(memcg, nr_mem);
+ else {
+ if (nr_mem)
+ res_counter_uncharge(&memcg->res, nr_mem * PAGE_SIZE);
+ if (nr_memsw)
+ res_counter_uncharge(&memcg->memsw, nr_memsw * PAGE_SIZE);
+ memcg_oom_recover(memcg);
+ }

local_irq_save(flags);
__this_cpu_sub(memcg->stat->count[MEM_CGROUP_STAT_RSS], nr_anon);
--
2.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/