Once zRAM is working, is there any reason to keep tmpfs around? Is there anything tmpfs does that zRAM can't do? Is there ever a reason to use tmpfs instead of or in addition to zRAM?
Data written to a
tmpfs will be kept in-memory uncompressed as long as enough memory is available. Once the system comes under memory pressure, it tries to move data from the
tmpfs (and from any other places, like normal process memory) to any
zram) it can find. Also you can change parameters of a
tmpfs by doing a simple
mount -o remount, especially the size of the file system or the number of inodes.
zram as the backing of a temporary file system has the disadvantage, that all data written there needs to be compressed immediatelly (and decompressed upon use). Also you need to put a file system on top, whiches structures need to be stored even if there are no actual files stored. Also you get limitations like max number of inodes, you can't easily change it's size and so on.
IMHO, best solution is to mount
tmpfs somewhere to use and create a
zram swap. It combines the advantages of both by minimizing the disadvantages.
Or buy more ram of couse ;)
You will get better performance from using
swap due to the compression that is possible.
Your kernel needs to be built with
CONFIG_ZRAM_LZ4_COMPRESS enabled to be able to benefit from
swap & for
zram-init uses sensible default mount options for
root@alpine [~]# cat /proc/swaps Filename Type Size Used Priority /dev/vda7 partition 1045500 0 -1 /dev/zram0 partition 1048572 0 16383 root@alpine [~]# mount|grep zram /dev/zram1 on /tmp type ext4 (rw,nosuid,nodev,noexec,discard)
There are still use cases for using
tmpfs. I use these for bind mounting volumes with secure mount options into
root@http [~]# mount|grep tmpfs tmpfs on /var/www/domain.com/bin type tmpfs (ro,nosuid,nodev,relatime,size=200k) tmpfs on /var/www/domain.comm/dev type tmpfs (rw,nosuid,relatime,size=4k,mode=755)