mm: move hugepage test examples to tools/testing/selftests/vm
[~shefty/rdma-dev.git] / tools / testing / selftests / vm / run_vmtests
1 #!/bin/bash
2 #please run as root
3
4 #we need 256M, below is the size in kB
5 needmem=262144
6 mnt=./huge
7
8 #get pagesize and freepages from /proc/meminfo
9 while read name size unit; do
10         if [ "$name" = "HugePages_Free:" ]; then
11                 freepgs=$size
12         fi
13         if [ "$name" = "Hugepagesize:" ]; then
14                 pgsize=$size
15         fi
16 done < /proc/meminfo
17
18 #set proper nr_hugepages
19 if [ -n "$freepgs" ] && [ -n "$pgsize" ]; then
20         nr_hugepgs=`cat /proc/sys/vm/nr_hugepages`
21         needpgs=`expr $needmem / $pgsize`
22         if [ $freepgs -lt $needpgs ]; then
23                 lackpgs=$(( $needpgs - $freepgs ))
24                 echo $(( $lackpgs + $nr_hugepgs )) > /proc/sys/vm/nr_hugepages
25                 if [ $? -ne 0 ]; then
26                         echo "Please run this test as root"
27                         exit 1
28                 fi
29         fi
30 else
31         echo "no hugetlbfs support in kernel?"
32         exit 1
33 fi
34
35 mkdir $mnt
36 mount -t hugetlbfs none $mnt
37
38 echo "--------------------"
39 echo "runing hugepage-mmap"
40 echo "--------------------"
41 ./hugepage-mmap
42 if [ $? -ne 0 ]; then
43         echo "[FAIL]"
44 else
45         echo "[PASS]"
46 fi
47
48 shmmax=`cat /proc/sys/kernel/shmmax`
49 shmall=`cat /proc/sys/kernel/shmall`
50 echo 268435456 > /proc/sys/kernel/shmmax
51 echo 4194304 > /proc/sys/kernel/shmall
52 echo "--------------------"
53 echo "runing hugepage-shm"
54 echo "--------------------"
55 ./hugepage-shm
56 if [ $? -ne 0 ]; then
57         echo "[FAIL]"
58 else
59         echo "[PASS]"
60 fi
61 echo $shmmax > /proc/sys/kernel/shmmax
62 echo $shmall > /proc/sys/kernel/shmall
63
64 echo "--------------------"
65 echo "runing map_hugetlb"
66 echo "--------------------"
67 ./map_hugetlb
68 if [ $? -ne 0 ]; then
69         echo "[FAIL]"
70 else
71         echo "[PASS]"
72 fi
73
74 #cleanup
75 umount $mnt
76 rm -rf $mnt
77 echo $nr_hugepgs > /proc/sys/vm/nr_hugepages