From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
To: akpm@linux-foundation.org, mhocko@suse.cz,
kamezawa.hiroyu@jp.fujitsu.com, liwanp@linux.vnet.ibm.com,
htejun@gmail.com, lizefan@huawei.com, cgroups@vger.kernel.org,
linux-mm@kvack.org
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Subject: [PATCH] cgroup: Don't drop the cgroup_mutex in cgroup_rmdir
Date: Thu, 19 Jul 2012 19:39:32 +0530 [thread overview]
Message-ID: <1342706972-10912-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> (raw)
In-Reply-To: <87ipdjc15j.fsf@skywalker.in.ibm.com>
From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
We dropped cgroup mutex, because of a deadlock between memcg and cpuset.
cpuset took hotplug lock followed by cgroup_mutex, where as memcg pre_destroy
did lru_add_drain_all() which took hotplug lock while already holding
cgroup_mutex. The deadlock is explained in 3fa59dfbc3b223f02c26593be69ce6fc9a940405
But dropping cgroup_mutex in cgroup_rmdir also means tasks could get
added to cgroup while we are in pre_destroy. This makes error handling in
pre_destroy complex. So move the unlock/lock to memcg pre_destroy callback.
Core cgroup will now call pre_destroy with cgroup_mutex held.
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
kernel/cgroup.c | 3 +--
mm/memcontrol.c | 11 ++++++++++-
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 7981850..01c67f4 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -4151,7 +4151,6 @@ again:
mutex_unlock(&cgroup_mutex);
return -EBUSY;
}
- mutex_unlock(&cgroup_mutex);
/*
* In general, subsystem has no css->refcnt after pre_destroy(). But
@@ -4171,10 +4170,10 @@ again:
ret = cgroup_call_pre_destroy(cgrp);
if (ret) {
clear_bit(CGRP_WAIT_ON_RMDIR, &cgrp->flags);
+ mutex_unlock(&cgroup_mutex);
return ret;
}
- mutex_lock(&cgroup_mutex);
parent = cgrp->parent;
if (atomic_read(&cgrp->count) || !list_empty(&cgrp->children)) {
clear_bit(CGRP_WAIT_ON_RMDIR, &cgrp->flags);
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index e8ddc00..9bd56ee 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4993,9 +4993,18 @@ free_out:
static int mem_cgroup_pre_destroy(struct cgroup *cont)
{
+ int ret;
struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
- return mem_cgroup_force_empty(memcg, false);
+ cgroup_unlock();
+ /*
+ * we call lru_add_drain_all, which end up taking
+ * mutex_lock(&cpu_hotplug.lock), But cpuset have
+ * the reverse order. So drop the cgroup lock
+ */
+ ret = mem_cgroup_force_empty(memcg, false);
+ cgroup_lock();
+ return ret;
}
static void mem_cgroup_destroy(struct cgroup *cont)
--
1.7.10
--
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:[~2012-07-19 14:09 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20120718212637.133475C0050@hpza9.eem.corp.google.com>
2012-07-19 11:39 ` + hugetlb-cgroup-simplify-pre_destroy-callback.patch added to -mm tree Michal Hocko
2012-07-19 12:21 ` Aneesh Kumar K.V
2012-07-19 12:38 ` Michal Hocko
2012-07-19 13:48 ` Aneesh Kumar K.V
2012-07-19 14:09 ` Aneesh Kumar K.V [this message]
2012-07-19 16:50 ` [PATCH] cgroup: Don't drop the cgroup_mutex in cgroup_rmdir Tejun Heo
2012-07-20 15:45 ` Peter Zijlstra
2012-07-20 20:05 ` Tejun Heo
2012-07-20 22:07 ` Glauber Costa
2012-07-27 6:15 ` Li Zefan
2012-07-30 18:25 ` Tejun Heo
2012-07-20 7:51 ` Michal Hocko
2012-07-20 19:49 ` Tejun Heo
2012-07-20 1:05 ` + hugetlb-cgroup-simplify-pre_destroy-callback.patch added to -mm tree Kamezawa Hiroyuki
2012-07-20 1:20 ` Kamezawa Hiroyuki
2012-07-20 8:01 ` Michal Hocko
2012-07-20 8:08 ` Kamezawa Hiroyuki
2012-07-20 8:06 ` Michal Hocko
2012-07-20 19:18 ` Aneesh Kumar K.V
2012-07-20 19:56 ` Tejun Heo
2012-07-21 2:14 ` Kamezawa Hiroyuki
2012-07-21 2:46 ` Tejun Heo
2012-07-21 4:05 ` Kamezawa Hiroyuki
2012-07-22 17:34 ` Tejun Heo
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=1342706972-10912-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com \
--to=aneesh.kumar@linux.vnet.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=htejun@gmail.com \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-mm@kvack.org \
--cc=liwanp@linux.vnet.ibm.com \
--cc=lizefan@huawei.com \
--cc=mhocko@suse.cz \
/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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).