linux/tools/testing/selftests/vm/run_vmtests
<<
>>
Prefs
   1#!/bin/bash
   2#please run as root
   3
   4#we need 256M, below is the size in kB
   5needmem=262144
   6mnt=./huge
   7
   8#get pagesize and freepages from /proc/meminfo
   9while 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
  16done < /proc/meminfo
  17
  18#set proper nr_hugepages
  19if [ -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
  30else
  31        echo "no hugetlbfs support in kernel?"
  32        exit 1
  33fi
  34
  35mkdir $mnt
  36mount -t hugetlbfs none $mnt
  37
  38echo "--------------------"
  39echo "running hugepage-mmap"
  40echo "--------------------"
  41./hugepage-mmap
  42if [ $? -ne 0 ]; then
  43        echo "[FAIL]"
  44else
  45        echo "[PASS]"
  46fi
  47
  48shmmax=`cat /proc/sys/kernel/shmmax`
  49shmall=`cat /proc/sys/kernel/shmall`
  50echo 268435456 > /proc/sys/kernel/shmmax
  51echo 4194304 > /proc/sys/kernel/shmall
  52echo "--------------------"
  53echo "running hugepage-shm"
  54echo "--------------------"
  55./hugepage-shm
  56if [ $? -ne 0 ]; then
  57        echo "[FAIL]"
  58else
  59        echo "[PASS]"
  60fi
  61echo $shmmax > /proc/sys/kernel/shmmax
  62echo $shmall > /proc/sys/kernel/shmall
  63
  64echo "--------------------"
  65echo "running map_hugetlb"
  66echo "--------------------"
  67./map_hugetlb
  68if [ $? -ne 0 ]; then
  69        echo "[FAIL]"
  70else
  71        echo "[PASS]"
  72fi
  73
  74#cleanup
  75umount $mnt
  76rm -rf $mnt
  77echo $nr_hugepgs > /proc/sys/vm/nr_hugepages
  78