From Fedora Project Wiki

(Create zswap page)
 
m (lz4=>lz4hc)
 
(2 intermediate revisions by 2 users not shown)
Line 3: Line 3:
Contrary to [[Zram|zram]], zswap eventually swaps out the compressed pages to disk. This behaviour can be configured by setting <code>vm.swappiness</code> inside <code>/etc/sysctl.conf</code>. One of the advantages of zswap over zram is that zswap requires no additional configuration in order to allow system hibernation.
Contrary to [[Zram|zram]], zswap eventually swaps out the compressed pages to disk. This behaviour can be configured by setting <code>vm.swappiness</code> inside <code>/etc/sysctl.conf</code>. One of the advantages of zswap over zram is that zswap requires no additional configuration in order to allow system hibernation.


== Enabling lz4 ==
== Enabling lz4hc ==


The lz4 algorithm is one of the fastest in terms of compression and decompression out there. The compression ratio is not the highest but it's the clear winner when both compression ratio and speed are taken into consideration. This is specially important in this setting where speed is critical. Some benchmarks [https://linuxaria.com/article/linux-compressors-comparison-on-centos-6-5-x86-64-lzo-vs-lz4-vs-gzip-vs-bzip2-vs-lzma] [https://catchchallenger.first-world.info/wiki/Quick_Benchmark:_Gzip_vs_Bzip2_vs_LZMA_vs_XZ_vs_LZ4_vs_LZO]
The lz4 algorithm is one of the fastest in terms of compression and decompression out there. The compression ratio is not the highest but it's the clear winner when both compression ratio and speed are taken into consideration. This is specially important in this setting where speed is critical. Some benchmarks [https://linuxaria.com/article/linux-compressors-comparison-on-centos-6-5-x86-64-lzo-vs-lz4-vs-gzip-vs-bzip2-vs-lzma] [https://catchchallenger.first-world.info/wiki/Quick_Benchmark:_Gzip_vs_Bzip2_vs_LZMA_vs_XZ_vs_LZ4_vs_LZO]
Line 10: Line 10:
<pre>
<pre>
$ su -
$ su -
$ modprobe lz4 lz4_compress
$ modprobe lz4hc lz4hc_compress
</pre>
</pre>


To enable lz4 permanently, simply tell dracut to include the lz4 kernel modules in the initramfs files. Create a file <code>/etc/dracut.conf.d/lz4.conf</code> with the following contents:
To enable lz4hc permanently, simply tell dracut to include the lz4hc kernel modules in the initramfs files. Create a file <code>/etc/dracut.conf.d/lz4hc.conf</code> with the following contents:
<pre>
<pre>
add_drivers+="lz4 lz4_compress"
add_drivers+="lz4hc lz4hc_compress"
</pre>
</pre>


Line 26: Line 26:
== Enabling zswap ==
== Enabling zswap ==


By default zswap uses ''lzo'' as the compression algorithm. If you to use any other compressor during runtime, for example ''lz4'', run:
By default zswap uses ''lzo'' as the compression algorithm. If you to use any other compressor during runtime, for example ''lz4hc'', run:
<pre>
<pre>
$ su -
$ su -
# echo lz4 > /sys/module/zswap/parameters/compressor
# echo lz4hc > /sys/module/zswap/parameters/compressor
</pre>
</pre>


Line 44: Line 44:
Permanently enabling zswap is very easy. Add the following contents to the kernel arguments in <code>/etc/default/grub</code>
Permanently enabling zswap is very easy. Add the following contents to the kernel arguments in <code>/etc/default/grub</code>
<pre>
<pre>
GRUB_CMDLINE_LINUX=" ... zswap.enabled=1 zswap.max_pool_percent=25 zswap.compressor=lz4"
GRUB_CMDLINE_LINUX=" ... zswap.enabled=1 zswap.max_pool_percent=25 zswap.compressor=lz4hc"
</pre>
</pre>


Where <code>zswap.max_pool_percent=25</code> and <code>zswap.compressor=lz4</code> can be configured to suit your preferences or omitted entirely. Finally update your grub2 configuration at your boot partition by following [[Grub 2]] instructions for EFI or MBR systems.
Where <code>zswap.max_pool_percent=25</code> and <code>zswap.compressor=lz4</code> can be configured to suit your preferences or omitted entirely. Finally update your grub2 configuration at your boot partition by following [[GRUB 2]] instructions for EFI or MBR systems.

Latest revision as of 15:18, 8 July 2020

Since version 3.11 the Linux kernel offers zswap support. If enabled, the kernel will avoid swapping out pages to disk by compressing them in ram. This will reduce disk I/O which can make systems with mechanical disks feel more responsive or lower the wear of flash based disks. The compressed memory pool is dynamically managed by the kernel. Basically it creates an intermediary memory system between the ram and the disk. This intermediate memory system is more cpu intensive than any of the other two. Although the compressed memory is slower than ram, it's still much faster than mechanical or flash based disks. Latency, compression ratio and speed are dependent on the compressor used with zswap.

Contrary to zram, zswap eventually swaps out the compressed pages to disk. This behaviour can be configured by setting vm.swappiness inside /etc/sysctl.conf. One of the advantages of zswap over zram is that zswap requires no additional configuration in order to allow system hibernation.

Enabling lz4hc

The lz4 algorithm is one of the fastest in terms of compression and decompression out there. The compression ratio is not the highest but it's the clear winner when both compression ratio and speed are taken into consideration. This is specially important in this setting where speed is critical. Some benchmarks [1] [2]

lz4 kernel support can be enabled during runtime using the following commands

$ su -
$ modprobe lz4hc lz4hc_compress

To enable lz4hc permanently, simply tell dracut to include the lz4hc kernel modules in the initramfs files. Create a file /etc/dracut.conf.d/lz4hc.conf with the following contents:

add_drivers+="lz4hc lz4hc_compress"

Now regenerate all of your initramfs images

$ su -
# dracut --regenerate-all --force

Enabling zswap

By default zswap uses lzo as the compression algorithm. If you to use any other compressor during runtime, for example lz4hc, run:

$ su -
# echo lz4hc > /sys/module/zswap/parameters/compressor

In a similar way you can configure the maximum size of the compressed memory pool with respect to the total ram available in your the system. In this example 25 means that zswap can use up to 25% of your total ram for storing compressed memory pages.

# echo 25 > /sys/module/zswap/parameters/max_pool_percent

Now if you want to enable zswap at runtime just run this

# echo 1 > /sys/module/zswap/parameters/enabled

Permanently enabling zswap is very easy. Add the following contents to the kernel arguments in /etc/default/grub

GRUB_CMDLINE_LINUX=" ... zswap.enabled=1 zswap.max_pool_percent=25 zswap.compressor=lz4hc"

Where zswap.max_pool_percent=25 and zswap.compressor=lz4 can be configured to suit your preferences or omitted entirely. Finally update your grub2 configuration at your boot partition by following GRUB 2 instructions for EFI or MBR systems.