Zram as SWAP file in Proxmox VE
Zram Technology
Zram is a technology which allows you to create a block device in RAM on which data is compressed by one of the selected algorithms when saving.
There are several algorithms available, depending on the version of the operating system. For example, in the latest Proxmox version, these are lzo, lz4, lz4hc, deflate. The default setting is lzo. This is probably because it was added to the kernel module earlier and saved as a default setting for compatibility purposes. The most optimal choice at the moment is lzo4, which has an optimal speed to compression ratio and is very fast to decompress. Furthermore, lz4 is available in almost all current linux distributions.
How to enable the zRAM module for faster swapping on Debian/Ubuntu
This example should work with recent versions of Debian (from version 9) and Ubuntu (from version 18). In this example we add 32G:
zramctl -s 32G -a lz4 /dev/zram0
mkswap /dev/zram0
swapon /dev/zram0 -p 10
Next, set up automatic zram swap creation at system startup:
echo "zram" > /etc/modules-load.d/zram.confecho 'KERNEL=="zram0", ATTR { disksize } ="32G" RUN="/sbin/mkswap /dev/zram0", TAG+="systemd"' > /etc/udev/rules.d/99-zram.rules
You can view the partition usage statistics by using the zramctl command without parameters:
Example output:
/dev/zram0 lz4 32G 48.7M 20.1M 21.5M 16 [SWAP]