memcg: convert uncharge batching from bytes to page granularity
authorJohannes Weiner <hannes@cmpxchg.org>
Wed, 23 Mar 2011 23:42:35 +0000 (16:42 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 24 Mar 2011 02:46:30 +0000 (19:46 -0700)
We never uncharge subpage quantities.

Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Cc: Balbir Singh <balbir@linux.vnet.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/sched.h
mm/memcontrol.c

index 4b601be3daced5b6a34feec4394ea731be25e19b..98fc7ed4b191317db5141b9264a39fc28a2d2c2e 100644 (file)
@@ -1524,8 +1524,8 @@ struct task_struct {
        struct memcg_batch_info {
                int do_batch;   /* incremented when batch uncharge started */
                struct mem_cgroup *memcg; /* target memcg of uncharge */
-               unsigned long bytes;            /* uncharged usage */
-               unsigned long memsw_bytes; /* uncharged mem+swap usage */
+               unsigned long nr_pages; /* uncharged usage */
+               unsigned long memsw_nr_pages; /* uncharged mem+swap usage */
        } memcg_batch;
 #endif
 };
index 91120a04f935180029244ff517bc4fb9652f6497..9dfbed2aacc9b6b5fa43e4a8ef9d007b0fde3418 100644 (file)
@@ -2579,9 +2579,9 @@ __do_uncharge(struct mem_cgroup *mem, const enum charge_type ctype,
        if (batch->memcg != mem)
                goto direct_uncharge;
        /* remember freed charge and uncharge it later */
-       batch->bytes += PAGE_SIZE;
+       batch->nr_pages++;
        if (uncharge_memsw)
-               batch->memsw_bytes += PAGE_SIZE;
+               batch->memsw_nr_pages++;
        return;
 direct_uncharge:
        res_counter_uncharge(&mem->res, page_size);
@@ -2708,8 +2708,8 @@ void mem_cgroup_uncharge_start(void)
        /* We can do nest. */
        if (current->memcg_batch.do_batch == 1) {
                current->memcg_batch.memcg = NULL;
-               current->memcg_batch.bytes = 0;
-               current->memcg_batch.memsw_bytes = 0;
+               current->memcg_batch.nr_pages = 0;
+               current->memcg_batch.memsw_nr_pages = 0;
        }
 }
 
@@ -2730,10 +2730,12 @@ void mem_cgroup_uncharge_end(void)
         * This "batch->memcg" is valid without any css_get/put etc...
         * bacause we hide charges behind us.
         */
-       if (batch->bytes)
-               res_counter_uncharge(&batch->memcg->res, batch->bytes);
-       if (batch->memsw_bytes)
-               res_counter_uncharge(&batch->memcg->memsw, batch->memsw_bytes);
+       if (batch->nr_pages)
+               res_counter_uncharge(&batch->memcg->res,
+                                    batch->nr_pages * PAGE_SIZE);
+       if (batch->memsw_nr_pages)
+               res_counter_uncharge(&batch->memcg->memsw,
+                                    batch->memsw_nr_pages * PAGE_SIZE);
        memcg_oom_recover(batch->memcg);
        /* forget this pointer (for sanity check) */
        batch->memcg = NULL;