{"id":393,"date":"2020-08-27T10:35:37","date_gmt":"2020-08-27T09:35:37","guid":{"rendered":"https:\/\/blog.thomarite.uk\/?p=393"},"modified":"2020-08-31T20:49:00","modified_gmt":"2020-08-31T19:49:00","slug":"zswap","status":"publish","type":"post","link":"https:\/\/blog.thomarite.uk\/index.php\/2020\/08\/27\/zswap\/","title":{"rendered":"ZSWAP"},"content":{"rendered":"\n<p>Yesterday read for first time an article about <a href=\"https:\/\/medium.com\/for-linux-users\/linux-tip-higher-performance-with-zswap-2a4654b935de\">zswap<\/a>. I though it was something new, but a bit search showed that it started around 2013 as per this <a href=\"https:\/\/lwn.net\/Articles\/537422\/\">article<\/a>.<\/p>\n\n\n\n<p>I have a 2015 Dell XPS13 with i7, 128GB SSD and 8GB RAM. But some times my systems struggle with memory and when swapping kicks in, the system gets stuck. I have used <a href=\"https:\/\/linuxhint.com\/understanding_vm_swappiness\/\">swappiness<\/a> in the past but not much improvement (or it was in my former company laptop??). Anyway this is my current swappiness:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># cat \/proc\/sys\/vm\/swappiness\n60\n# sysctl vm.swappiness\nvm.swappiness = 60\n<\/pre>\n\n\n\n<p>Even having &#8220;suspender&#8221; enabled in Chrome, I just have over 2GB RAM free.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ top\ntop - 10:23:14 up 6 days, 1:54, 1 user, load average: 0.23, 0.41, 0.44\nTasks: 333 total, 1 running, 332 sleeping, 0 stopped, 0 zombie\n%Cpu(s): 0.7 us, 0.2 sy, 0.0 ni, 99.1 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st\nMiB Mem : 56.6\/7933.8 [||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ]\nMiB Swap: 1.3\/6964.0 [| ]<\/pre>\n\n\n\n<p>Ok, check you have ZSWAP available in your kernel.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ uname -a\nLinux x 5.7.0-2-amd64 #1 SMP Debian 5.7.10-1 (2020-07-26) x86_64 GNU\/Linux\n\n$ cat \/boot\/config-<code>uname -r<\/code> | grep -i zswap\nCONFIG_ZSWAP=y\n# CONFIG_ZSWAP_COMPRESSOR_DEFAULT_DEFLATE is not set\nCONFIG_ZSWAP_COMPRESSOR_DEFAULT_LZO=y\n# CONFIG_ZSWAP_COMPRESSOR_DEFAULT_842 is not set\n# CONFIG_ZSWAP_COMPRESSOR_DEFAULT_LZ4 is not set\n# CONFIG_ZSWAP_COMPRESSOR_DEFAULT_LZ4HC is not set\n# CONFIG_ZSWAP_COMPRESSOR_DEFAULT_ZSTD is not set\nCONFIG_ZSWAP_COMPRESSOR_DEFAULT=\"lzo\"\nCONFIG_ZSWAP_ZPOOL_DEFAULT_ZBUD=y\n# CONFIG_ZSWAP_ZPOOL_DEFAULT_Z3FOLD is not set\n# CONFIG_ZSWAP_ZPOOL_DEFAULT_ZSMALLOC is not set\nCONFIG_ZSWAP_ZPOOL_DEFAULT=\"zbud\"\n# CONFIG_ZSWAP_DEFAULT_ON is not set\n\n$ cat \/sys\/module\/zswap\/parameters\/enabled\nN<\/pre>\n\n\n\n<p>If you have &#8220;N&#8221;in the last command and &#8220;CONFIG_ZSWAP=y&#8221; then your systems supports zswap but it is not enabled.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ echo Y | sudo tee \/sys\/module\/zswap\/parameters\/enabled\n\n$ cat \/sys\/module\/zswap\/parameters\/enabled\nY<\/pre>\n\n\n\n<p>Now you can tune some parameters to increase compression rate (3:1)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># list all parameters\ngrep . \/sys\/module\/zswap\/parameters\/*\n\n# change  compression params\necho z3fold | sudo tee \/sys\/module\/zswap\/parameters\/zpool\necho lzo | sudo tee \/sys\/module\/zswap\/parameters\/compressor<\/pre>\n\n\n\n<p>How to check zswap is working? I  followed this <a href=\"https:\/\/lkml.org\/lkml\/2013\/7\/17\/147\">email<\/a> thread to find some clues:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># cd \/sys\/kernel\/debug\/zswap\n\n\/sys\/kernel\/debug\/zswap# grep . *\nduplicate_entry:0\npool_limit_hit:0\npool_total_size:237568\nreject_alloc_fail:0\nreject_compress_poor:0\nreject_kmemcache_fail:0\nreject_reclaim_fail:0\nsame_filled_pages:33\nstored_pages:151\nwritten_back_pages:0\n\n###############\n## 12h later ##\n###############\n\n\/sys\/kernel\/debug\/zswap# grep . *\nduplicate_entry:0\npool_limit_hit:0\npool_total_size:17944576\nreject_alloc_fail:0\nreject_compress_poor:8\nreject_kmemcache_fail:0\nreject_reclaim_fail:0\nsame_filled_pages:4146\nstored_pages:16927\nwritten_back_pages:0<\/pre>\n\n\n\n<p>So it seems some values are increasing.<\/p>\n\n\n\n<p>The difficult part seems to make this change to survive a reboot. The easy way, it is just to update &#8220;\/etc\/rc.local&#8221;.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># cat \/etc\/rc.local\n....\n# enabling zswap - 2020-08\necho Y >\/sys\/module\/zswap\/parameters\/enabled\necho z3fold >\/sys\/module\/zswap\/parameters\/zpool<\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday read for first time an article about zswap. I though it was something new, but a bit search showed that it started around 2013 as per this article. I have a 2015 Dell XPS13 with i7, 128GB SSD and 8GB RAM. But some times my systems struggle with memory and when swapping kicks in, &hellip; <a href=\"https:\/\/blog.thomarite.uk\/index.php\/2020\/08\/27\/zswap\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;ZSWAP&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-393","post","type-post","status-publish","format-standard","hentry","category-unix"],"_links":{"self":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/393","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/comments?post=393"}],"version-history":[{"count":1,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/393\/revisions"}],"predecessor-version":[{"id":394,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/393\/revisions\/394"}],"wp:attachment":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/media?parent=393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/categories?post=393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/tags?post=393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}