10

I don't fully understand the functionality and the potential advantages of zram.

For example: once zram is activated, what percentage of memory will be dedicated to paging?

Another issue: obviously the total ram size is the upper bound of swap file in ram. Once it is exhausted, will the system begin to swap on regular swap partitions (if present)?

What are the main disadvantages of zram?

Note: I have 32gb of physical memory and 20Gb of swap partition. I use very memory-hungry programs, and often I run out of memory (top command shows both physical and swap almost full, and system slows a lot).

Thanks.

1 Answer 1

15

zram creates a virtual block device of a size you specify by writing ( for example "512m" ) to /sys/block/zramX/disksize ( where X is the 0 based number of the zram device in question, so 0 for the first one ).

You can then format it for swap with mkswap /dev/zram0 and enable swapping on it with swapon /dev/zram0. Data written to it will be compressed and stored in RAM. The compressed data itself can not be swapped out. Note that not all data is compressible.

Which swap device is used up first is up to their priority, which you can specify with the -p xx argument to swapon. A swap with higher priority will be filled before a lower one so it is a good idea to give zwap a high priority so it will be used up before falling back to a disk swap.

3
  • 1
    Very clear answer, I'll accept it. Just a few things: First, what do you exactly mean by "compressed data itself cannot be swapped out"? Second, is it a good idea to use zram and zcache together? Three, should I lower the swappiness value when I use zram? Thanks a lot.
    – MadHatter
    May 19, 2015 at 14:04
  • 3
    @MadHatter, when the kernel swaps data out to the zram device, it then compresses that data and keeps it in ram. It can not then be swapped out again ( to disk or otherwise ). zcache is kind of a better solution than zram. The one thing zram can do that zcache can't is run without any on disk swap. Lowering the swappiness value sacrifices the disk cache in favor of NOT swapping, which kind of defeats the purpose of zram. If anything, I'd turn it up.
    – psusi
    May 19, 2015 at 22:31
  • What's the difference between /sys/block/zramX/disksize and /sys/block/zramX/size ?
    – Thushi
    Sep 27, 2019 at 16:07

You must log in to answer this question.

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