ZRAM – Ultimate Guide: zram vs zswap vs zcache

kernelperformanceramswap

  1. What the hell are they? how are they different (I've written my understanding in an answer below)
  2. In the Zswap system, when a page is evicted from the zswap to the actual swap is it stored in a compressed from? (or is it decompressed before storing?, AFAICT it is still compressed but i can't be sure)
  3. What is the current state of zcache? it was apparently removed or something in 3.11. What does this mean? (http://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/commit/?id=96256460487387d28b8398033928e06eb9e428f7)

Best Answer

Regarding 2., zswap does seem to decompress the pages on write-back, confirming @Cbhihe's comment.

mm/zswap.c, line 828:

/*
 * Attempts to free an entry by adding a page to the swap cache,
 * decompressing the entry data into the page, and issuing a
 * bio write to write the page back to the swap device.
 * ...
 */
static int zswap_writeback_entry(struct zpool *pool, unsigned long handle)
{
    ...
    
    case ZSWAP_SWAPCACHE_NEW: /* page is locked */
        /* decompress */
        ...
        
        ret = crypto_comp_decompress(tfm, src, entry->length,
                         dst, &dlen);
        ...
        kunmap_atomic(dst);    


$ git show
commit 1573d2caf713874cfe0d1336c823d0fb548d8bed
Merge: 4cdf8db 0a86248
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date:   Tue Oct 11 23:59:07 2016 -0700

So zswap is useful for situations where the compressed in-ram cache is likely to be forgotten soon before written back to disk. It is not for applications with large, long living heaps that will eventually need to be backed by the actual swap device.

Related Question