2 # SPDX-License-Identifier: GPL-2.0
5 # Kselftest framework requirement - SKIP code is 4.
12 usage: ${BASH_SOURCE[0]:-$0} [ -h | -t "<categories>"]
13 -t: specify specific categories to tests to run
14 -h: display this message
16 The default behavior is to run all tests.
18 Alternatively, specific groups tests can be run by passing a string
19 to the -t argument containing one or more of the following categories
24 tests for gup using gup_test interface
26 tests for userfaultfd(2)
28 a test for the patch "Allow compaction of unevictable pages"
34 tests for very large virtual address space
40 test memadvise(2) MADV_POPULATE_{READ,WRITE} options
44 test process_mrelease(2)
46 ksm tests that do not require >=2 NUMA nodes
48 ksm tests that require >=2 NUMA nodes
50 memory protection key tests
52 test soft dirty page bit semantics
54 test copy-on-write semantics
55 example: ./run_vmtests.sh -t "hmm mmap ksm"
61 while getopts "ht:" OPT; do
64 "t") VM_SELFTEST_ITEMS=${OPTARG} ;;
69 # default behavior: run all tests
70 VM_SELFTEST_ITEMS=${VM_SELFTEST_ITEMS:-default}
73 if [ "$VM_SELFTEST_ITEMS" == "default" ]; then
74 # If no VM_SELFTEST_ITEMS are specified, run all tests
77 # If test selected argument is one of the test items
78 if [[ " ${VM_SELFTEST_ITEMS[*]} " =~ " ${1} " ]]; then
85 # get huge pagesize and freepages from /proc/meminfo
86 while read -r name size unit; do
87 if [ "$name" = "HugePages_Free:" ]; then
90 if [ "$name" = "Hugepagesize:" ]; then
95 # Simple hugetlbfs tests have a hardcoded minimum requirement of
96 # huge pages totaling 256MB (262144KB) in size. The userfaultfd
97 # hugetlb test requires a minimum of 2 * nr_cpus huge pages. Take
98 # both of these requirements into account and attempt to increase
99 # number of huge pages available.
101 hpgsize_MB=$((hpgsize_KB / 1024))
102 half_ufd_size_MB=$((((nr_cpus * hpgsize_MB + 127) / 128) * 128))
103 needmem_KB=$((half_ufd_size_MB * 2 * 1024))
105 # set proper nr_hugepages
106 if [ -n "$freepgs" ] && [ -n "$hpgsize_KB" ]; then
107 nr_hugepgs=$(cat /proc/sys/vm/nr_hugepages)
108 needpgs=$((needmem_KB / hpgsize_KB))
110 while [ "$tries" -gt 0 ] && [ "$freepgs" -lt "$needpgs" ]; do
111 lackpgs=$((needpgs - freepgs))
112 echo 3 > /proc/sys/vm/drop_caches
113 if ! echo $((lackpgs + nr_hugepgs)) > /proc/sys/vm/nr_hugepages; then
114 echo "Please run this test as root"
117 while read -r name size unit; do
118 if [ "$name" = "HugePages_Free:" ]; then
124 if [ "$freepgs" -lt "$needpgs" ]; then
125 printf "Not enough huge pages available (%d < %d)\n" \
126 "$freepgs" "$needpgs"
130 echo "no hugetlbfs support in kernel?"
134 # filter 64bit architectures
135 ARCH64STR="arm64 ia64 mips64 parisc64 ppc64 ppc64le riscv64 s390x sh64 sparc64 x86_64"
136 if [ -z "$ARCH" ]; then
137 ARCH=$(uname -m 2>/dev/null | sed -e 's/aarch64.*/arm64/')
140 echo "$ARCH64STR" | grep "$ARCH" &>/dev/null && VADDR64=1
142 # Usage: run_test [test binary] [arbitrary test arguments...]
144 if test_selected ${CATEGORY}; then
145 local title="running $*"
146 local sep=$(echo -n "$title" | tr "[:graph:][:space:]" -)
147 printf "%s\n%s\n%s\n" "$sep" "$title" "$sep"
151 if [ $ret -eq 0 ]; then
153 elif [ $ret -eq $ksft_skip ]; then
163 CATEGORY="hugetlb" run_test ./hugepage-mmap
165 shmmax=$(cat /proc/sys/kernel/shmmax)
166 shmall=$(cat /proc/sys/kernel/shmall)
167 echo 268435456 > /proc/sys/kernel/shmmax
168 echo 4194304 > /proc/sys/kernel/shmall
169 CATEGORY="hugetlb" run_test ./hugepage-shm
170 echo "$shmmax" > /proc/sys/kernel/shmmax
171 echo "$shmall" > /proc/sys/kernel/shmall
173 CATEGORY="hugetlb" run_test ./map_hugetlb
174 CATEGORY="hugetlb" run_test ./hugepage-mremap
175 CATEGORY="hugetlb" run_test ./hugepage-vmemmap
176 CATEGORY="hugetlb" run_test ./hugetlb-madvise
178 if test_selected "hugetlb"; then
179 echo "NOTE: These hugetlb tests provide minimal coverage. Use"
180 echo " https://github.com/libhugetlbfs/libhugetlbfs.git for"
181 echo " hugetlb regression testing."
184 CATEGORY="mmap" run_test ./map_fixed_noreplace
186 # get_user_pages_fast() benchmark
187 CATEGORY="gup_test" run_test ./gup_test -u
188 # pin_user_pages_fast() benchmark
189 CATEGORY="gup_test" run_test ./gup_test -a
190 # Dump pages 0, 19, and 4096, using pin_user_pages:
191 CATEGORY="gup_test" run_test ./gup_test -ct -F 0x1 0 19 0x1000
193 uffd_mods=("" ":dev")
194 for mod in "${uffd_mods[@]}"; do
195 CATEGORY="userfaultfd" run_test ./userfaultfd anon${mod} 20 16
196 # Hugetlb tests require source and destination huge pages. Pass in half
197 # the size ($half_ufd_size_MB), which is used for *each*.
198 CATEGORY="userfaultfd" run_test ./userfaultfd hugetlb${mod} "$half_ufd_size_MB" 32
199 CATEGORY="userfaultfd" run_test ./userfaultfd hugetlb_shared${mod} "$half_ufd_size_MB" 32
200 CATEGORY="userfaultfd" run_test ./userfaultfd shmem${mod} 20 16
204 echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages
206 CATEGORY="compaction" run_test ./compaction_test
208 CATEGORY="mlock" run_test sudo -u nobody ./on-fault-limit
210 CATEGORY="mmap" run_test ./map_populate
212 CATEGORY="mlock" run_test ./mlock-random-test
214 CATEGORY="mlock" run_test ./mlock2-tests
216 CATEGORY="process_mrelease" run_test ./mrelease_test
218 CATEGORY="mremap" run_test ./mremap_test
220 CATEGORY="hugetlb" run_test ./thuge-gen
222 if [ $VADDR64 -ne 0 ]; then
223 CATEGORY="hugevm" run_test ./virtual_address_range
225 # virtual address 128TB switch test
226 CATEGORY="hugevm" run_test ./va_128TBswitch.sh
229 # vmalloc stability smoke test
230 CATEGORY="vmalloc" run_test ./test_vmalloc.sh smoke
232 CATEGORY="mremap" run_test ./mremap_dontunmap
234 CATEGORY="hmm" run_test ./test_hmm.sh smoke
236 # MADV_POPULATE_READ and MADV_POPULATE_WRITE tests
237 CATEGORY="madv_populate" run_test ./madv_populate
239 CATEGORY="memfd_secret" run_test ./memfd_secret
241 # KSM MADV_MERGEABLE test with 10 identical pages
242 CATEGORY="ksm" run_test ./ksm_tests -M -p 10
244 CATEGORY="ksm" run_test ./ksm_tests -U
245 # KSM test with 10 zero pages and use_zero_pages = 0
246 CATEGORY="ksm" run_test ./ksm_tests -Z -p 10 -z 0
247 # KSM test with 10 zero pages and use_zero_pages = 1
248 CATEGORY="ksm" run_test ./ksm_tests -Z -p 10 -z 1
249 # KSM test with 2 NUMA nodes and merge_across_nodes = 1
250 CATEGORY="ksm_numa" run_test ./ksm_tests -N -m 1
251 # KSM test with 2 NUMA nodes and merge_across_nodes = 0
252 CATEGORY="ksm_numa" run_test ./ksm_tests -N -m 0
254 CATEGORY="ksm" run_test ./ksm_functional_tests
256 run_test ./ksm_functional_tests
258 # protection_keys tests
259 if [ -x ./protection_keys_32 ]
261 CATEGORY="pkey" run_test ./protection_keys_32
264 if [ -x ./protection_keys_64 ]
266 CATEGORY="pkey" run_test ./protection_keys_64
269 CATEGORY="soft_dirty" run_test ./soft-dirty
272 CATEGORY="cow" run_test ./cow