1#!/bin/bash 2#please run as root 3 4#we need 256M, below is the size in kB 5needmem=262144 6mnt=./huge 7exitcode=0 8 9#get pagesize and freepages from /proc/meminfo 10while read name size unit; do 11 if [ "$name" = "HugePages_Free:" ]; then 12 freepgs=$size 13 fi 14 if [ "$name" = "Hugepagesize:" ]; then 15 pgsize=$size 16 fi 17done < /proc/meminfo 18 19#set proper nr_hugepages 20if [ -n "$freepgs" ] && [ -n "$pgsize" ]; then 21 nr_hugepgs=`cat /proc/sys/vm/nr_hugepages` 22 needpgs=`expr $needmem / $pgsize` 23 tries=2 24 while [ $tries -gt 0 ] && [ $freepgs -lt $needpgs ]; do 25 lackpgs=$(( $needpgs - $freepgs )) 26 echo 3 > /proc/sys/vm/drop_caches 27 echo $(( $lackpgs + $nr_hugepgs )) > /proc/sys/vm/nr_hugepages 28 if [ $? -ne 0 ]; then 29 echo "Please run this test as root" 30 exit 1 31 fi 32 while read name size unit; do 33 if [ "$name" = "HugePages_Free:" ]; then 34 freepgs=$size 35 fi 36 done < /proc/meminfo 37 tries=$((tries - 1)) 38 done 39 if [ $freepgs -lt $needpgs ]; then 40 printf "Not enough huge pages available (%d < %d)\n" \ 41 $freepgs $needpgs 42 exit 1 43 fi 44else 45 echo "no hugetlbfs support in kernel?" 46 exit 1 47fi 48 49mkdir $mnt 50mount -t hugetlbfs none $mnt 51 52echo "--------------------" 53echo "running hugepage-mmap" 54echo "--------------------" 55./hugepage-mmap 56if [ $? -ne 0 ]; then 57 echo "[FAIL]" 58 exitcode=1 59else 60 echo "[PASS]" 61fi 62 63shmmax=`cat /proc/sys/kernel/shmmax` 64shmall=`cat /proc/sys/kernel/shmall` 65echo 268435456 > /proc/sys/kernel/shmmax 66echo 4194304 > /proc/sys/kernel/shmall 67echo "--------------------" 68echo "running hugepage-shm" 69echo "--------------------" 70./hugepage-shm 71if [ $? -ne 0 ]; then 72 echo "[FAIL]" 73 exitcode=1 74else 75 echo "[PASS]" 76fi 77echo $shmmax > /proc/sys/kernel/shmmax 78echo $shmall > /proc/sys/kernel/shmall 79 80echo "--------------------" 81echo "running map_hugetlb" 82echo "--------------------" 83./map_hugetlb 84if [ $? -ne 0 ]; then 85 echo "[FAIL]" 86 exitcode=1 87else 88 echo "[PASS]" 89fi 90 91echo "NOTE: The above hugetlb tests provide minimal coverage. Use" 92echo " https://github.com/libhugetlbfs/libhugetlbfs.git for" 93echo " hugetlb regression testing." 94 95echo "--------------------" 96echo "running userfaultfd" 97echo "--------------------" 98./userfaultfd 128 32 99if [ $? -ne 0 ]; then 100 echo "[FAIL]" 101 exitcode=1 102else 103 echo "[PASS]" 104fi 105 106#cleanup 107umount $mnt 108rm -rf $mnt 109echo $nr_hugepgs > /proc/sys/vm/nr_hugepages 110 111echo "-----------------------" 112echo "running compaction_test" 113echo "-----------------------" 114./compaction_test 115if [ $? -ne 0 ]; then 116 echo "[FAIL]" 117 exitcode=1 118else 119 echo "[PASS]" 120fi 121 122echo "--------------------" 123echo "running on-fault-limit" 124echo "--------------------" 125sudo -u nobody ./on-fault-limit 126if [ $? -ne 0 ]; then 127 echo "[FAIL]" 128 exitcode=1 129else 130 echo "[PASS]" 131fi 132 133echo "--------------------" 134echo "running mlock2-tests" 135echo "--------------------" 136./mlock2-tests 137if [ $? -ne 0 ]; then 138 echo "[FAIL]" 139 exitcode=1 140else 141 echo "[PASS]" 142fi 143 144exit $exitcode 145