HugePages

Configure HugePages in Pritunl Cloud

Static hugepages provide a sector of the system memory to be dedicated for hugepages. This memory will be used for instances allowing higher memory performance and preventing the host system from disturbing memory dedicated for virtual instances. This option should always be used on production systems. The hugepages size can be set from the Pritunl Cloud web console in the Nodes tab. Enabling this option while instances are running is likely to crash the system.

First run the command free -m on the server to get the total memory size in megabytes. In this example the total memory is 257824. Then subtract 4-6 gigabytes that will be left for the system.

877

In this example 6gb will be left for the system 257824-6144 and a 251680 megabyte hugepages size will be used. Stop all running instances and run sudo sh -c "echo 3 > /proc/sys/vm/drop_caches" to clear the current disk cache. Then in the Nodes tab from the web console enable HugePages and set the HugePages Size. Then click Save.

367

Once an instant is started the HugePages size will be set and the log message hugepages: Updating hugepages size will be shown. The HugePages usage can be monitored by running the command cat /proc/meminfo | grep Huge.

527

ZRAM Swap

Using a ZRAM swap can also improve the server performance without using a disk device. The ZRAM swap will use compression instead of a disk device. First verify that the existing swap will fit in system memory then run sudo swapoff -a to turn off the swap. If the swap is configured in /etc/fstab remove the mount to prevent the swap from being automatically added. Run sudo swapon -a then verify that no swap space is added.

sudo swapoff -a
sudo nano /etc/fstab
sudo swapon -a

Edit the 2G below to change the size of the ZRAM swap. The swap should not be larger then 50% of system memory left after the HugePages allocation. Then run the commands below to create a systemd service to automatically configure the swap on system startup.

sudo tee /usr/bin/zram-swapon << EOF
#!/bin/bash
/usr/sbin/modprobe zram
echo lzo-rle > /sys/block/zram0/comp_algorithm
echo 2G > /sys/block/zram0/disksize
/usr/sbin/mkswap --label zram0 /dev/zram0
/usr/sbin/swapon --priority 100 /dev/zram0
EOF
sudo chmod +x /usr/bin/zram-swapon

sudo tee /etc/systemd/system/zram-swapon.service << EOF
[Unit]
Description=ZRAM Swap
Wants=network-online.target
After=network-online.target

[Service]
User=root
Type=oneshot
ExecStart=/usr/bin/zram-swapon

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl enable zram-swapon
sudo systemctl start zram-swapon