27

The zswap documentation says:

Zswap seeks to be simple in its policies.  Sysfs attributes allow for one user
controlled policy:
* max_pool_percent - The maximum percentage of memory that the compressed
    pool can occupy.

This specifies the maximum percentage of memory the compressed pool can occupy.

How do I find out:

  • The current percentage of memory occupied by the compressed pool
  • How much of this pool is in use
  • Compression ratios, hit rates, and other useful info
Tom Hale
  • 28,728
  • 32
  • 139
  • 229

2 Answers2

35

Current statistics:

# grep -R . /sys/kernel/debug/zswap/

Compression ratio:

# cd /sys/kernel/debug/zswap
# perl -E  "say $(cat stored_pages) * 4096 / $(cat pool_total_size)"

Current settings:

$ grep -R . /sys/module/zswap
Tom Hale
  • 28,728
  • 32
  • 139
  • 229
James
  • 531
  • 4
  • 3
1

Create /usr/local/bin/zswap with content:

#!/bin/bash

MDL=/sys/module/zswap
DBG=/sys/kernel/debug/zswap
PAGE=$[`cat $DBG/stored_pages`*4096]
POOL=$[`cat $DBG/pool_total_size`]

Show(){
    printf "========\n$1\n========\n"
    grep -R . $2 2>&1 | sed 's|.*/||'
}

Show Settings $MDL
Show Stats    $DBG

printf "\nCompression ratio: "

[ $POOL -gt 0 ] && {
     echo "scale=3;$PAGE/$POOL" | bc
} || echo zswap disabled

Make the file executable (# chmod 755 /usr/local/bin/zswap) and launch it. Example:

# zswap
========
Settings
========
uevent: Permission denied
same_filled_pages_enabled:Y
enabled:Y
max_pool_percent:20
compressor:zstd
zpool:zbud
accept_threshold_percent:90
========
Stats
========
same_filled_pages:72227
stored_pages:394760
pool_total_size:660660224
duplicate_entry:0
written_back_pages:0
reject_compress_poor:345
reject_kmemcache_fail:0
reject_alloc_fail:0
reject_reclaim_fail:0
pool_limit_hit:0

Compression ratio: 2.447