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.