Commit b3b0d09c authored by Eric B Munson's avatar Eric B Munson Committed by Linus Torvalds

selftests: vm: add tests for lock on fault

Test the mmap() flag, and the mlockall() flag.  These tests ensure that
pages are not faulted in until they are accessed, that the pages are
unevictable once faulted in, and that VMA splitting and merging works with
the new VM flag.  The second test ensures that mlock limits are respected.
 Note that the limit test needs to be run a normal user.

Also add tests to use the new mlock2 family of system calls.

[treding@nvidia.com: : Fix mlock2-tests for 32-bit architectures]
[treding@nvidia.com: ensure the mlock2 syscall number can be found]
[treding@nvidia.com: use the right arguments for main()]
Signed-off-by: default avatarEric B Munson <emunson@akamai.com>
Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Michael Kerrisk <mtk.manpages@gmail.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b0f205c2
...@@ -5,6 +5,8 @@ BINARIES = compaction_test ...@@ -5,6 +5,8 @@ BINARIES = compaction_test
BINARIES += hugepage-mmap BINARIES += hugepage-mmap
BINARIES += hugepage-shm BINARIES += hugepage-shm
BINARIES += map_hugetlb BINARIES += map_hugetlb
BINARIES += mlock2-tests
BINARIES += on-fault-limit
BINARIES += thuge-gen BINARIES += thuge-gen
BINARIES += transhuge-stress BINARIES += transhuge-stress
BINARIES += userfaultfd BINARIES += userfaultfd
......
This diff is collapsed.
#include <sys/mman.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/time.h>
#include <sys/resource.h>
#ifndef MCL_ONFAULT
#define MCL_ONFAULT (MCL_FUTURE << 1)
#endif
static int test_limit(void)
{
int ret = 1;
struct rlimit lims;
void *map;
if (getrlimit(RLIMIT_MEMLOCK, &lims)) {
perror("getrlimit");
return ret;
}
if (mlockall(MCL_CURRENT | MCL_ONFAULT | MCL_FUTURE)) {
perror("mlockall");
return ret;
}
map = mmap(NULL, 2 * lims.rlim_max, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, 0, 0);
if (map != MAP_FAILED)
printf("mmap should have failed, but didn't\n");
else {
ret = 0;
munmap(map, 2 * lims.rlim_max);
}
munlockall();
return ret;
}
int main(int argc, char **argv)
{
int ret = 0;
ret += test_limit();
return ret;
}
...@@ -106,4 +106,26 @@ else ...@@ -106,4 +106,26 @@ else
echo "[PASS]" echo "[PASS]"
fi fi
echo "--------------------"
echo "running on-fault-limit"
echo "--------------------"
sudo -u nobody ./on-fault-limit
if [ $? -ne 0 ]; then
echo "[FAIL]"
exitcode=1
else
echo "[PASS]"
fi
echo "--------------------"
echo "running mlock2-tests"
echo "--------------------"
./mlock2-tests
if [ $? -ne 0 ]; then
echo "[FAIL]"
exitcode=1
else
echo "[PASS]"
fi
exit $exitcode exit $exitcode
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