cgroup: fix potential deadlock in pre_destroy
authorKAMEZAWA Hiroyuki <[email protected]>
Wed, 19 Nov 2008 23:36:34 +0000 (15:36 -0800)
committerLinus Torvalds <[email protected]>
Thu, 20 Nov 2008 02:49:58 +0000 (18:49 -0800)
commit3fa59dfbc3b223f02c26593be69ce6fc9a940405
treed3d9df521342b49abc636e1ee465b704858b3e0d
parent0ae15132a4f5c758a6ffcde74495641dc3f62ba1
cgroup: fix potential deadlock in pre_destroy

As Balbir pointed out, memcg's pre_destroy handler has potential deadlock.

It has following lock sequence.

cgroup_mutex (cgroup_rmdir)
    -> pre_destroy -> mem_cgroup_pre_destroy-> force_empty
-> cpu_hotplug.lock. (lru_add_drain_all->
      schedule_work->
                                      get_online_cpus)

But, cpuset has following.
cpu_hotplug.lock (call notifier)
-> cgroup_mutex. (within notifier)

Then, this lock sequence should be fixed.

Considering how pre_destroy works, it's not necessary to holding
cgroup_mutex() while calling it.

As a side effect, we don't have to wait at this mutex while memcg's
force_empty works.(it can be long when there are tons of pages.)

Signed-off-by: KAMEZAWA Hiroyuki <[email protected]>
Acked-by: Balbir Singh <[email protected]>
Cc: Li Zefan <[email protected]>
Cc: Paul Menage <[email protected]>
Cc: Daisuke Nishimura <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
kernel/cgroup.c