Commit ead942ce authored by Chris Wright's avatar Chris Wright Committed by Linus Torvalds

[PATCH] make can_do_mlock useful for mlock/mlockall

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: default avatarChris Wright <chrisw@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 74b2d0c0
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment