28

How can I check to verify that zswap is enabled and working on my system?

Rucent88
  • 1,978

3 Answers3

26
sudo dmesg | grep zswap

That should be all you need to know if it's running. You should see a message along the lines of:

[    1.241302] zswap: loading zswap
[    1.241306] zswap: using zbud pool
[    1.241310] zswap: using lzo compressor

On Ubuntu 20.04 and later, the dmesg output is even shorter, like this:

[    1.802721] zswap: loaded using pool lzo/zbud

You can see what it's doing with the following:

$ sudo grep -R . /sys/kernel/debug/zswap
/sys/kernel/debug/zswap/stored_pages:0
/sys/kernel/debug/zswap/pool_total_size:0
/sys/kernel/debug/zswap/duplicate_entry:0
/sys/kernel/debug/zswap/written_back_pages:0
/sys/kernel/debug/zswap/reject_compress_poor:0
/sys/kernel/debug/zswap/reject_kmemcache_fail:0
/sys/kernel/debug/zswap/reject_alloc_fail:0
/sys/kernel/debug/zswap/reject_reclaim_fail:0
/sys/kernel/debug/zswap/pool_limit_hit:0

The key parameters to look out for are stored_pages which is the number of compressed pages and written_back_pages which is the number of pages which have been written out to the swap file.

Artur Meinild
  • 26,018
Oli
  • 293,335
  • 1
    dmesg | grep zswap shows nothing on my system (Ubuntu 18.04), but sudo grep -r . /sys/kernel/debug/zswap shows zswap is working. – scoobydoo Jul 12 '19 at 05:21
  • @scoobydoo Same as you. Do you know the reason? – ife Jun 09 '21 at 03:54
  • 1
    @吴毅凡 not sure but now with Ubuntu 20.04 dmesg | grep zswap does show that zswap is loaded: [ 1.802721] zswap: loaded using pool lzo/zbud – scoobydoo Jun 10 '21 at 07:33
  • I am looking at this data, but still not sure what it means: What is stored_pages, written_back_pages, pool_total_size? – ctrl-alt-delor Feb 20 '22 at 11:40
  • Hello! It looks like someone copied your answer, along with the question, to another site without giving attribution. It's at https://ubuntuusa.com/questions/23672/173/How-to-verify-zswap-running , in case you want to contact them. I tried contacting SE, but they said they don't do anything in cases like this anymore. – Someone Oct 18 '23 at 01:58
  • This won't work if zswap has been modified at runtime. See my answer. – Alberto Salvia Novella Feb 10 '24 at 23:52
5

Shell expansion is a weird thing sometimes. grep fortunately have a recursive option so to simplify it:

sudo grep -r . /sys/kernel/debug/zswap
1

The other answers are wrong if zswap has been modified at runtime.

For checking under any circumstance:

cat /sys/module/zswap/parameters/enabled