Deployment
apt install zram-tools
nano /etc/default/zramswap
ALGO=lz4 #low cpu overhead
or ALGO=zstd #high compress ratio high cpu overhead
PERCENT=50 #fifty percent of total ram size for zram
enable zram service
systemctl enable --now zramswap
sudo systemctl restart zramswap
check the zram status
zramctl
swapon --show
LZ4 (default / fastest)
lz4
lz4hc
| Mode | Speed | Compression | CPU cost | zram suitability |
|---|---|---|---|---|
| lz4 | ⭐⭐⭐⭐⭐ | ⭐⭐ | ⭐ | ✅ Excellent |
| lz4hc | ⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐ | ⚠️ Rarely worth it |
lz4
- Extremely fast compression and decompression
- Low CPU overhead
- Best choice for swap-on-zram and low-power CPUs
lz4hc (high compression)
- Slightly better compression
- Much slower compression
- Usually not recommended for zram
| Level | Speed | Compression | CPU cost | zram use case |
|---|---|---|---|---|
| zstd:1 | ⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐ | ✅ Good balance |
| zstd:3 | ⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐ | ⚠️ Maybe |
| zstd:6 | ⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ❌ Not ideal |
| zstd:10+ | ⭐ | ⭐⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ❌ No |
use zstd:1 or zstd:3
- Anything higher is usually wasted CPU.
| Aspect | LZ4 | ZSTD |
|---|---|---|
| Compression speed | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ |
| Decompression speed | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ |
| Compression ratio | ⭐⭐ | ⭐⭐⭐⭐ |
| CPU usage | ⭐ | ⭐⭐⭐ |
| Swap latency | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ |
| Low-end CPU | ✅ Perfect | ⚠️ Maybe |
评论区