aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/check_hugepage.sh
blob: bde11a946d6ca32a475a514da77f0ae591095553 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash -x

set -x

hugepagesize=$(cat /proc/meminfo | grep Hugepagesize | awk -F " " {'print$2'})
if [ "$hugepagesize" == "2048" ]; then
    pages=1536
elif [ "$hugepagesize" == "1048576" ]; then
    pages=3
fi
sudo sysctl -w vm.nr_hugepages=$pages
HUGEPAGES=`sysctl -n  vm.nr_hugepages`
if [ $HUGEPAGES != $pages ]; then
    echo "ERROR: Unable to get $pages hugepages, only got $HUGEPAGES.  Cannot finish."
    exit 1
fi

hugepageTotal=$(cat /proc/meminfo | grep -c "HugePages_Total:       0")
if [ $hugepageTotal -ne 0 ]; then
    echo "HugePages_Total is zero"
    exit 1
fi

hugepageFree=$(cat /proc/meminfo | grep -c "HugePages_Free:        0")
if [ $hugepageFree -ne 0 ]; then
    echo "HugePages_Free is zero"
    exit 1
fi

hugepageSize=$(cat /proc/meminfo | grep -c "Hugepagesize:          0 kB")
if [ $hugepageSize -ne 0 ]; then
    echo "Hugepagesize is zero"
    exit 1
fi

sudo mkdir /mnt/nstackhuge -p
if [ "$hugepagesize" == "2048" ]; then
    sudo mount -t hugetlbfs -o pagesize=2M none /mnt/nstackhuge/
elif [ "$hugepagesize" == "1048576" ]; then
    sudo mount -t hugetlbfs -o pagesize=1G none /mnt/nstackhuge/
fi