• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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	if [ $freepgs -lt $needpgs ]; then
24		lackpgs=$(( $needpgs - $freepgs ))
25		echo $(( $lackpgs + $nr_hugepgs )) > /proc/sys/vm/nr_hugepages
26		if [ $? -ne 0 ]; then
27			echo "Please run this test as root"
28			exit 1
29		fi
30	fi
31else
32	echo "no hugetlbfs support in kernel?"
33	exit 1
34fi
35
36mkdir $mnt
37mount -t hugetlbfs none $mnt
38
39echo "--------------------"
40echo "running hugepage-mmap"
41echo "--------------------"
42./hugepage-mmap
43if [ $? -ne 0 ]; then
44	echo "[FAIL]"
45	exitcode=1
46else
47	echo "[PASS]"
48fi
49
50shmmax=`cat /proc/sys/kernel/shmmax`
51shmall=`cat /proc/sys/kernel/shmall`
52echo 268435456 > /proc/sys/kernel/shmmax
53echo 4194304 > /proc/sys/kernel/shmall
54echo "--------------------"
55echo "running hugepage-shm"
56echo "--------------------"
57./hugepage-shm
58if [ $? -ne 0 ]; then
59	echo "[FAIL]"
60	exitcode=1
61else
62	echo "[PASS]"
63fi
64echo $shmmax > /proc/sys/kernel/shmmax
65echo $shmall > /proc/sys/kernel/shmall
66
67echo "--------------------"
68echo "running map_hugetlb"
69echo "--------------------"
70./map_hugetlb
71if [ $? -ne 0 ]; then
72	echo "[FAIL]"
73	exitcode=1
74else
75	echo "[PASS]"
76fi
77
78echo "--------------------"
79echo "running hugetlbfstest"
80echo "--------------------"
81./hugetlbfstest
82if [ $? -ne 0 ]; then
83	echo "[FAIL]"
84	exitcode=1
85else
86	echo "[PASS]"
87fi
88
89#cleanup
90umount $mnt
91rm -rf $mnt
92echo $nr_hugepgs > /proc/sys/vm/nr_hugepages
93exit $exitcode
94