]> git.hungrycats.org Git - linux/commitdiff
[PATCH] make can_do_mlock useful for mlock/mlockall
authorChris Wright <chrisw@osdl.org>
Fri, 1 Oct 2004 09:34:43 +0000 (02:34 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Fri, 1 Oct 2004 09:34:43 +0000 (02:34 -0700)
Move the simple can_do_mlock() check before the full rlimits based
restriction checks for mlock() and mlockall().  As it is, the check
adds nothing.  This has a side-effect of eliminating an unnecessary call
to can_do_mlock() on the munlockall() path.

Signed-off-by: Chris Wright <chrisw@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
mm/mlock.c

index 9ae544bf0f2c882e8049e9f5cfb5d0b86c105852..146224c5a2abe283cb94f45211827e6f231fdf9a 100644 (file)
@@ -60,8 +60,6 @@ static int do_mlock(unsigned long start, size_t len, int on)
        struct vm_area_struct * vma, * next;
        int error;
 
-       if (on && !can_do_mlock())
-               return -EPERM;
        len = PAGE_ALIGN(len);
        end = start + len;
        if (end < start)
@@ -107,6 +105,9 @@ asmlinkage long sys_mlock(unsigned long start, size_t len)
        unsigned long lock_limit;
        int error = -ENOMEM;
 
+       if (!can_do_mlock())
+               return -EPERM;
+
        down_write(&current->mm->mmap_sem);
        len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
        start &= PAGE_MASK;
@@ -138,13 +139,9 @@ asmlinkage long sys_munlock(unsigned long start, size_t len)
 
 static int do_mlockall(int flags)
 {
-       unsigned int def_flags;
        struct vm_area_struct * vma;
+       unsigned int def_flags = 0;
 
-       if (!can_do_mlock())
-               return -EPERM;
-
-       def_flags = 0;
        if (flags & MCL_FUTURE)
                def_flags = VM_LOCKED;
        current->mm->def_flags = def_flags;
@@ -174,6 +171,10 @@ asmlinkage long sys_mlockall(int flags)
        if (!flags || (flags & ~(MCL_CURRENT | MCL_FUTURE)))
                goto out;
 
+       ret = -EPERM;
+       if (!can_do_mlock())
+               goto out;
+
        lock_limit = current->rlim[RLIMIT_MEMLOCK].rlim_cur;
        lock_limit >>= PAGE_SHIFT;