summaryrefslogtreecommitdiff
path: root/scripts/.local/bin/checkzswap
blob: d6a4a00b0404c36053b88e45536303e8aba2d74a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh

# https://gist.github.com/phizev/31185a30e7d4984724f1fbbf9c2afe19

ENABLED=$(cat /sys/module/zswap/parameters/enabled)
COMPRESSOR=$(cat /sys/module/zswap/parameters/compressor)
ZPOOL=$(cat /sys/module/zswap/parameters/zpool)
PAGE_SIZE=$(getconf PAGE_SIZE)
STORED_PAGES=$(cat /sys/kernel/debug/zswap/stored_pages)
POOL_TOTAL_SIZE=$(cat /sys/kernel/debug/zswap/pool_total_size)

POOL_SIZE=$(numfmt --to=iec-i $POOL_TOTAL_SIZE)

if [ "$POOL_TOTAL_SIZE" = "0" ]
then
    DECOMPRESSED_SIZE="N/A"
    RATIO="N/A"
else
    DECOMPRESSED_SIZE=$(echo "$STORED_PAGES * $PAGE_SIZE" | bc | numfmt --to=iec-i)
    RATIO=$(echo "scale=3; $STORED_PAGES * $PAGE_SIZE / $POOL_TOTAL_SIZE" | bc -l)
fi

echo "Zswap enabled:            $ENABLED"
echo "Compressor:               $COMPRESSOR"
echo "Zpool:                    $ZPOOL"
echo
echo "Page size:                $PAGE_SIZE"
echo "Stored pages:             $STORED_PAGES"
echo "Pool size:                $POOL_SIZE"
echo "Decompressed size:        $DECOMPRESSED_SIZE"
echo "Page compression ratio:   $RATIO"

if [ "$1" = "-v" ]
then
    echo
    grep -R . /sys/kernel/debug/zswap/
    grep -R . /sys/module/zswap/parameters/
fi