zram Guide


zram is a memory compression technique provided by Linux kernel. zram is a standard logical block device. It can be used as a swap or formatted as a logical block device file system (vfat, ext2,...). zram can alleviate some of the problems caused by small memory embedded devices.

zram kernel support

kernel CONFIG:

CONFIG_ZSMALLOC=y
CONFIG_PGTABLE_MAPPING=y
CONFIG_ZRAM=y
CONFIG_ZRAM_LZ4_COMPRESS=y

zram swap

zram logical block device

zram can be used as a virtual logic block device, In addition to being a swap, it can be formatted as a logical block device file system, for example:

echo 100 > /proc/sys/vm/swappiness
echo 8388608 > /sys/block/zram0/disksize
mkfs.vfat /dev/zram0
mkdir /tmp/zram
mount /dev/zram0 /tmp/zram

This way, the zram vfat partition is successfully mounted. The advantage of this scheme is that certain applications require the use of /tmp/(TMPFS) as a temporary directory, but this method is a waste of memory. If you use compressed memory, you can get a higher memory utilization.