vms/qemu.d/cad/prepare/begin/alloc_hugepages.sh

29 lines
980 B
Bash
Raw Normal View History

2021-05-19 17:49:55 +03:00
#!/bin/bash
MEMORY=24576
## Calculate number of hugepages to allocate from memory (in MB)
HUGEPAGES="$(($MEMORY/$(($(grep Hugepagesize /proc/meminfo | awk '{print $2}')/1024))))"
## Node to allocate on (node1 for this VM)
NODESPATH=/sys/devices/system/node/node1
echo "Allocating hugepages..."
echo $HUGEPAGES > $NODESPATH/hugepages/hugepages-2048kB/nr_hugepages
ALLOC_PAGES=$(cat $NODESPATH/hugepages/hugepages-2048kB/nr_hugepages)
TRIES=0
while (( $ALLOC_PAGES != $HUGEPAGES && $TRIES < 1000 ))
do
echo 1 > /proc/sys/vm/compact_memory ## defrag ram
echo $HUGEPAGES > $NODESPATH/hugepages/hugepages-2048kB/nr_hugepages
ALLOC_PAGES=$(cat $NODESPATH/hugepages/hugepages-2048kB/nr_hugepages)
echo "Succesfully allocated $ALLOC_PAGES / $HUGEPAGES"
let TRIES+=1
done
if [ "$ALLOC_PAGES" -ne "$HUGEPAGES" ]
then
echo "Not able to allocate all hugepages. Reverting..."
echo 0 > $NODESPATH/hugepages/hugepages-2048kB/nr_hugepages
exit 1
fi