Another interesting to “oprex” :
Summary of what to use when:
- ZRAM if you have no HDD/SSD swap partition.
- ZSWAP if you do have a HDD/SSD swap partition.
- ZCACHE: It does what ZSWAP does and ALSO compresses and speeds the filesystem page cache. (It is internally much more complicated and is not in the mainline kernel as it is still under development).
Summary of their implementations:
- ZRAM is a compressed RAM based swap device
- ZSWAP is a compressed Cache if you already have a swap.
- ZCache is a backend for a special type of Virtual RAM thingy (Transcendent memory) that can be used to cache filesystem pages or swap data.
- ZRAM: Makes a swap device in the RAM. Pages sent here are compressed as they are stored. It has a higher priority than other swap devices: pages that are swapped out are preferentially sent to the zram device till it is full, only then are any other swap devices used.
- Benefits: Independent of other (physical) swap devices. It can be used when there is no swap partition to expand the available memory.
- Disadvantages: If other swap devices (HDD/SSD) are present they are not used optimally. As the zram device is an independent swap device, once it is full, any new pages that need to be swapped out are sent to next swap device directly, hence:
- There is a real chance of LRU (least recently used) inversion: It will be the most recently swapped data that goes to the slow disk, while inactive pages that were swapped out long ago will remain in the fast ZRAM
- The data sent to and read from the disk will consume a lot of bandwidth as it is uncompressed.
- Status: Merged into the mainline kernel 3.14. Once enabled on a system, it requires some userspace configuration to set up the swap devices and use them.
- ZSWAP: The
frontswapsystem hooks attempts to swap out pages and uses zswap as write-back-cache for a HDD/SSD swap device: An attempt is made to compress the page and if it contains poorly compressible data it is directly written two the disk. If the data is compressed, it is stored in the pool of zswap memory. If pages are swapped out of memory when the total compressed pages in RAM exceeds a certain size, the Least Recently Used (LRU) compressed page is written to the disk as it is unlikely to be required soon.
- Benefits: Very efficient use RAM and disk based swap. Minimizes Disk I/O by both reducing the number of writes and reads required (data is compressed and held in RAM) and by reducing the bandwidth of these I/O operaions as the data is in a compressed form.
- Limitations: It is an enhancement of disk based swap systems and hence depends on a swap partition on the hard disk.
- Status: Merged into the 3.11 mainline linux kernel.
- ZCache: It is a backend for the Transcendent memory system. Transcendent memory provides a RAM-like memory that can only be accessed a page at a time by using
getcalls. This is unlike normal memory that can be accessed a byte at a time. The
cleancachesystems hook attempts to swap and reclaim file-system page caches respectively and send them to the transcendent memory backends. When zcache is used as a backend, the data is compressed and stored in the RAM. When it fills up, compressed pages are evicted to the swap. (an alternate backend is RAMster which shares a pool of RAM across networked computers). Using only the
frontswapfrontend with the
zcachebackend works just like
zswap. (In fact zswap is a simplified subset of zcache)
- Benefits Provides compressed caching both for swap and for filesystem caches.
- Status: Still not mainlined as it is very complicated and is being worked on.
The best resources I found were: