From: Johannes Weiner <hannes@cmpxchg.org> To: Andrew Morton <akpm@linux-foundation.org> Cc: Michal Hocko <mhocko@suse.cz>, Vladimir Davydov <vdavydov@virtuozzo.com>, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 4/8] mm: memcontrol: group kmem init and exit functions together Date: Tue, 8 Dec 2015 13:34:21 -0500 [thread overview] Message-ID: <1449599665-18047-5-git-send-email-hannes@cmpxchg.org> (raw) In-Reply-To: <1449599665-18047-1-git-send-email-hannes@cmpxchg.org> Put all the related code to setup and teardown the kmem accounting state into the same location. No functional change intended. Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> --- mm/memcontrol.c | 157 +++++++++++++++++++++++++++----------------------------- 1 file changed, 76 insertions(+), 81 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 22b8c4f..5118618 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2924,12 +2924,88 @@ static int memcg_propagate_kmem(struct mem_cgroup *memcg) mutex_unlock(&memcg_limit_mutex); return ret; } + +static int memcg_init_kmem(struct mem_cgroup *memcg) +{ + int ret; + + ret = memcg_propagate_kmem(memcg); + if (ret) + return ret; + + return tcp_init_cgroup(memcg); +} + +static void memcg_offline_kmem(struct mem_cgroup *memcg) +{ + struct cgroup_subsys_state *css; + struct mem_cgroup *parent, *child; + int kmemcg_id; + + if (memcg->kmem_state != KMEM_ONLINE) + return; + /* + * Clear the online state before clearing memcg_caches array + * entries. The slab_mutex in memcg_deactivate_kmem_caches() + * guarantees that no cache will be created for this cgroup + * after we are done (see memcg_create_kmem_cache()). + */ + memcg->kmem_state = KMEM_ALLOCATED; + + memcg_deactivate_kmem_caches(memcg); + + kmemcg_id = memcg->kmemcg_id; + BUG_ON(kmemcg_id < 0); + + parent = parent_mem_cgroup(memcg); + if (!parent) + parent = root_mem_cgroup; + + /* + * Change kmemcg_id of this cgroup and all its descendants to the + * parent's id, and then move all entries from this cgroup's list_lrus + * to ones of the parent. After we have finished, all list_lrus + * corresponding to this cgroup are guaranteed to remain empty. The + * ordering is imposed by list_lru_node->lock taken by + * memcg_drain_all_list_lrus(). + */ + css_for_each_descendant_pre(css, &memcg->css) { + child = mem_cgroup_from_css(css); + BUG_ON(child->kmemcg_id != kmemcg_id); + child->kmemcg_id = parent->kmemcg_id; + if (!memcg->use_hierarchy) + break; + } + memcg_drain_all_list_lrus(kmemcg_id, parent->kmemcg_id); + + memcg_free_cache_id(kmemcg_id); +} + +static void memcg_free_kmem(struct mem_cgroup *memcg) +{ + if (memcg->kmem_state == KMEM_ALLOCATED) { + memcg_destroy_kmem_caches(memcg); + static_branch_dec(&memcg_kmem_enabled_key); + WARN_ON(page_counter_read(&memcg->kmem)); + } + tcp_destroy_cgroup(memcg); +} #else static int memcg_update_kmem_limit(struct mem_cgroup *memcg, unsigned long limit) { return -EINVAL; } +static int memcg_init_kmem(struct mem_cgroup *memcg) +{ + return 0; +} +static void memcg_offline_kmem(struct mem_cgroup *memcg) +{ +} +static void memcg_free_kmem(struct mem_cgroup *memcg) +{ +} #endif /* CONFIG_MEMCG_KMEM */ /* @@ -3555,87 +3631,6 @@ static int mem_cgroup_oom_control_write(struct cgroup_subsys_state *css, return 0; } -#ifdef CONFIG_MEMCG_KMEM -static int memcg_init_kmem(struct mem_cgroup *memcg) -{ - int ret; - - ret = memcg_propagate_kmem(memcg); - if (ret) - return ret; - - return tcp_init_cgroup(memcg); -} - -static void memcg_offline_kmem(struct mem_cgroup *memcg) -{ - struct cgroup_subsys_state *css; - struct mem_cgroup *parent, *child; - int kmemcg_id; - - if (memcg->kmem_state != KMEM_ONLINE) - return; - /* - * Clear the online state before clearing memcg_caches array - * entries. The slab_mutex in memcg_deactivate_kmem_caches() - * guarantees that no cache will be created for this cgroup - * after we are done (see memcg_create_kmem_cache()). - */ - memcg->kmem_state = KMEM_ALLOCATED; - - memcg_deactivate_kmem_caches(memcg); - - kmemcg_id = memcg->kmemcg_id; - BUG_ON(kmemcg_id < 0); - - parent = parent_mem_cgroup(memcg); - if (!parent) - parent = root_mem_cgroup; - - /* - * Change kmemcg_id of this cgroup and all its descendants to the - * parent's id, and then move all entries from this cgroup's list_lrus - * to ones of the parent. After we have finished, all list_lrus - * corresponding to this cgroup are guaranteed to remain empty. The - * ordering is imposed by list_lru_node->lock taken by - * memcg_drain_all_list_lrus(). - */ - css_for_each_descendant_pre(css, &memcg->css) { - child = mem_cgroup_from_css(css); - BUG_ON(child->kmemcg_id != kmemcg_id); - child->kmemcg_id = parent->kmemcg_id; - if (!memcg->use_hierarchy) - break; - } - memcg_drain_all_list_lrus(kmemcg_id, parent->kmemcg_id); - - memcg_free_cache_id(kmemcg_id); -} - -static void memcg_free_kmem(struct mem_cgroup *memcg) -{ - if (memcg->kmem_state == KMEM_ALLOCATED) { - memcg_destroy_kmem_caches(memcg); - static_branch_dec(&memcg_kmem_enabled_key); - WARN_ON(page_counter_read(&memcg->kmem)); - } - tcp_destroy_cgroup(memcg); -} -#else -static int memcg_init_kmem(struct mem_cgroup *memcg, struct cgroup_subsys *ss) -{ - return 0; -} - -static void memcg_offline_kmem(struct mem_cgroup *memcg) -{ -} - -static void memcg_free_kmem(struct mem_cgroup *memcg) -{ -} -#endif - #ifdef CONFIG_CGROUP_WRITEBACK struct list_head *mem_cgroup_cgwb_list(struct mem_cgroup *memcg) -- 2.6.3
WARNING: multiple messages have this Message-ID (diff)
From: Johannes Weiner <hannes@cmpxchg.org> To: Andrew Morton <akpm@linux-foundation.org> Cc: Michal Hocko <mhocko@suse.cz>, Vladimir Davydov <vdavydov@virtuozzo.com>, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 4/8] mm: memcontrol: group kmem init and exit functions together Date: Tue, 8 Dec 2015 13:34:21 -0500 [thread overview] Message-ID: <1449599665-18047-5-git-send-email-hannes@cmpxchg.org> (raw) In-Reply-To: <1449599665-18047-1-git-send-email-hannes@cmpxchg.org> Put all the related code to setup and teardown the kmem accounting state into the same location. No functional change intended. Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> --- mm/memcontrol.c | 157 +++++++++++++++++++++++++++----------------------------- 1 file changed, 76 insertions(+), 81 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 22b8c4f..5118618 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2924,12 +2924,88 @@ static int memcg_propagate_kmem(struct mem_cgroup *memcg) mutex_unlock(&memcg_limit_mutex); return ret; } + +static int memcg_init_kmem(struct mem_cgroup *memcg) +{ + int ret; + + ret = memcg_propagate_kmem(memcg); + if (ret) + return ret; + + return tcp_init_cgroup(memcg); +} + +static void memcg_offline_kmem(struct mem_cgroup *memcg) +{ + struct cgroup_subsys_state *css; + struct mem_cgroup *parent, *child; + int kmemcg_id; + + if (memcg->kmem_state != KMEM_ONLINE) + return; + /* + * Clear the online state before clearing memcg_caches array + * entries. The slab_mutex in memcg_deactivate_kmem_caches() + * guarantees that no cache will be created for this cgroup + * after we are done (see memcg_create_kmem_cache()). + */ + memcg->kmem_state = KMEM_ALLOCATED; + + memcg_deactivate_kmem_caches(memcg); + + kmemcg_id = memcg->kmemcg_id; + BUG_ON(kmemcg_id < 0); + + parent = parent_mem_cgroup(memcg); + if (!parent) + parent = root_mem_cgroup; + + /* + * Change kmemcg_id of this cgroup and all its descendants to the + * parent's id, and then move all entries from this cgroup's list_lrus + * to ones of the parent. After we have finished, all list_lrus + * corresponding to this cgroup are guaranteed to remain empty. The + * ordering is imposed by list_lru_node->lock taken by + * memcg_drain_all_list_lrus(). + */ + css_for_each_descendant_pre(css, &memcg->css) { + child = mem_cgroup_from_css(css); + BUG_ON(child->kmemcg_id != kmemcg_id); + child->kmemcg_id = parent->kmemcg_id; + if (!memcg->use_hierarchy) + break; + } + memcg_drain_all_list_lrus(kmemcg_id, parent->kmemcg_id); + + memcg_free_cache_id(kmemcg_id); +} + +static void memcg_free_kmem(struct mem_cgroup *memcg) +{ + if (memcg->kmem_state == KMEM_ALLOCATED) { + memcg_destroy_kmem_caches(memcg); + static_branch_dec(&memcg_kmem_enabled_key); + WARN_ON(page_counter_read(&memcg->kmem)); + } + tcp_destroy_cgroup(memcg); +} #else static int memcg_update_kmem_limit(struct mem_cgroup *memcg, unsigned long limit) { return -EINVAL; } +static int memcg_init_kmem(struct mem_cgroup *memcg) +{ + return 0; +} +static void memcg_offline_kmem(struct mem_cgroup *memcg) +{ +} +static void memcg_free_kmem(struct mem_cgroup *memcg) +{ +} #endif /* CONFIG_MEMCG_KMEM */ /* @@ -3555,87 +3631,6 @@ static int mem_cgroup_oom_control_write(struct cgroup_subsys_state *css, return 0; } -#ifdef CONFIG_MEMCG_KMEM -static int memcg_init_kmem(struct mem_cgroup *memcg) -{ - int ret; - - ret = memcg_propagate_kmem(memcg); - if (ret) - return ret; - - return tcp_init_cgroup(memcg); -} - -static void memcg_offline_kmem(struct mem_cgroup *memcg) -{ - struct cgroup_subsys_state *css; - struct mem_cgroup *parent, *child; - int kmemcg_id; - - if (memcg->kmem_state != KMEM_ONLINE) - return; - /* - * Clear the online state before clearing memcg_caches array - * entries. The slab_mutex in memcg_deactivate_kmem_caches() - * guarantees that no cache will be created for this cgroup - * after we are done (see memcg_create_kmem_cache()). - */ - memcg->kmem_state = KMEM_ALLOCATED; - - memcg_deactivate_kmem_caches(memcg); - - kmemcg_id = memcg->kmemcg_id; - BUG_ON(kmemcg_id < 0); - - parent = parent_mem_cgroup(memcg); - if (!parent) - parent = root_mem_cgroup; - - /* - * Change kmemcg_id of this cgroup and all its descendants to the - * parent's id, and then move all entries from this cgroup's list_lrus - * to ones of the parent. After we have finished, all list_lrus - * corresponding to this cgroup are guaranteed to remain empty. The - * ordering is imposed by list_lru_node->lock taken by - * memcg_drain_all_list_lrus(). - */ - css_for_each_descendant_pre(css, &memcg->css) { - child = mem_cgroup_from_css(css); - BUG_ON(child->kmemcg_id != kmemcg_id); - child->kmemcg_id = parent->kmemcg_id; - if (!memcg->use_hierarchy) - break; - } - memcg_drain_all_list_lrus(kmemcg_id, parent->kmemcg_id); - - memcg_free_cache_id(kmemcg_id); -} - -static void memcg_free_kmem(struct mem_cgroup *memcg) -{ - if (memcg->kmem_state == KMEM_ALLOCATED) { - memcg_destroy_kmem_caches(memcg); - static_branch_dec(&memcg_kmem_enabled_key); - WARN_ON(page_counter_read(&memcg->kmem)); - } - tcp_destroy_cgroup(memcg); -} -#else -static int memcg_init_kmem(struct mem_cgroup *memcg, struct cgroup_subsys *ss) -{ - return 0; -} - -static void memcg_offline_kmem(struct mem_cgroup *memcg) -{ -} - -static void memcg_free_kmem(struct mem_cgroup *memcg) -{ -} -#endif - #ifdef CONFIG_CGROUP_WRITEBACK struct list_head *mem_cgroup_cgwb_list(struct mem_cgroup *memcg) -- 2.6.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2015-12-08 18:36 UTC|newest] Thread overview: 79+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-12-08 18:34 [PATCH 0/8] mm: memcontrol: account "kmem" in cgroup2 Johannes Weiner 2015-12-08 18:34 ` Johannes Weiner 2015-12-08 18:34 ` Johannes Weiner 2015-12-08 18:34 ` [PATCH 1/8] mm: memcontrol: drop unused @css argument in memcg_init_kmem Johannes Weiner 2015-12-08 18:34 ` Johannes Weiner 2015-12-09 9:01 ` Vladimir Davydov 2015-12-09 9:01 ` Vladimir Davydov 2015-12-09 9:01 ` Vladimir Davydov 2015-12-10 12:37 ` Michal Hocko 2015-12-10 12:37 ` Michal Hocko 2015-12-10 12:37 ` Michal Hocko 2015-12-08 18:34 ` [PATCH 2/8] mm: memcontrol: remove double kmem page_counter init Johannes Weiner 2015-12-08 18:34 ` Johannes Weiner 2015-12-09 9:05 ` Vladimir Davydov 2015-12-09 9:05 ` Vladimir Davydov 2015-12-10 12:40 ` Michal Hocko 2015-12-10 12:40 ` Michal Hocko 2015-12-10 12:40 ` Michal Hocko 2015-12-08 18:34 ` [PATCH 3/8] mm: memcontrol: give the kmem states more descriptive names Johannes Weiner 2015-12-08 18:34 ` Johannes Weiner 2015-12-09 9:10 ` Vladimir Davydov 2015-12-09 9:10 ` Vladimir Davydov 2015-12-09 9:10 ` Vladimir Davydov 2015-12-10 12:47 ` Michal Hocko 2015-12-10 12:47 ` Michal Hocko 2015-12-08 18:34 ` Johannes Weiner [this message] 2015-12-08 18:34 ` [PATCH 4/8] mm: memcontrol: group kmem init and exit functions together Johannes Weiner 2015-12-09 9:14 ` Vladimir Davydov 2015-12-09 9:14 ` Vladimir Davydov 2015-12-09 9:14 ` Vladimir Davydov 2015-12-10 12:56 ` Michal Hocko 2015-12-10 12:56 ` Michal Hocko 2015-12-08 18:34 ` [PATCH 5/8] mm: memcontrol: separate kmem code from legacy tcp accounting code Johannes Weiner 2015-12-08 18:34 ` Johannes Weiner 2015-12-09 9:23 ` Vladimir Davydov 2015-12-09 9:23 ` Vladimir Davydov 2015-12-09 9:23 ` Vladimir Davydov 2015-12-10 12:59 ` Michal Hocko 2015-12-10 12:59 ` Michal Hocko 2015-12-10 12:59 ` Michal Hocko 2015-12-08 18:34 ` [PATCH 6/8] mm: memcontrol: move kmem accounting code to CONFIG_MEMCG Johannes Weiner 2015-12-08 18:34 ` Johannes Weiner 2015-12-09 9:32 ` Vladimir Davydov 2015-12-09 9:32 ` Vladimir Davydov 2015-12-09 9:32 ` Vladimir Davydov 2015-12-10 13:17 ` Michal Hocko 2015-12-10 13:17 ` Michal Hocko 2015-12-10 14:00 ` Johannes Weiner 2015-12-10 14:00 ` Johannes Weiner 2015-12-10 14:00 ` Johannes Weiner 2015-12-10 20:22 ` [PATCH 6/8 v2] " Johannes Weiner 2015-12-10 20:22 ` Johannes Weiner 2015-12-10 20:22 ` Johannes Weiner 2015-12-10 20:50 ` Johannes Weiner 2015-12-10 20:50 ` Johannes Weiner 2015-12-10 20:50 ` Johannes Weiner 2015-12-08 18:34 ` [PATCH 7/8] mm: memcontrol: account "kmem" consumers in cgroup2 memory controller Johannes Weiner 2015-12-08 18:34 ` Johannes Weiner 2015-12-09 11:30 ` Vladimir Davydov 2015-12-09 11:30 ` Vladimir Davydov 2015-12-09 11:30 ` Vladimir Davydov 2015-12-09 14:32 ` Johannes Weiner 2015-12-09 14:32 ` Johannes Weiner 2015-12-09 14:32 ` Johannes Weiner 2015-12-10 13:28 ` Michal Hocko 2015-12-10 13:28 ` Michal Hocko 2015-12-10 13:28 ` Michal Hocko 2015-12-10 15:16 ` Johannes Weiner 2015-12-10 15:16 ` Johannes Weiner 2015-12-10 16:25 ` Michal Hocko 2015-12-10 16:25 ` Michal Hocko 2015-12-10 16:25 ` Michal Hocko 2015-12-10 14:21 ` Michal Hocko 2015-12-10 14:21 ` Michal Hocko 2015-12-08 18:34 ` [PATCH 8/8] mm: memcontrol: introduce CONFIG_MEMCG_LEGACY_KMEM Johannes Weiner 2015-12-08 18:34 ` Johannes Weiner 2015-12-09 11:31 ` Vladimir Davydov 2015-12-09 11:31 ` Vladimir Davydov 2015-12-09 11:31 ` Vladimir Davydov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1449599665-18047-5-git-send-email-hannes@cmpxchg.org \ --to=hannes@cmpxchg.org \ --cc=akpm@linux-foundation.org \ --cc=cgroups@vger.kernel.org \ --cc=kernel-team@fb.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=mhocko@suse.cz \ --cc=vdavydov@virtuozzo.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.