6

Running Ubuntu 12.10 here, on an 128Gb SSD and a 4GB RAM system. Ever since I installed the OS, I realised that I dont need the swap partition, as I never use the hibernate function and rarely run out of RAM. However, would installing zRam bring any real improvement when RAM is full, even if there is no swap partition?

2
  • Using zRAM On Ubuntu 13.04 Linux phoronix.com/scan.php?page=news_item&px=MTM1NjQ
    – Qasim
    May 21, 2013 at 1:44
  • I'm running 16.10 with 8GB ram and still found zram made everything more 'peppy'. I have a 10 year old laptop with 1.5GB RAM and it seems to me that the more the RAM, the more effective zram is. Nov 10, 2016 at 21:55

6 Answers 6

12

I would presume whether or not you have swap space is more or less irrelevant to the usefulness of zRam. Regardless of whether or not you have zRam installed, if you run out of RAM with no swap space, bad things start to happen. :-)

If you do expect to run out of RAM, then zRAM could be helpful because it essentially expands the amount of data you can store in RAM (assuming it's not of unreasonably high entropy) so it will take longer to fill up. So it might buy you some more time, assuming you're not storing large arrays of random numbers.

If you're 99.9% sure you won't get close to running out of RAM (i.e. you have 16GB on your web-only netbook), than anything stored in zRAM is needlessly requiring extra CPU time to compress and decompress, so it's not really beneficial in this case.

If you're on the high end of the RAM usage spectrum (on average over 50-60%, for example) you might benefit from some additional peace of mind using zRAM. (Or you could buy more RAM.)

I suppose you have to evaluate your normal and heavily-loaded RAM utilization (average and max) and what kind of data you work with.

4

Yes enabling zRAM is certainly a best thing.why means zRAM will creates a RAM based block device which acts as a swap disk, but is compressed and stored in memory instead of swap disk allowing very fast I/O and increasing the amount of memory available before the system starts swapping to disk.

Actually compcache is the original name and its changed to zRAM these days.

you can install it with sudo apt-get install zram-config

2

zRAM will only get used if it's needed, so enabling it will have no effect if you don't need it. I very much doubt you will even notice it working when it is needed.

2

It is NOT true that disabling swap is bad. Because if you running out of memory without swap OOM will be invoked and some of tasks just die, you can continue your work. In case with swap it's very easy to run out of memory + out of swap, in this case your machine will hang in disk IO. Most probably reasons you run out of memory (memory leak, huge allocation) - it wouldn't stop on RAM size, it will eat whole swap too and you will run out of memory anyway.

You could easily try this with simple program which allocates memory in infinity loop with and without swap.

2

I'd say that if Linux kernel did work perfectly, using zRam and no real swap would be probably pointless unless you know for a fact that the RAM contents will compress really well and you're a bit short on RAM.

However, I'm running system with 32 GiB of RAM, zero real swap and I've installed zram-config but modified /etc/init/zram-config.conf to use only 5% of RAM for zram (instead of default 50%). This allows kernel to see some swap but that swap is hugely faster than any SDD. As a result, all swap-related codepaths inside kernel can be used and I think this has fixed some issues that I had when I didn't have swap at all. (Namely, it seems to me that when RAM is fragmented and the system does not have any swap, the kernel is not clever enough to workaround the problem. However, with zRam or swap on ramdisk, the kernel is able to move pages to swap and relocate during swapin. That's only my theory, though.)

TL;DR: zRam in a system without real swap space allows kernel to use all swap related codepaths which may avoid some bugs.

2
  • 1
    Whoever downvoted this answer should explain his or her vote. If you feel that the answer is incorrect, please point out the error or fix the answer if you have enough reputation. Jan 14, 2019 at 17:41
  • 1
    After running with 5% of zRAM and zero real swap for half a year I can report that this has made my system more stable (currently running Ubuntu 4.15.0-60-lowlatency). Previously the system would live hang (technically not crashed but slow enough to be unusable) about once a month. Now the system will slow down when RAM is full but it will not crash or hang. I can also report that many leaky apps leak redundant memory contents and those compress really well. My total zRAM memory is 1.6 GB and effective swap size is often around 2-4 GB (that is, the number of pages swapped by processes). Oct 27, 2019 at 9:22
0

Swap is misunderstood.

As said in "in defence of swap" by a kernel developer, swap is always advantageous despite of machine.

zswap will spend some CPU resources on compression, but save plenty of IO, resulting almost warranted in a net benefit.

This is because any RAM which is not used is employed as storage cache. The more cache the less need to read the storage.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .