Ubuntu – ZRAM vs. regular swap partition

memory usageramswapzram

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.

Best Answer

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.

Related Question