3

I'm thinking about using zRam on my server. From what I've read about zRam, it apparently does everything tmpfs does and more.

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?

3

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 swap (including swap on 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.

Using 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 ;)

0

You will get better performance from using zram for swap due to the compression that is possible.

zram-init makes zram simple to use. Remember to read the instructions.

Your kernel needs to be built with CONFIG_ZRAM_LZ4_COMPRESS enabled to be able to benefit from lz4 compression.

I use zram for swap & for /tmp (zram-init uses sensible default mount options for /tmp):

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 lxc containers:

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)
  • What you say is true. But I don't see how it's relevant to my question about tmpfs. Did you perhaps mean to post this as an answer to some other question? – David Cary Feb 4 '16 at 4:23
  • @David Cary - answer expanded – Stuart Cardall Feb 4 '16 at 17:54
  • 1
    Is "There is never any reason to use tmpfs. Instead, zram is just as easy to use and gives better performance" a valid summary? Because I'm not seeing any reasons to use tmpfs in your answer. (It may be obvious to you the reasons why using tmpfs is a great idea "for bind mounting volumes with secure mount options into lxc containers", but I wish you would tell me what those reasons are. Or is there no actual reason, and you're still doing it that way only because you haven't had time to convert that system zram?) – David Cary Feb 8 '16 at 0:08
  • perhaps you should try actually using them both. – Stuart Cardall Feb 9 '16 at 1:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.