Commit 1f522a48 authored by Mike Kravetz's avatar Mike Kravetz Committed by Linus Torvalds

selftests/memfd: add memfd_create hugetlbfs selftest

With the addition of hugetlbfs support in memfd_create, the memfd
selftests should verify correct functionality with hugetlbfs.

Instead of writing a separate memfd hugetlbfs test, modify the
memfd_test program to take an optional argument 'hugetlbfs'.  If the
hugetlbfs argument is specified, basic memfd_create functionality will
be exercised on hugetlbfs.  If hugetlbfs is not specified, the current
functionality of the test is unchanged.

Note that many of the tests in memfd_test test file sealing operations.
hugetlbfs does not support file sealing, therefore for hugetlbfs all
sealing related tests are skipped.

In order to test on hugetlbfs, there needs to be preallocated huge
pages.  A new script (run_tests) is added.  This script will first run
the existing memfd_create tests.  It will then, attempt to allocate the
required number of huge pages before running the hugetlbfs test.  At the
end of testing, it will release any huge pages allocated for testing
purposes.

Link: http://lkml.kernel.org/r/1502495772-24736-3-git-send-email-mike.kravetz@oracle.comSigned-off-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 749df87b
...@@ -3,7 +3,7 @@ CFLAGS += -I../../../../include/uapi/ ...@@ -3,7 +3,7 @@ CFLAGS += -I../../../../include/uapi/
CFLAGS += -I../../../../include/ CFLAGS += -I../../../../include/
CFLAGS += -I../../../../usr/include/ CFLAGS += -I../../../../usr/include/
TEST_PROGS := run_fuse_test.sh TEST_PROGS := run_tests.sh
TEST_GEN_FILES := memfd_test fuse_mnt fuse_test TEST_GEN_FILES := memfd_test fuse_mnt fuse_test
fuse_mnt.o: CFLAGS += $(shell pkg-config fuse --cflags) fuse_mnt.o: CFLAGS += $(shell pkg-config fuse --cflags)
......
This diff is collapsed.
#!/bin/bash
# please run as root
#
# Normal tests requiring no special resources
#
./run_fuse_test.sh
./memfd_test
#
# To test memfd_create with hugetlbfs, there needs to be hpages_test
# huge pages free. Attempt to allocate enough pages to test.
#
hpages_test=8
#
# Get count of free huge pages from /proc/meminfo
#
while read name size unit; do
if [ "$name" = "HugePages_Free:" ]; then
freepgs=$size
fi
done < /proc/meminfo
#
# If not enough free huge pages for test, attempt to increase
#
if [ -n "$freepgs" ] && [ $freepgs -lt $hpages_test ]; then
nr_hugepgs=`cat /proc/sys/vm/nr_hugepages`
hpages_needed=`expr $hpages_test - $freepgs`
echo 3 > /proc/sys/vm/drop_caches
echo $(( $hpages_needed + $nr_hugepgs )) > /proc/sys/vm/nr_hugepages
if [ $? -ne 0 ]; then
echo "Please run this test as root"
exit 1
fi
while read name size unit; do
if [ "$name" = "HugePages_Free:" ]; then
freepgs=$size
fi
done < /proc/meminfo
fi
#
# If still not enough huge pages available, exit. But, give back any huge
# pages potentially allocated above.
#
if [ $freepgs -lt $hpages_test ]; then
# nr_hugepgs non-zero only if we attempted to increase
if [ -n "$nr_hugepgs" ]; then
echo $nr_hugepgs > /proc/sys/vm/nr_hugepages
fi
printf "Not enough huge pages available (%d < %d)\n" \
$freepgs $needpgs
exit 1
fi
#
# Run the hugetlbfs test
#
./memfd_test hugetlbfs
#
# Give back any huge pages allocated for the test
#
if [ -n "$nr_hugepgs" ]; then
echo $nr_hugepgs > /proc/sys/vm/nr_hugepages
fi
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