Skip to content

Instantly share code, notes, and snippets.

@kotet
Created Apr 30, 2020
Embed
What would you like to do?
Zswapの情報を若干見やすく表示するやつ
#!/usr/bin/python3
import os
if os.getuid() != 0:
print("error: you cannot perform this operation unless you are root.")
exit(1)
def read(path):
with open(path) as f:
return f.readline().strip()
def printstat(key, val):
print((key+":").ljust(30, " ")+val)
def prettysize(bytes):
return str(round(int(bytes)/(1024*1024), 3))+"MiB"
printstat("enabled", read("/sys/module/zswap/parameters/enabled"))
printstat("same filled pages enabled",
read("/sys/module/zswap/parameters/same_filled_pages_enabled"))
printstat("max pool", read("/sys/module/zswap/parameters/max_pool_percent")+"%")
printstat("compressor", read("/sys/module/zswap/parameters/compressor"))
printstat("zpool", read("/sys/module/zswap/parameters/zpool"))
print()
printstat("pool total size", prettysize(
read("/sys/kernel/debug/zswap/pool_total_size")))
stored = int(read("/sys/kernel/debug/zswap/stored_pages"))*4096
total = int(read("/sys/kernel/debug/zswap/pool_total_size"))
if total != 0:
printstat("compression ratio", str(round(stored/total, 4)))
else:
printstat("compression ratio", "NaN")
print()
printstat("same filled pages", read(
"/sys/kernel/debug/zswap/same_filled_pages"))
printstat("stored pages", read("/sys/kernel/debug/zswap/stored_pages"))
printstat("written back pages", read(
"/sys/kernel/debug/zswap/written_back_pages"))
printstat("reject compress poor", read(
"/sys/kernel/debug/zswap/reject_compress_poor"))
printstat("reject kmemcache fail", read(
"/sys/kernel/debug/zswap/reject_kmemcache_fail"))
printstat("reject alloc fail", read(
"/sys/kernel/debug/zswap/reject_alloc_fail"))
printstat("reject reclaim fail", read(
"/sys/kernel/debug/zswap/reject_reclaim_fail"))
printstat("reject kmemcache fail", read(
"/sys/kernel/debug/zswap/reject_kmemcache_fail"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment