aboutsummaryrefslogtreecommitdiffstats
path: root/mm/mlock.c
diff options
context:
space:
mode:
authorMichel Lespinasse <walken@google.com>2013-02-22 19:32:37 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-23 20:50:10 -0500
commitbebeb3d68b24bb4132d452c5707fe321208bcbcd (patch)
tree6e609cb7323fb1b4b7026fa0e35867145a181094 /mm/mlock.c
parent940e7da5163029978c2f6b5bbe213607add59062 (diff)
mm: introduce mm_populate() for populating new vmas
When creating new mappings using the MAP_POPULATE / MAP_LOCKED flags (or with MCL_FUTURE in effect), we want to populate the pages within the newly created vmas. This may take a while as we may have to read pages from disk, so ideally we want to do this outside of the write-locked mmap_sem region. This change introduces mm_populate(), which is used to defer populating such mappings until after the mmap_sem write lock has been released. This is implemented as a generalization of the former do_mlock_pages(), which accomplished the same task but was using during mlock() / mlockall(). Signed-off-by: Michel Lespinasse <walken@google.com> Reported-by: Andy Lutomirski <luto@amacapital.net> Acked-by: Rik van Riel <riel@redhat.com> Tested-by: Andy Lutomirski <luto@amacapital.net> Cc: Greg Ungerer <gregungerer@westnet.com.au> Cc: David Howells <dhowells@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/mlock.c')
-rw-r--r--mm/mlock.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/mm/mlock.c b/mm/mlock.c
index c9bd528b01d2..a296a49865df 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -416,7 +416,14 @@ static int do_mlock(unsigned long start, size_t len, int on)
416 return error; 416 return error;
417} 417}
418 418
419static int do_mlock_pages(unsigned long start, size_t len, int ignore_errors) 419/*
420 * __mm_populate - populate and/or mlock pages within a range of address space.
421 *
422 * This is used to implement mlock() and the MAP_POPULATE / MAP_LOCKED mmap
423 * flags. VMAs must be already marked with the desired vm_flags, and
424 * mmap_sem must not be held.
425 */
426int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)
420{ 427{
421 struct mm_struct *mm = current->mm; 428 struct mm_struct *mm = current->mm;
422 unsigned long end, nstart, nend; 429 unsigned long end, nstart, nend;
@@ -498,7 +505,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
498 error = do_mlock(start, len, 1); 505 error = do_mlock(start, len, 1);
499 up_write(&current->mm->mmap_sem); 506 up_write(&current->mm->mmap_sem);
500 if (!error) 507 if (!error)
501 error = do_mlock_pages(start, len, 0); 508 error = __mm_populate(start, len, 0);
502 return error; 509 return error;
503} 510}
504 511
@@ -564,10 +571,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
564 capable(CAP_IPC_LOCK)) 571 capable(CAP_IPC_LOCK))
565 ret = do_mlockall(flags); 572 ret = do_mlockall(flags);
566 up_write(&current->mm->mmap_sem); 573 up_write(&current->mm->mmap_sem);
567 if (!ret && (flags & MCL_CURRENT)) { 574 if (!ret && (flags & MCL_CURRENT))
568 /* Ignore errors */ 575 mm_populate(0, TASK_SIZE);
569 do_mlock_pages(0, TASK_SIZE, 1);
570 }
571out: 576out:
572 return ret; 577 return ret;
573} 578}