]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - mm/memcontrol.c
scm: lower SCM_MAX_FD
[net-next-2.6.git] / mm / memcontrol.c
index 31a1d3b71eee269824036a70a067e2b9de65c05d..2efa8ea07ff7d931577da964c190f5524088da3d 100644 (file)
@@ -1132,11 +1132,14 @@ static unsigned int get_swappiness(struct mem_cgroup *memcg)
 static void mem_cgroup_start_move(struct mem_cgroup *mem)
 {
        int cpu;
-       /* Because this is for moving account, reuse mc.lock */
-       spin_lock(&mc.lock);
-       for_each_possible_cpu(cpu)
+
+       get_online_cpus();
+       spin_lock(&mem->pcp_counter_lock);
+       for_each_online_cpu(cpu)
                per_cpu(mem->stat->count[MEM_CGROUP_ON_MOVE], cpu) += 1;
-       spin_unlock(&mc.lock);
+       mem->nocpu_base.count[MEM_CGROUP_ON_MOVE] += 1;
+       spin_unlock(&mem->pcp_counter_lock);
+       put_online_cpus();
 
        synchronize_rcu();
 }
@@ -1147,10 +1150,13 @@ static void mem_cgroup_end_move(struct mem_cgroup *mem)
 
        if (!mem)
                return;
-       spin_lock(&mc.lock);
-       for_each_possible_cpu(cpu)
+       get_online_cpus();
+       spin_lock(&mem->pcp_counter_lock);
+       for_each_online_cpu(cpu)
                per_cpu(mem->stat->count[MEM_CGROUP_ON_MOVE], cpu) -= 1;
-       spin_unlock(&mc.lock);
+       mem->nocpu_base.count[MEM_CGROUP_ON_MOVE] -= 1;
+       spin_unlock(&mem->pcp_counter_lock);
+       put_online_cpus();
 }
 /*
  * 2 routines for checking "mem" is under move_account() or not.
@@ -1585,7 +1591,8 @@ bool mem_cgroup_handle_oom(struct mem_cgroup *mem, gfp_t mask)
  * small, we check MEM_CGROUP_ON_MOVE percpu value and detect there are
  * possibility of race condition. If there is, we take a lock.
  */
-void mem_cgroup_update_file_mapped(struct page *page, int val)
+
+static void mem_cgroup_update_file_stat(struct page *page, int idx, int val)
 {
        struct mem_cgroup *mem;
        struct page_cgroup *pc = lookup_page_cgroup(page);
@@ -1607,13 +1614,18 @@ void mem_cgroup_update_file_mapped(struct page *page, int val)
                if (!mem || !PageCgroupUsed(pc))
                        goto out;
        }
-       if (val > 0) {
-               this_cpu_inc(mem->stat->count[MEM_CGROUP_STAT_FILE_MAPPED]);
-               SetPageCgroupFileMapped(pc);
-       } else {
-               this_cpu_dec(mem->stat->count[MEM_CGROUP_STAT_FILE_MAPPED]);
-               if (!page_mapped(page)) /* for race between dec->inc counter */
+
+       this_cpu_add(mem->stat->count[idx], val);
+
+       switch (idx) {
+       case MEM_CGROUP_STAT_FILE_MAPPED:
+               if (val > 0)
+                       SetPageCgroupFileMapped(pc);
+               else if (!page_mapped(page))
                        ClearPageCgroupFileMapped(pc);
+               break;
+       default:
+               BUG();
        }
 
 out:
@@ -1623,6 +1635,11 @@ out:
        return;
 }
 
+void mem_cgroup_update_file_mapped(struct page *page, int val)
+{
+       mem_cgroup_update_file_stat(page, MEM_CGROUP_STAT_FILE_MAPPED, val);
+}
+
 /*
  * size of first charge trial. "32" comes from vmscan.c's magic value.
  * TODO: maybe necessary to use big numbers in big irons.
@@ -1751,6 +1768,17 @@ static void mem_cgroup_drain_pcp_counter(struct mem_cgroup *mem, int cpu)
                per_cpu(mem->stat->count[i], cpu) = 0;
                mem->nocpu_base.count[i] += x;
        }
+       /* need to clear ON_MOVE value, works as a kind of lock. */
+       per_cpu(mem->stat->count[MEM_CGROUP_ON_MOVE], cpu) = 0;
+       spin_unlock(&mem->pcp_counter_lock);
+}
+
+static void synchronize_mem_cgroup_on_move(struct mem_cgroup *mem, int cpu)
+{
+       int idx = MEM_CGROUP_ON_MOVE;
+
+       spin_lock(&mem->pcp_counter_lock);
+       per_cpu(mem->stat->count[idx], cpu) = mem->nocpu_base.count[idx];
        spin_unlock(&mem->pcp_counter_lock);
 }
 
@@ -1762,6 +1790,12 @@ static int __cpuinit memcg_cpu_hotplug_callback(struct notifier_block *nb,
        struct memcg_stock_pcp *stock;
        struct mem_cgroup *iter;
 
+       if ((action == CPU_ONLINE)) {
+               for_each_mem_cgroup_all(iter)
+                       synchronize_mem_cgroup_on_move(iter, cpu);
+               return NOTIFY_OK;
+       }
+
        if ((action != CPU_DEAD) || action != CPU_DEAD_FROZEN)
                return NOTIFY_OK;
 
@@ -4174,15 +4208,17 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
 
        memset(mem, 0, size);
        mem->stat = alloc_percpu(struct mem_cgroup_stat_cpu);
-       if (!mem->stat) {
-               if (size < PAGE_SIZE)
-                       kfree(mem);
-               else
-                       vfree(mem);
-               mem = NULL;
-       }
+       if (!mem->stat)
+               goto out_free;
        spin_lock_init(&mem->pcp_counter_lock);
        return mem;
+
+out_free:
+       if (size < PAGE_SIZE)
+               kfree(mem);
+       else
+               vfree(mem);
+       return NULL;
 }
 
 /*