[PATCH 3/4] make can_do_mlock useful for mlock/mlockall

From: Chris Wright
Date: Wed Sep 29 2004 - 13:59:18 EST


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@xxxxxxxx>

--- 2.6.9-rc2/mm/mlock.c~can_do_mlock 2004-09-28 15:06:54.668639256 -0700
+++ 2.6.9-rc2/mm/mlock.c 2004-09-28 15:08:56.175167456 -0700
@@ -60,8 +60,6 @@ static int do_mlock(unsigned long start,
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
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 lon

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;

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/