Revision 7906d00cd1f687268f0a3599442d113767795ae6 authored by Andrea Arcangeli on 28 July 2008, 22:46:26 UTC, committed by Linus Torvalds on 28 July 2008, 23:30:21 UTC
mm_take_all_locks holds off reclaim from an entire mm_struct.  This allows
mmu notifiers to register into the mm at any time with the guarantee that
no mmu operation is in progress on the mm.

This operation locks against the VM for all pte/vma/mm related operations
that could ever happen on a certain mm.  This includes vmtruncate,
try_to_unmap, and all page faults.

The caller must take the mmap_sem in write mode before calling
mm_take_all_locks().  The caller isn't allowed to release the mmap_sem
until mm_drop_all_locks() returns.

mmap_sem in write mode is required in order to block all operations that
could modify pagetables and free pages without need of altering the vma
layout (for example populate_range() with nonlinear vmas).  It's also
needed in write mode to avoid new anon_vmas to be associated with existing
vmas.

A single task can't take more than one mm_take_all_locks() in a row or it
would deadlock.

mm_take_all_locks() and mm_drop_all_locks are expensive operations that
may have to take thousand of locks.

mm_take_all_locks() can fail if it's interrupted by signals.

When mmu_notifier_register returns, we must be sure that the driver is
notified if some task is in the middle of a vmtruncate for the 'mm' where
the mmu notifier was registered (mmu_notifier_invalidate_range_start/end
is run around the vmtruncation but mmu_notifier_register can run after
mmu_notifier_invalidate_range_start and before
mmu_notifier_invalidate_range_end).  Same problem for rmap paths.  And
we've to remove page pinning to avoid replicating the tlb_gather logic
inside KVM (and GRU doesn't work well with page pinning regardless of
needing tlb_gather), so without mm_take_all_locks when vmtruncate frees
the page, kvm would have no way to notice that it mapped into sptes a page
that is going into the freelist without a chance of any further
mmu_notifier notification.

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Andrea Arcangeli <andrea@qumranet.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Christoph Lameter <cl@linux-foundation.org>
Cc: Jack Steiner <steiner@sgi.com>
Cc: Robin Holt <holt@sgi.com>
Cc: Nick Piggin <npiggin@suse.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Kanoj Sarcar <kanojsarcar@yahoo.com>
Cc: Roland Dreier <rdreier@cisco.com>
Cc: Steve Wise <swise@opengridcomputing.com>
Cc: Avi Kivity <avi@qumranet.com>
Cc: Hugh Dickins <hugh@veritas.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Anthony Liguori <aliguori@us.ibm.com>
Cc: Chris Wright <chrisw@redhat.com>
Cc: Marcelo Tosatti <marcelo@kvack.org>
Cc: Eric Dumazet <dada1@cosmosbay.com>
Cc: "Paul E. McKenney" <paulmck@us.ibm.com>
Cc: Izik Eidus <izike@qumranet.com>
Cc: Anthony Liguori <aliguori@us.ibm.com>
Cc: Rik van Riel <riel@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 6beeac7
History
File Mode Size
9p
adfs
affs
afs
autofs
autofs4
befs
bfs
cifs
coda
configfs
cramfs
debugfs
devpts
dlm
ecryptfs
efs
exportfs
ext2
ext3
ext4
fat
freevxfs
fuse
gfs2
hfs
hfsplus
hostfs
hpfs
hppfs
hugetlbfs
isofs
jbd
jbd2
jffs2
jfs
lockd
minix
msdos
ncpfs
nfs
nfs_common
nfsd
nls
ntfs
ocfs2
omfs
openpromfs
partitions
proc
qnx4
ramfs
reiserfs
romfs
smbfs
sysfs
sysv
ubifs
udf
ufs
vfat
xfs
Kconfig -rw-r--r-- 73.9 KB
Kconfig.binfmt -rw-r--r-- 5.4 KB
Makefile -rw-r--r-- 3.9 KB
aio.c -rw-r--r-- 45.9 KB
anon_inodes.c -rw-r--r-- 4.9 KB
attr.c -rw-r--r-- 4.8 KB
bad_inode.c -rw-r--r-- 8.0 KB
binfmt_aout.c -rw-r--r-- 14.7 KB
binfmt_elf.c -rw-r--r-- 53.7 KB
binfmt_elf_fdpic.c -rw-r--r-- 47.4 KB
binfmt_em86.c -rw-r--r-- 2.8 KB
binfmt_flat.c -rw-r--r-- 26.5 KB
binfmt_misc.c -rw-r--r-- 15.1 KB
binfmt_script.c -rw-r--r-- 2.7 KB
binfmt_som.c -rw-r--r-- 7.5 KB
bio-integrity.c -rw-r--r-- 19.4 KB
bio.c -rw-r--r-- 31.9 KB
block_dev.c -rw-r--r-- 30.6 KB
buffer.c -rw-r--r-- 86.8 KB
char_dev.c -rw-r--r-- 13.2 KB
compat.c -rw-r--r-- 53.2 KB
compat_binfmt_elf.c -rw-r--r-- 3.4 KB
compat_ioctl.c -rw-r--r-- 81.0 KB
dcache.c -rw-r--r-- 56.9 KB
dcookies.c -rw-r--r-- 6.3 KB
direct-io.c -rw-r--r-- 34.0 KB
dnotify.c -rw-r--r-- 4.6 KB
dquot.c -rw-r--r-- 62.0 KB
drop_caches.c -rw-r--r-- 1.6 KB
eventfd.c -rw-r--r-- 5.3 KB
eventpoll.c -rw-r--r-- 36.1 KB
exec.c -rw-r--r-- 42.1 KB
fcntl.c -rw-r--r-- 14.2 KB
fifo.c -rw-r--r-- 3.2 KB
file.c -rw-r--r-- 10.9 KB
file_table.c -rw-r--r-- 9.8 KB
filesystems.c -rw-r--r-- 5.5 KB
fs-writeback.c -rw-r--r-- 22.4 KB
generic_acl.c -rw-r--r-- 4.2 KB
inode.c -rw-r--r-- 37.6 KB
inotify.c -rw-r--r-- 20.2 KB
inotify_user.c -rw-r--r-- 18.6 KB
internal.h -rw-r--r-- 1.4 KB
ioctl.c -rw-r--r-- 4.5 KB
ioprio.c -rw-r--r-- 5.0 KB
libfs.c -rw-r--r-- 21.0 KB
locks.c -rw-r--r-- 57.2 KB
mbcache.c -rw-r--r-- 18.3 KB
mpage.c -rw-r--r-- 19.8 KB
namei.c -rw-r--r-- 69.9 KB
namespace.c -rw-r--r-- 58.5 KB
nfsctl.c -rw-r--r-- 2.4 KB
no-block.c -rw-r--r-- 663 bytes
open.c -rw-r--r-- 27.4 KB
pipe.c -rw-r--r-- 24.2 KB
pnode.c -rw-r--r-- 8.9 KB
pnode.h -rw-r--r-- 1.1 KB
posix_acl.c -rw-r--r-- 8.5 KB
quota.c -rw-r--r-- 12.2 KB
quota_v1.c -rw-r--r-- 5.9 KB
quota_v2.c -rw-r--r-- 20.2 KB
read_write.c -rw-r--r-- 17.4 KB
read_write.h -rw-r--r-- 542 bytes
readdir.c -rw-r--r-- 6.8 KB
select.c -rw-r--r-- 20.8 KB
seq_file.c -rw-r--r-- 12.2 KB
signalfd.c -rw-r--r-- 7.1 KB
splice.c -rw-r--r-- 38.8 KB
stack.c -rw-r--r-- 1.1 KB
stat.c -rw-r--r-- 10.6 KB
super.c -rw-r--r-- 22.8 KB
sync.c -rw-r--r-- 7.1 KB
timerfd.c -rw-r--r-- 6.8 KB
utimes.c -rw-r--r-- 5.6 KB
xattr.c -rw-r--r-- 15.0 KB
xattr_acl.c -rw-r--r-- 2.3 KB

back to top