From 869bebf1714463b046599a700710023fc82836d7 Mon Sep 17 00:00:00 2001 From: Yi Tao Date: Thu, 7 Jan 2021 20:54:24 +0800 Subject: [PATCH 2531/2944] alinux: memcg: memcg: extract init from mem_cgroup_alloc to #31531504 To use cache for memcg, it is necessary to provide an init function. so extract init logic from mem_cgroup_alloc() Signed-off-by: Yi Tao Suggested-by: Shanpei Chen Acked-by: Xunlei Pang --- mm/memcontrol.c | 79 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 30 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 20ddc46..d8c68a4 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6121,6 +6121,54 @@ struct mem_cgroup *mem_cgroup_from_id(unsigned short id) return idr_find(&mem_cgroup_idr, id); } +static void mem_cgroup_per_node_info_init(struct mem_cgroup *memcg, int node) +{ + struct mem_cgroup_per_node *pn = memcg->nodeinfo[node]; + + lruvec_init(&pn->lruvec); + pn->usage_in_excess = 0; + pn->on_tree = false; + pn->memcg = memcg; + +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + spin_lock_init(&pn->deferred_split_queue.split_queue_lock); + INIT_LIST_HEAD(&pn->deferred_split_queue.split_queue); + pn->deferred_split_queue.split_queue_len = 0; +#endif +} + +static bool __mem_cgroup_init(struct mem_cgroup *memcg) +{ + int node; + + if (memcg_wb_domain_init(memcg, GFP_KERNEL)) + return false; + + for_each_node(node) + mem_cgroup_per_node_info_init(memcg, node); + + INIT_WORK(&memcg->high_work, high_work_func); + INIT_WORK(&memcg->wmark_work, wmark_work_func); + memcg->last_scanned_node = MAX_NUMNODES; + INIT_LIST_HEAD(&memcg->oom_notify); + mutex_init(&memcg->thresholds_lock); + spin_lock_init(&memcg->move_lock); + vmpressure_init(&memcg->vmpressure); + INIT_LIST_HEAD(&memcg->event_list); + spin_lock_init(&memcg->event_list_lock); + memcg->socket_pressure = jiffies; +#ifdef CONFIG_MEMCG_KMEM + memcg->kmemcg_id = -1; +#endif +#ifdef CONFIG_CGROUP_WRITEBACK + INIT_LIST_HEAD(&memcg->cgwb_list); +#endif + kidled_memcg_init(memcg); + idr_replace(&mem_cgroup_idr, memcg, memcg->id.id); + + return true; +} + static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node) { struct mem_cgroup_per_node *pn; @@ -6152,17 +6200,6 @@ static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node) return 1; } - lruvec_init(&pn->lruvec); - pn->usage_in_excess = 0; - pn->on_tree = false; - pn->memcg = memcg; - -#ifdef CONFIG_TRANSPARENT_HUGEPAGE - spin_lock_init(&pn->deferred_split_queue.split_queue_lock); - INIT_LIST_HEAD(&pn->deferred_split_queue.split_queue); - pn->deferred_split_queue.split_queue_len = 0; -#endif - memcg->nodeinfo[node] = pn; return 0; } @@ -6243,27 +6280,9 @@ static struct mem_cgroup *mem_cgroup_alloc(void) if (alloc_mem_cgroup_per_node_info(memcg, node)) goto fail; - if (memcg_wb_domain_init(memcg, GFP_KERNEL)) + if (!__mem_cgroup_init(memcg)) goto fail; - INIT_WORK(&memcg->high_work, high_work_func); - INIT_WORK(&memcg->wmark_work, wmark_work_func); - memcg->last_scanned_node = MAX_NUMNODES; - INIT_LIST_HEAD(&memcg->oom_notify); - mutex_init(&memcg->thresholds_lock); - spin_lock_init(&memcg->move_lock); - vmpressure_init(&memcg->vmpressure); - INIT_LIST_HEAD(&memcg->event_list); - spin_lock_init(&memcg->event_list_lock); - memcg->socket_pressure = jiffies; -#ifdef CONFIG_MEMCG_KMEM - memcg->kmemcg_id = -1; -#endif -#ifdef CONFIG_CGROUP_WRITEBACK - INIT_LIST_HEAD(&memcg->cgwb_list); -#endif - kidled_memcg_init(memcg); - idr_replace(&mem_cgroup_idr, memcg, memcg->id.id); return memcg; fail: mem_cgroup_id_remove(memcg); -- 1.8.3.1