Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between ZRAM and ZSWAP [closed]

Tags:

linux-kernel

Does anyone know what is the difference between feature ZRAM and ZSWAP in linux kernel? Seems they are very similar-- store compressed pages in ram.

like image 699
user1391731 Avatar asked Aug 26 '13 05:08

user1391731


People also ask

Is zram better than swap?

Senior Member. So let's start this off by explaining both of them. Zram basically compresses unused apps within the system RAM. This allows the system to swap less needed processes to the Zram partition for faster access at a later time, instead of killing them.

What is the purpose of zram?

On Android, there is no swap! In ZRAM unnecessary storage resources are compressed and then moved to a reserved area in the fixed RAM (ZRAM). So a kind of swap in memory. This Ram is more free because the data then only about 1/4 of the former storage requirements have.

What is Linux zram?

zram (previously called compcache) is a Linux kernel feature and userspace tools for creating compressible RAM-based block devices. It has been included as a module of the mainline Linux since kernel version 3.14.

What is zram writeback?

writeback. With CONFIG_ZRAM_WRITEBACK, zram can write idle/incompressible page to backing storage rather than keeping it in memory. To use the feature, admin should set up backing device via: echo /dev/sda5 > /sys/block/zramX/backing_dev. before disksize setting.


2 Answers

zram

  • Status: Available in mainline kernel as of version 3.14 (March 2014)

  • Implementation: compressed block device, memory is dynamically allocated as data is stored

  • Usage: Configure zram block device as a swap device to eliminate need for physical swap defice or swap file

  • Benefits:

    1. Eliminates need for physical swap device. This beame popular when netbooks first showed up. Zram (then compcache) allowed users to avoid swap shortening the lifespan of SSDs in these memory constrained systems.

    2. A zram block device can be used for other applications other than swap, anything you might use a block device for conceivably.

  • Drawbacks:

    1. Once a page is stored in zram it will remain there until paged in or invalidated. The first pages to be paged out will be the oldest pages (LRU list), these are 'cold' pages that are infrequently access. As the system continues to swap it will move on to pages that are warmer (more frequently accessed), these may not be able to be stored because of the swap slots consumed by the cold pages. What zram can not do (compcache had the option to configure a block backing device) is to evict pages out to physical disk. Ideally you want to age data out of the in-kernel compressed swap space out to disk so that you can use kernel memory for caching warm swap pages or free it for more productive use.

zswap

  • Status: Available in mainline kernel as of version 3.11 (September 2013)

  • Implementation: compressed in-kernel cache for swap pages. In-kernel cache is compressed, the compression algorithm is pluggable using the CryptoAPI and the storage for pages is dynamically allocated. Older pages can be evicted to disk making this a sort of write-behind cache.

  • Usage: Cache swap pages destined for regular swap devices (or swap files).

  • Benefits:

    1. Integration with swap code (using Frontswap API) allows zswap to choose to store only pages that compress well and handle memory allocation failures, in those cases pages are sent to the backing swap device.

    2. Oldest pages in the cache are pushed out to backing swap device to make room for newer pages, this solves the LRU inversion problem that a lack of page eviction would present.

  • Drawbacks:

    1. Needs a physical swap device (or swapfile).
like image 81
ava1ar Avatar answered Sep 28 '22 03:09

ava1ar


ZRAM is a module of the Linux kernel, previously called "compcache". ZRAM increases performance by avoiding paging on disk and instead uses a compressed block device in RAM in which paging takes place until it is necessary to use the swap space on the hard disk drive. Since using RAM is faster than using disks, zram allows Linux to make more use of RAM when swapping/paging is required, especially on older computers with less RAM installed.

ZSWAP is a lightweight compressed cache for swap pages. It takes pages that are in the process of being swapped out and attempts to compress them into a dynamically allocated RAM-based memory pool. zswap basically trades CPU cycles for potentially reduced swap I/O. This trade-off can also result in a significant performance improvement if reads from the compressed cache are faster than reads from a swap device.

like image 43
Gopal Singh Dagur Avatar answered Sep 28 '22 03:09

Gopal Singh Dagur