I looked up zram since this was the first time I'd heard of it, and it seems like a much better alternative to a standard swap partition. However, I couldn't find much on setting it up. Do you have any advice or resources on doing so?
using the standard set of tools most distros have and a kernel with zram compiled as module and sysfs:
modprobe/kmod zram num_devices=(number of CPUs)
this will create {0..number of CPUs - 1} zram devices with the size of zero
then to set their size you can simply write the value you need into disksize
e.g. 2GB for device zero:
echo 2G > /sys/block/zram0/disksize
note here that this is more of a "maximum value" and the space is only allocated when it's actually needed.
then to set up the swap area (expecting that the dev nodes were created):
mkswap /dev/zram0
to activate it for use by the kernel
swapon /dev/zram0 -p 10
(this requires the linux kernel userland utilities which are usually installed)
- to activate the swap partition, - interesting here is the priority flag which tells the kernel what swap device to fill up first/prefer. The higher number devices are preferred, then come the lower number devices. By default this value is -1 which is lowest priority. If you system uses some harddrive swap with no priority set, this makes sure the zram swap partition is chosen over it. This is not as clean cut with modern kernels, it still doesn't hurt to give it a hint that the zram device is in fact fastest. If you have a multicore machine and have one zram device set up per core, setting all these zram devices to the same priority will make the kernel share the data between the devices, kinda like RAID striping. This will make it possible for the scheduler to split the compression/decompression workload over the different cores if necessary/useful, hence why multiple zram devices.
repeat/automate as necessary for the other zwap devices and sizes in scripting language of choice.
So actually pretty simple, these steps can easily be reversed to disable zram swap again. You can also add entries in fstab to activate swap that way, but I personally find it easier to script it and in my setup this is in a "do once on boot" setup script I've written for runit. There doesn't need to be any clean-up at shutdown since the memory gets freed/lost anyways. To translate these instructions into a preferred scripting language/instructions for some service manager is left as an exercise to the reader.