2 # SPDX-License-Identifier: GPL-2.0
5 # Kselftest framework requirement - SKIP code is 4.
15 usage: ${BASH_SOURCE[0]:-$0} [ options ]
17 -a: run all tests, including extra ones
18 -t: specify specific categories to tests to run
19 -h: display this message
21 The default behavior is to run required tests only. If -a is specified,
24 Alternatively, specific groups tests can be run by passing a string
25 to the -t argument containing one or more of the following categories
32 tests for userfaultfd(2)
34 a test for the patch "Allow compaction of unevictable pages"
40 tests for very large virtual address space
46 test memadvise(2) MADV_POPULATE_{READ,WRITE} options
50 test process_mrelease(2)
52 ksm tests that do not require >=2 NUMA nodes
54 ksm tests that require >=2 NUMA nodes
56 memory protection key tests
58 test soft dirty page bit semantics
60 test pagemap_scan IOCTL
62 test copy-on-write semantics
64 test transparent huge pages
66 invoke move_pages(2) to exercise the migration entry code
69 test handling of code that might set PTE/PMD dirty in
72 test prctl(PR_SET_MDWE, ...)
74 example: ./run_vmtests.sh -t "hmm mmap ksm"
81 while getopts "aht:" OPT; do
85 "t") VM_SELFTEST_ITEMS=${OPTARG} ;;
90 # default behavior: run all tests
91 VM_SELFTEST_ITEMS=${VM_SELFTEST_ITEMS:-default}
94 if [ "$VM_SELFTEST_ITEMS" == "default" ]; then
95 # If no VM_SELFTEST_ITEMS are specified, run all tests
98 # If test selected argument is one of the test items
99 if [[ " ${VM_SELFTEST_ITEMS[*]} " =~ " ${1} " ]]; then
107 # -t: thp=on, -T: thp=off, -H: hugetlb=on
108 local hugetlb_mb=$(( needmem_KB / 1024 ))
110 for huge in -t -T "-H -m $hugetlb_mb"; do
111 # -u: gup-fast, -U: gup-basic, -a: pin-fast, -b: pin-basic, -L: pin-longterm
112 for test_cmd in -u -U -a -b -L; do
113 # -w: write=1, -W: write=0
114 for write in -w -W; do
116 for share in -S " "; do
117 # -n: How many pages to fetch together? 512 is special
118 # because it's default thp size (or 2M on x86), 123 to
119 # just test partial gup when hit a huge in whatever form
120 for num in "-n 1" "-n 512" "-n 123"; do
121 CATEGORY="gup_test" run_test ./gup_test \
122 $huge $test_cmd $write $share $num
130 # get huge pagesize and freepages from /proc/meminfo
131 while read -r name size unit; do
132 if [ "$name" = "HugePages_Free:" ]; then
135 if [ "$name" = "Hugepagesize:" ]; then
140 # Simple hugetlbfs tests have a hardcoded minimum requirement of
141 # huge pages totaling 256MB (262144KB) in size. The userfaultfd
142 # hugetlb test requires a minimum of 2 * nr_cpus huge pages. Take
143 # both of these requirements into account and attempt to increase
144 # number of huge pages available.
146 hpgsize_MB=$((hpgsize_KB / 1024))
147 half_ufd_size_MB=$((((nr_cpus * hpgsize_MB + 127) / 128) * 128))
148 needmem_KB=$((half_ufd_size_MB * 2 * 1024))
150 # set proper nr_hugepages
151 if [ -n "$freepgs" ] && [ -n "$hpgsize_KB" ]; then
152 nr_hugepgs=$(cat /proc/sys/vm/nr_hugepages)
153 needpgs=$((needmem_KB / hpgsize_KB))
155 while [ "$tries" -gt 0 ] && [ "$freepgs" -lt "$needpgs" ]; do
156 lackpgs=$((needpgs - freepgs))
157 echo 3 > /proc/sys/vm/drop_caches
158 if ! echo $((lackpgs + nr_hugepgs)) > /proc/sys/vm/nr_hugepages; then
159 echo "Please run this test as root"
162 while read -r name size unit; do
163 if [ "$name" = "HugePages_Free:" ]; then
169 if [ "$freepgs" -lt "$needpgs" ]; then
170 printf "Not enough huge pages available (%d < %d)\n" \
171 "$freepgs" "$needpgs"
175 echo "no hugetlbfs support in kernel?"
179 # filter 64bit architectures
180 ARCH64STR="arm64 ia64 mips64 parisc64 ppc64 ppc64le riscv64 s390x sparc64 x86_64"
181 if [ -z "$ARCH" ]; then
182 ARCH=$(uname -m 2>/dev/null | sed -e 's/aarch64.*/arm64/')
185 echo "$ARCH64STR" | grep "$ARCH" &>/dev/null && VADDR64=1
187 # Usage: run_test [test binary] [arbitrary test arguments...]
189 if test_selected ${CATEGORY}; then
190 local title="running $*"
191 local sep=$(echo -n "$title" | tr "[:graph:][:space:]" -)
192 printf "%s\n%s\n%s\n" "$sep" "$title" "$sep"
196 if [ $ret -eq 0 ]; then
197 count_pass=$(( count_pass + 1 ))
199 elif [ $ret -eq $ksft_skip ]; then
200 count_skip=$(( count_skip + 1 ))
204 count_fail=$(( count_fail + 1 ))
211 CATEGORY="hugetlb" run_test ./hugepage-mmap
213 shmmax=$(cat /proc/sys/kernel/shmmax)
214 shmall=$(cat /proc/sys/kernel/shmall)
215 echo 268435456 > /proc/sys/kernel/shmmax
216 echo 4194304 > /proc/sys/kernel/shmall
217 CATEGORY="hugetlb" run_test ./hugepage-shm
218 echo "$shmmax" > /proc/sys/kernel/shmmax
219 echo "$shmall" > /proc/sys/kernel/shmall
221 CATEGORY="hugetlb" run_test ./map_hugetlb
222 CATEGORY="hugetlb" run_test ./hugepage-mremap
223 CATEGORY="hugetlb" run_test ./hugepage-vmemmap
224 CATEGORY="hugetlb" run_test ./hugetlb-madvise
226 # For this test, we need one and just one huge page
227 echo 1 > /proc/sys/vm/nr_hugepages
228 CATEGORY="hugetlb" run_test ./hugetlb_fault_after_madv
230 if test_selected "hugetlb"; then
231 echo "NOTE: These hugetlb tests provide minimal coverage. Use"
232 echo " https://github.com/libhugetlbfs/libhugetlbfs.git for"
233 echo " hugetlb regression testing."
236 CATEGORY="mmap" run_test ./map_fixed_noreplace
241 # get_user_pages_fast() benchmark
242 CATEGORY="gup_test" run_test ./gup_test -u
243 # pin_user_pages_fast() benchmark
244 CATEGORY="gup_test" run_test ./gup_test -a
246 # Dump pages 0, 19, and 4096, using pin_user_pages:
247 CATEGORY="gup_test" run_test ./gup_test -ct -F 0x1 0 19 0x1000
248 CATEGORY="gup_test" run_test ./gup_longterm
250 CATEGORY="userfaultfd" run_test ./uffd-unit-tests
251 uffd_stress_bin=./uffd-stress
252 CATEGORY="userfaultfd" run_test ${uffd_stress_bin} anon 20 16
253 # Hugetlb tests require source and destination huge pages. Pass in half
254 # the size ($half_ufd_size_MB), which is used for *each*.
255 CATEGORY="userfaultfd" run_test ${uffd_stress_bin} hugetlb "$half_ufd_size_MB" 32
256 CATEGORY="userfaultfd" run_test ${uffd_stress_bin} hugetlb-private "$half_ufd_size_MB" 32
257 CATEGORY="userfaultfd" run_test ${uffd_stress_bin} shmem 20 16
258 CATEGORY="userfaultfd" run_test ${uffd_stress_bin} shmem-private 20 16
261 echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages
263 CATEGORY="compaction" run_test ./compaction_test
265 CATEGORY="mlock" run_test sudo -u nobody ./on-fault-limit
267 CATEGORY="mmap" run_test ./map_populate
269 CATEGORY="mlock" run_test ./mlock-random-test
271 CATEGORY="mlock" run_test ./mlock2-tests
273 CATEGORY="process_mrelease" run_test ./mrelease_test
275 CATEGORY="mremap" run_test ./mremap_test
277 CATEGORY="hugetlb" run_test ./thuge-gen
279 if [ $VADDR64 -ne 0 ]; then
281 # set overcommit_policy as OVERCOMMIT_ALWAYS so that kernel
282 # allows high virtual address allocation requests independent
283 # of platform's physical memory.
285 prev_policy=$(cat /proc/sys/vm/overcommit_memory)
286 echo 1 > /proc/sys/vm/overcommit_memory
287 CATEGORY="hugevm" run_test ./virtual_address_range
288 echo $prev_policy > /proc/sys/vm/overcommit_memory
290 # va high address boundary switch test
292 prev_nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
293 if [ "$ARCH" == "$ARCH_ARM64" ]; then
294 echo 6 > /proc/sys/vm/nr_hugepages
296 CATEGORY="hugevm" run_test bash ./va_high_addr_switch.sh
297 if [ "$ARCH" == "$ARCH_ARM64" ]; then
298 echo $prev_nr_hugepages > /proc/sys/vm/nr_hugepages
302 # vmalloc stability smoke test
303 CATEGORY="vmalloc" run_test bash ./test_vmalloc.sh smoke
305 CATEGORY="mremap" run_test ./mremap_dontunmap
307 CATEGORY="hmm" run_test bash ./test_hmm.sh smoke
309 # MADV_POPULATE_READ and MADV_POPULATE_WRITE tests
310 CATEGORY="madv_populate" run_test ./madv_populate
312 echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
313 CATEGORY="memfd_secret" run_test ./memfd_secret
315 # KSM KSM_MERGE_TIME_HUGE_PAGES test with size of 100
316 CATEGORY="ksm" run_test ./ksm_tests -H -s 100
317 # KSM KSM_MERGE_TIME test with size of 100
318 CATEGORY="ksm" run_test ./ksm_tests -P -s 100
319 # KSM MADV_MERGEABLE test with 10 identical pages
320 CATEGORY="ksm" run_test ./ksm_tests -M -p 10
322 CATEGORY="ksm" run_test ./ksm_tests -U
323 # KSM test with 10 zero pages and use_zero_pages = 0
324 CATEGORY="ksm" run_test ./ksm_tests -Z -p 10 -z 0
325 # KSM test with 10 zero pages and use_zero_pages = 1
326 CATEGORY="ksm" run_test ./ksm_tests -Z -p 10 -z 1
327 # KSM test with 2 NUMA nodes and merge_across_nodes = 1
328 CATEGORY="ksm_numa" run_test ./ksm_tests -N -m 1
329 # KSM test with 2 NUMA nodes and merge_across_nodes = 0
330 CATEGORY="ksm_numa" run_test ./ksm_tests -N -m 0
332 CATEGORY="ksm" run_test ./ksm_functional_tests
334 run_test ./ksm_functional_tests
336 # protection_keys tests
337 if [ -x ./protection_keys_32 ]
339 CATEGORY="pkey" run_test ./protection_keys_32
342 if [ -x ./protection_keys_64 ]
344 CATEGORY="pkey" run_test ./protection_keys_64
347 if [ -x ./soft-dirty ]
349 CATEGORY="soft_dirty" run_test ./soft-dirty
352 CATEGORY="pagemap" run_test ./pagemap_ioctl
355 CATEGORY="cow" run_test ./cow
357 CATEGORY="thp" run_test ./khugepaged
359 CATEGORY="thp" run_test ./transhuge-stress -d 20
361 CATEGORY="thp" run_test ./split_huge_page_test
363 CATEGORY="migration" run_test ./migration
365 CATEGORY="mkdirty" run_test ./mkdirty
367 CATEGORY="mdwe" run_test ./mdwe_test
369 echo "SUMMARY: PASS=${count_pass} SKIP=${count_skip} FAIL=${count_fail}"