Mega fast SWAP for Linux VM's (and hosts) ZRAM


jimbo45

Well-known member
Pro User
VIP
Local time
11:05 AM
Posts
4,007
Location
Hafnarfjörður IS
OS
Windows XP,7,10,11 Linux Arch Linux
Hi folks
If you guys use Linux at all for any VM's - especially if you have them on Nvme devices then use ZRAM for swap rather than standard swap files -- especially in a VM where the "Virtual disk" is being emulated to run the Guest's file system -- so you get "double overhead" as the HOST OS has to convert data into the Guest's file system.

On Debian type distros (arch linux, manjaro debian, Mint etc) -- simply make a bash script.


echo 0 > /sys/module/zswap/parameters/enabled
modprobe zram
zramctl /dev/zram0 --algorithm zstd --size 2.6G <===================== choose your size here
mkswap -U clear /dev/zram0
swapon --priority 100 /dev/zram0
zramctl <========================= this displays status to see if it works

save as zram.sh and execute as su or sudo with ./zram.sh after boot.

There are methods for automatically enabling zram as a service to start at boot but this so simple and saves messing about with various config files. Note zram is automatically built in to any kernel these days.

There are some other kernel parmeters but those are only worth using if you have an absolutely lightning fast PC. This method should give a big performance boost on standard machines.

if it works properly type lsblk on the console and you should see something like this

Screenshot_20231106_115650.png

For the more technical ones -- if you have plenty of RAM you can use ZRAM for "Normal RAM" rather than as a swap and you can have multiple ZRAM devices. This leads to the interesting idea of perhaps being able to install a Windows VM on it -- should in theory absolutely make Windows fly since it's operating in RAM rather than from HDD's / SSD's etc.


I'll have a play with that later.

Cheers
jimbo
 

My Computer

System One

  • OS
    Windows XP,7,10,11 Linux Arch Linux
    Computer type
    PC/Desktop
    CPU
    2 X Intel i7
Back
Top Bottom