From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx168.postini.com [74.125.245.168]) by kanga.kvack.org (Postfix) with SMTP id 1456A6B00BE for ; Tue, 18 Sep 2012 10:16:42 -0400 (EDT) From: Glauber Costa Subject: [PATCH v3 07/16] memcg: skip memcg kmem allocations in specified code regions Date: Tue, 18 Sep 2012 18:12:01 +0400 Message-Id: <1347977530-29755-8-git-send-email-glommer@parallels.com> In-Reply-To: <1347977530-29755-1-git-send-email-glommer@parallels.com> References: <1347977530-29755-1-git-send-email-glommer@parallels.com> Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org Cc: cgroups@vger.kernel.org, kamezawa.hiroyu@jp.fujitsu.com, devel@openvz.org, Tejun Heo , linux-mm@kvack.org, Suleiman Souhlal , Frederic Weisbecker , Mel Gorman , David Rientjes , Glauber Costa , Christoph Lameter , Pekka Enberg , Michal Hocko , Johannes Weiner This patch creates a mechanism that skip memcg allocations during certain pieces of our core code. It basically works in the same way as preempt_disable()/preempt_enable(): By marking a region under which all allocations will be accounted to the root memcg. We need this to prevent races in early cache creation, when we allocate data using caches that are not necessarily created already. Signed-off-by: Glauber Costa CC: Christoph Lameter CC: Pekka Enberg CC: Michal Hocko CC: Kamezawa Hiroyuki CC: Johannes Weiner CC: Suleiman Souhlal --- include/linux/sched.h | 1 + mm/memcontrol.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index 81967b1..4c983c6 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1574,6 +1574,7 @@ struct task_struct { unsigned long nr_pages; /* uncharged usage */ unsigned long memsw_nr_pages; /* uncharged mem+swap usage */ } memcg_batch; + unsigned int memcg_kmem_skip_account; #endif #ifdef CONFIG_HAVE_HW_BREAKPOINT atomic_t ptrace_bp_refcnt; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 1cce5c3..54247ec 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -544,6 +544,22 @@ static inline bool memcg_can_account_kmem(struct mem_cgroup *memcg) (memcg->kmem_accounted & (KMEM_ACCOUNTED_MASK)); } +static void memcg_stop_kmem_account(void) +{ + if (!current->mm) + return; + + current->memcg_kmem_skip_account++; +} + +static void memcg_resume_kmem_account(void) +{ + if (!current->mm) + return; + + current->memcg_kmem_skip_account--; +} + static char *memcg_cache_name(struct mem_cgroup *memcg, struct kmem_cache *cachep) { char *name; @@ -721,7 +737,9 @@ static struct kmem_cache *memcg_create_kmem_cache(struct mem_cgroup *memcg, if (new_cachep) goto out; + memcg_stop_kmem_account(); new_cachep = kmem_cache_dup(memcg, cachep); + memcg_resume_kmem_account(); if (new_cachep == NULL) { new_cachep = cachep; @@ -811,7 +829,9 @@ static void memcg_create_cache_enqueue(struct mem_cgroup *memcg, if (!css_tryget(&memcg->css)) return; + memcg_stop_kmem_account(); cw = kmalloc(sizeof(struct create_work), GFP_NOWAIT); + memcg_resume_kmem_account(); if (cw == NULL) { css_put(&memcg->css); return; @@ -846,6 +866,9 @@ struct kmem_cache *__memcg_kmem_get_cache(struct kmem_cache *cachep, int idx; struct task_struct *p; + if (!current->mm || current->memcg_kmem_skip_account) + return cachep; + if (cachep->memcg_params.memcg) return cachep; -- 1.7.11.4 -- 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: email@kvack.org