mirror of
https://gitlab.com/Karuri/vfio.git
synced 2024-11-15 12:13:01 +00:00
29 lines
820 B
Bash
29 lines
820 B
Bash
#!/bin/bash
|
|
|
|
## Load the config file
|
|
source "/etc/libvirt/hooks/kvm.conf"
|
|
|
|
## Calculate number of hugepages to allocate from memory (in MB)
|
|
HUGEPAGES="$(($MEMORY/$(($(grep Hugepagesize /proc/meminfo | awk '{print $2}')/1024))))"
|
|
|
|
echo "Allocating hugepages..."
|
|
echo $HUGEPAGES > /proc/sys/vm/nr_hugepages
|
|
ALLOC_PAGES=$(cat /proc/sys/vm/nr_hugepages)
|
|
|
|
TRIES=0
|
|
while (( $ALLOC_PAGES != $HUGEPAGES && $TRIES < 1000 ))
|
|
do
|
|
echo 1 > /proc/sys/vm/compact_memory ## defrag ram
|
|
echo $HUGEPAGES > /proc/sys/vm/nr_hugepages
|
|
ALLOC_PAGES=$(cat /proc/sys/vm/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 > /proc/sys/vm/nr_hugepages
|
|
exit 1
|
|
fi
|