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.
kernel CONFIG:
CONFIG_ZSMALLOC=y
CONFIG_PGTABLE_MAPPING=y
CONFIG_ZRAM=y
CONFIG_ZRAM_LZ4_COMPRESS=y
First,enable the kernel swap function support:CONFIG_SWAP=y
then,enable zram support(similar to "First")。
zram swap, opening under a system:
echo 100 > /proc/sys/vm/swappiness
echo 8388608 > /sys/block/zram0/disksize
mkswap /dev/zram0
swapon /dev/zram0
disksize is the zram block device's size,30% of a system memory is recommended. Its maximum value can not exceed twice of the system's maximum memory.
cat /proc/swaps display the swap's usezram 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.