logoalt Hacker News

antongriboktoday at 2:06 AM1 replyview on HN

I think more people should know about the existence of ZRAM on modern Linux distributions. It's really changed the way I look at swap configs.

ZRAM is a compressed block device that is stored in RAM. It's great!

Previously, if I ever had high memory pressure situations, I really dreaded the slowdowns. Now, with swap sitting on top of /dev/zram0 it's a completely different experience.

I have ZRAM enabled on all of my personal machines, both laptops with limited memory, and desktops with 64 or 128GB of RAM. It's rarely used, but it is nice to have that extra room sometimes.

The performance of a zram device is so much faster than even the latest NVMe drives.


Replies

justinsaccounttoday at 2:36 AM

One interesting thing with zram (which OS X also does by default) is that certain memory leaks... effectively don't. I have a little raspberry pi where I have zram enabled. If I make a string in python and keep appending 'a's to it, eventually zram just soaks it up:

  $ zramctl
  NAME       ALGORITHM DISKSIZE  DATA COMPR TOTAL STREAMS MOUNTPOINT
  /dev/zram0 zstd          3.8G  2.3G 13.2M 17.2M       4 [SWAP]
2.3GB of 'a's that gets compressed down to 20MB.