mm: avoid anon_vma_chain allocation under anon_vma lock
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 18 Jun 2011 02:05:36 +0000 (19:05 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 18 Jun 2011 02:24:11 +0000 (19:24 -0700)
commitdd34739c03f2f9a79403d33419c2e61e11b4c403
tree74e4e43b78d54994e88aef7df96f0f8f4b080934
parenteee2acbae95555006307395d8a6c91452d62851d
mm: avoid anon_vma_chain allocation under anon_vma lock

Hugh Dickins points out that lockdep (correctly) spots a potential
deadlock on the anon_vma lock, because we now do a GFP_KERNEL allocation
of anon_vma_chain while doing anon_vma_clone().  The problem is that
page reclaim will want to take the anon_vma lock of any anonymous pages
that it will try to reclaim.

So re-organize the code in anon_vma_clone() slightly: first do just a
GFP_NOWAIT allocation, which will usually work fine.  But if that fails,
let's just drop the lock and re-do the allocation, now with GFP_KERNEL.

End result: not only do we avoid the locking problem, this also ends up
getting better concurrency in case the allocation does need to block.
Tim Chen reports that with all these anon_vma locking tweaks, we're now
almost back up to the spinlock performance.

Reported-and-tested-by: Hugh Dickins <hughd@google.com>
Tested-by: Tim Chen <tim.c.chen@linux.intel.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/rmap.c