这zswap 文档说:
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.
这指定了最大限度压缩池可以占用的内存百分比。
我如何得知:
- 这当前的压缩池占用的内存百分比
- 该池有多少空间正在使用中
- 压缩率、命中率和其他有用信息
答案1
目前统计:
# grep -R . /sys/kernel/debug/zswap/
压缩率:
# cd /sys/kernel/debug/zswap
# perl -E "say $(cat stored_pages) * 4096 / $(cat pool_total_size)"
当前的设置:
$ grep -R . /sys/module/zswap
答案2
创造/usr/local/bin/zswap内容:
#!/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
使文件可执行(# chmod 755 /usr/local/bin/zswap)并启动它。例子:
# 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