As we all know, the bottleneck of modern computer is hard disk, and Linux system in the design, in order to high-load security at the expense of performance, using virtual memory swap as a stopgap measure, not the system lack of available memory crashes, the results can be imagined that once the swap to the hard disk will be slow as cattle, The performance will go straight down. So theoretically, once you use swap, it means you should add a memory bar.
Zram is the gospel of the poor, a part of physical memory virtual into a special compression function of the block device (similar to TMPFS, but TMPFS does not have compression function), as a swap partition, by compressing the swap to obtain additional performance improvement, compression ratio of about 3:1.
Zram officially entered the production state at the start of Linux kernel 3.13. Ubuntu 14.04.5 kernel is 3.16, can be assured to use Zram. In fact, many companies have started using zram very early.
1, the Import module Zram, will produce a new block device/dev/zram0
Modprobe Zram
2, adjust the capacity, the use of 512M memory here
echo 1024M >/sys/block/zram0/disksize
3. Create a Swap partition
Mkswap/dev/zram0
4. Mount the Swap partition
Swapon-p 100/dev/zram0
Using the Free-m command, you can find that the swap partition is more 512m,-p than the priority, and the value is about the higher the priority level.
If the swap exceeds 512M, it will be the same as the Linux preset: the system slows down. After all, Zram is not a silver bullet.
In addition, Zram can be used to a certain extent in place of TMPFS, such as the/TMP partition, not detailed.
Reference documents
Https://wiki.gentoo.org/wiki/Zram
This article is from the "Focus on Linux Operations" blog, please be sure to keep this source http://purplegrape.blog.51cto.com/1330104/1708945
Ubuntu 14.04 using Zram