Skip to content

mlock: do not hold mmap_sem for extended periods of time

Michel Lespinasse linux-mm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest6 patches 15 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6mlock: only hold mmap_sem in shared mode when faulting in pagesmm/mlock.c+58 -1710 replies
2/6mm: add FOLL_MLOCK follow_page flag.include/linux/mm.h mm/memory.c mm/mlock.c+32 -611 reply
3/6mm: move VM_LOCKED check to __mlock_vma_pages_range()mm/mlock.c+9 -90 replies
4/6rwsem: implement rwsem_is_contended()arch/alpha/include/asm/rwsem.h arch/ia64/include/asm/rwsem.h arch/powerpc/include/asm/rwsem.h +7 more+53 -00 replies
5/6mlock: do not hold mmap_sem for extended periods of timemm/internal.h mm/memory.c mm/mlock.c +1 more+47 -211 reply
6/6x86 rwsem: more precise rwsem_is_contended() implementationarch/x86/include/asm/rwsem.h arch/x86/lib/rwsem_64.S arch/x86/lib/semaphore_32.S+23 -172 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/6] mlock: do not hold mmap_sem for extended periods of time

Currently mlock() holds mmap_sem in exclusive mode while the pages get faulted in. In the case of a large mlock, this can potentially take a very long time, during which various commands such as 'ps auxw' will block. This makes sysadmins unhappy:

real    14m36.232s
user    0m0.003s
sys     0m0.015s

(output from 'time ps auxw' while a 20GB file was being mlocked without being previously preloaded into page cache)

I propose that mlock() could release mmap_sem after the VM_LOCKED bits have been set in all appropriate VMAs. Then a second pass could be done to actually mlock the pages, in small batches, releasing mmap_sem when we block on disk access or when we detect some contention.

Patches are against v2.6.37-rc4 plus my patches to avoid mlock dirtying (presently queued in -mm).

Michel Lespinasse (6):
mlock: only hold mmap_sem in shared mode when faulting in pages
mm: add FOLL_MLOCK follow_page flag.
mm: move VM_LOCKED check to __mlock_vma_pages_range()
rwsem: implement rwsem_is_contended()
mlock: do not hold mmap_sem for extended periods of time x86 rwsem: more precise rwsem_is_contended() implementation

 arch/alpha/include/asm/rwsem.h   |    5 +
 arch/ia64/include/asm/rwsem.h    |    5 +
 arch/powerpc/include/asm/rwsem.h |    5 +
 arch/s390/include/asm/rwsem.h    |    5 +
 arch/sh/include/asm/rwsem.h      |    5 +
 arch/sparc/include/asm/rwsem.h   |    5 +
 arch/x86/include/asm/rwsem.h     |   35 ++++++---
 arch/x86/lib/rwsem_64.S          |    4 +-
 arch/x86/lib/semaphore_32.S      |    4 +-
 arch/xtensa/include/asm/rwsem.h  |    5 +
 include/linux/mm.h               |    1 +
 include/linux/rwsem-spinlock.h   |    1 +
 lib/rwsem-spinlock.c             |   12 +++
 mm/internal.h                    |    3 +-
 mm/memory.c                      |   54 ++++++++++++--
 mm/mlock.c                       |  150 ++++++++++++++++++--------------------
 mm/nommu.c                       |    6 +-
 17 files changed, 201 insertions(+), 104 deletions(-)
Signature · 8 lines
1.7.3.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>