aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorChris Wright <chrisw@osdl.org>2004-10-01 02:34:43 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2004-10-01 02:34:43 -0700
commitead942ce8a794f2103a5e5d2ad608a7b6b642d2c (patch)
tree587cdbc22ef20050b36c41adc48c42fecf4ce911 /mm
parent74b2d0c02d45e6b8f1b5c77b48171ab46b237b79 (diff)
downloadhistory-ead942ce8a794f2103a5e5d2ad608a7b6b642d2c.tar.gz
[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: Chris Wright <chrisw@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/mlock.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/mm/mlock.c b/mm/mlock.c
index 9ae544bf0f2c88..146224c5a2abe2 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -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;