Skip to content

volh/zramtop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zramtop

A terminal UI for monitoring memory and zram compression statistics.

zramtop screenshot

Background

How zram works

Zram creates a compressed block device in RAM. When the kernel swaps pages to zram:

  1. Pages are compressed (typically 2-4x ratio)
  2. Compressed data is stored in RAM, not on disk
  3. Access is ~10x faster than SSD swap

vm.swappiness with zram

With disk-based swap, low vm.swappiness (10-30) avoids slow I/O. With zram, higher values make sense because swapping to compressed RAM is cheap:

vm.swappiness = 180  # common with zram (Linux 5.8+ allows >100)

This causes more data to end up in zram, which is fine - that's what it's for.

What htop and free show

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           31Gi        20Gi       1.2Gi       1.1Gi       9.8Gi        11Gi
Swap:          31Gi        26Gi       4.9Gi

The "Swap used: 26G" is the uncompressed size of data in zram. The actual RAM used by zram to store this is ~8GB (at 3.4x compression). Standard tools don't show the compression ratio or physical RAM used.

What This Tool Shows

This tool shows zram-specific metrics: compression ratio, physical RAM used by zram, and bytes saved.

Memory [████████████████████████████████░░░░░░░░░░░░░░░░ 19.9/30.9G]
Zram   [████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 8.0G compressed from 26.0G (3.4x)]
Saved: 18.02G saved by compression

Anon: 9.70G
Cache: 8.79G  Buffers: 0.00G
Available: 11.1G

Total  [██████████████████████████████████████████████████ 37.9G data, 30.9G RAM]

Metrics

Metric Source Description
Memory MemTotal - MemAvailable Physical RAM in use
Zram mm_stat column 3 Physical RAM used by zram
Compressed from mm_stat column 1 Uncompressed size of data in zram
Compression ratio col1 / col2 Compression efficiency
Saved col1 - col3 RAM saved by compression
Anon AnonPages Anonymous pages
Cache/Buffers Cached, Buffers Page cache and buffer cache
Available MemAvailable Memory available for new allocations
Total used + saved Total data footprint

Installation

cargo install zramtop

Or build from source:

git clone https://github.com/volh/zramtop
cd zramtop
cargo build --release
./target/release/zramtop

Usage

# Interactive TUI
zramtop

# Debug output (non-interactive)
zramtop --debug

Keybindings

Key Action
q / Esc Quit
/ k Scroll up
/ j Scroll down
PgUp / PgDn Scroll page
Home / End Jump to top/bottom

Scripts

Script Purpose
scripts/zram-status Full status output (bash)
scripts/zram-oneline One-line output for status bars
scripts/zram-json JSON output for integrations
scripts/zram-compare Side-by-side with free output

Status Bar Integration

scripts/zram-oneline           # 19.9G/30.9G (3.4x, +18.0G saved)
scripts/zram-oneline short     # 19.9/30.9G 3.4x
scripts/zram-oneline percent   # 64% (3.4x)

Data Sources

  • /proc/meminfo - System memory statistics
  • /sys/block/zram*/mm_stat - Per-device zram statistics

mm_stat format

orig_data_size compr_data_size mem_used_total mem_limit mem_used_max ...
Column Field Description
1 orig_data_size Uncompressed size of data in zram
2 compr_data_size Compressed size
3 mem_used_total Physical RAM used (includes allocator overhead)

See kernel zram documentation for full details.

Requirements

  • Linux with zram configured
  • Read access to /proc and /sys
  • Terminal with Unicode support

License

MIT

About

TUI for monitoring memory and zram compression statistics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors