]> err.no Git - linux-2.6/blobdiff - mm/memcontrol.c
tg3: sparse cleanup
[linux-2.6] / mm / memcontrol.c
index f72067094e05f3fc43534995cfd05f6562d4ac8f..2e0bfc93484b327557e6b88f509476c4f837ac8f 100644 (file)
@@ -533,6 +533,9 @@ static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm,
        unsigned long nr_retries = MEM_CGROUP_RECLAIM_RETRIES;
        struct mem_cgroup_per_zone *mz;
 
+       if (mem_cgroup_subsys.disabled)
+               return 0;
+
        /*
         * Should page_cgroup's go to their own slab?
         * One could optimize the performance of the charging routine
@@ -623,13 +626,13 @@ retry:
                goto retry;
        }
        page_assign_page_cgroup(page, pc);
-       unlock_page_cgroup(page);
 
        mz = page_cgroup_zoneinfo(pc);
        spin_lock_irqsave(&mz->lru_lock, flags);
        __mem_cgroup_add_list(pc);
        spin_unlock_irqrestore(&mz->lru_lock, flags);
 
+       unlock_page_cgroup(page);
 done:
        return 0;
 out:
@@ -665,6 +668,9 @@ void mem_cgroup_uncharge_page(struct page *page)
        struct mem_cgroup_per_zone *mz;
        unsigned long flags;
 
+       if (mem_cgroup_subsys.disabled)
+               return;
+
        /*
         * Check if our page_cgroup is valid
         */
@@ -677,14 +683,14 @@ void mem_cgroup_uncharge_page(struct page *page)
        VM_BUG_ON(pc->ref_cnt <= 0);
 
        if (--(pc->ref_cnt) == 0) {
-               page_assign_page_cgroup(page, NULL);
-               unlock_page_cgroup(page);
-
                mz = page_cgroup_zoneinfo(pc);
                spin_lock_irqsave(&mz->lru_lock, flags);
                __mem_cgroup_remove_list(pc);
                spin_unlock_irqrestore(&mz->lru_lock, flags);
 
+               page_assign_page_cgroup(page, NULL);
+               unlock_page_cgroup(page);
+
                mem = pc->mem_cgroup;
                res_counter_uncharge(&mem->res, PAGE_SIZE);
                css_put(&mem->css);
@@ -705,6 +711,9 @@ int mem_cgroup_prepare_migration(struct page *page)
 {
        struct page_cgroup *pc;
 
+       if (mem_cgroup_subsys.disabled)
+               return 0;
+
        lock_page_cgroup(page);
        pc = page_get_page_cgroup(page);
        if (pc)
@@ -736,23 +745,24 @@ void mem_cgroup_page_migration(struct page *page, struct page *newpage)
                return;
        }
 
-       page_assign_page_cgroup(page, NULL);
-       unlock_page_cgroup(page);
-
        mz = page_cgroup_zoneinfo(pc);
        spin_lock_irqsave(&mz->lru_lock, flags);
        __mem_cgroup_remove_list(pc);
        spin_unlock_irqrestore(&mz->lru_lock, flags);
 
+       page_assign_page_cgroup(page, NULL);
+       unlock_page_cgroup(page);
+
        pc->page = newpage;
        lock_page_cgroup(newpage);
        page_assign_page_cgroup(newpage, pc);
-       unlock_page_cgroup(newpage);
 
        mz = page_cgroup_zoneinfo(pc);
        spin_lock_irqsave(&mz->lru_lock, flags);
        __mem_cgroup_add_list(pc);
        spin_unlock_irqrestore(&mz->lru_lock, flags);
+
+       unlock_page_cgroup(newpage);
 }
 
 /*
@@ -802,6 +812,9 @@ static int mem_cgroup_force_empty(struct mem_cgroup *mem)
        int ret = -EBUSY;
        int node, zid;
 
+       if (mem_cgroup_subsys.disabled)
+               return 0;
+
        css_get(&mem->css);
        /*
         * page reclaim code (kswapd etc..) will move pages between
@@ -965,7 +978,7 @@ static int alloc_mem_cgroup_per_zone_info(struct mem_cgroup *mem, int node)
 {
        struct mem_cgroup_per_node *pn;
        struct mem_cgroup_per_zone *mz;
-       int zone;
+       int zone, tmp = node;
        /*
         * This routine is called against possible nodes.
         * But it's BUG to call kmalloc() against offline node.
@@ -974,10 +987,9 @@ static int alloc_mem_cgroup_per_zone_info(struct mem_cgroup *mem, int node)
         *       never be onlined. It's better to use memory hotplug callback
         *       function.
         */
-       if (node_state(node, N_HIGH_MEMORY))
-               pn = kmalloc_node(sizeof(*pn), GFP_KERNEL, node);
-       else
-               pn = kmalloc(sizeof(*pn), GFP_KERNEL);
+       if (!node_state(node, N_NORMAL_MEMORY))
+               tmp = -1;
+       pn = kmalloc_node(sizeof(*pn), GFP_KERNEL, tmp);
        if (!pn)
                return 1;
 
@@ -1052,6 +1064,8 @@ static void mem_cgroup_destroy(struct cgroup_subsys *ss,
 static int mem_cgroup_populate(struct cgroup_subsys *ss,
                                struct cgroup *cont)
 {
+       if (mem_cgroup_subsys.disabled)
+               return 0;
        return cgroup_add_files(cont, ss, mem_cgroup_files,
                                        ARRAY_SIZE(mem_cgroup_files));
 }
@@ -1064,6 +1078,9 @@ static void mem_cgroup_move_task(struct cgroup_subsys *ss,
        struct mm_struct *mm;
        struct mem_cgroup *mem, *old_mem;
 
+       if (mem_cgroup_subsys.disabled)
+               return;
+
        mm = get_task_mm(p);
        if (mm == NULL)
                return;
@@ -1078,7 +1095,7 @@ static void mem_cgroup_move_task(struct cgroup_subsys *ss,
         * Only thread group leaders are allowed to migrate, the mm_struct is
         * in effect owned by the leader
         */
-       if (p->tgid != p->pid)
+       if (!thread_group_leader(p))
                goto out;
 
        css_get(&mem->css);