Call alloc_mem_cgroup_per_node_info() and IDR allocation later. This is preparation for next patches, which will require this two actions are made nearby (they will be done under read lock, and here we place them together to minimize the time, it's held). Signed-off-by: Kirill Tkhai <ktkhai@xxxxxxxxxxxxx> --- mm/memcontrol.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 25b148c2d222..acabea274cc3 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4382,20 +4382,10 @@ static struct mem_cgroup *mem_cgroup_alloc(void) if (!memcg) return NULL; - memcg->id.id = idr_alloc(&mem_cgroup_idr, NULL, - 1, MEM_CGROUP_ID_MAX, - GFP_KERNEL); - if (memcg->id.id < 0) - goto fail; - memcg->stat_cpu = alloc_percpu(struct mem_cgroup_stat_cpu); if (!memcg->stat_cpu) goto fail; - for_each_node(node) - if (alloc_mem_cgroup_per_node_info(memcg, node)) - goto fail; - if (memcg_wb_domain_init(memcg, GFP_KERNEL)) goto fail; @@ -4414,7 +4404,16 @@ static struct mem_cgroup *mem_cgroup_alloc(void) #ifdef CONFIG_CGROUP_WRITEBACK INIT_LIST_HEAD(&memcg->cgwb_list); #endif - idr_replace(&mem_cgroup_idr, memcg, memcg->id.id); + for_each_node(node) + if (alloc_mem_cgroup_per_node_info(memcg, node)) + goto fail; + + memcg->id.id = idr_alloc(&mem_cgroup_idr, memcg, + 1, MEM_CGROUP_ID_MAX, + GFP_KERNEL); + if (memcg->id.id < 0) + goto fail; + return memcg; fail: mem_cgroup_id_remove(memcg);