Skip to content

Commit 50c6f55

Browse files
committed
Update README.md
1 parent c1244cb commit 50c6f55

1 file changed

Lines changed: 58 additions & 9 deletions

File tree

README.md

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Smart dynamic swap management for Linux, written in Rust.
88
- **Zswap + SwapFC**: Compressed RAM cache with dynamic btrfs swap files
99
- **Zram + SwapFC**: Alternative mode with zram as primary swap
1010
- **Zram writeback**: Move idle pages from zram to disk (kernel 5.4+)
11-
- **Btrfs optimized**: Sparse files with optional compression
11+
- **Sparse files (thin provisioning)**: Swap files don't pre-allocate disk space
12+
- **Btrfs optimized**: Optional compression mode for swap data
1213
- **Lightweight**: ~250 KB binary vs ~10 MB Python version
1314

1415
## Swap Modes
@@ -25,8 +26,9 @@ Smart dynamic swap management for Linux, written in Rust.
2526

2627
**zswap + swapfc (default for btrfs)**:
2728
- Zswap compresses pages in RAM before writing to swap
28-
- SwapFC creates swap files dynamically as memory pressure increases
29-
- Best desktop performance with efficient memory usage
29+
- SwapFC creates swap files as sparse files (thin provisioning)
30+
- Disk space is only used when zswap pool is full
31+
- Best desktop performance with efficient disk usage
3032

3133
**zram + swapfc**:
3234
- Zram creates compressed block device in RAM (highest priority)
@@ -60,8 +62,8 @@ makepkg -si
6062
## Usage
6163

6264
```bash
63-
# Check status
64-
systemd-swap status
65+
# Check status (run as root for detailed zswap stats)
66+
sudo systemd-swap status
6567

6668
# View available compression algorithms
6769
systemd-swap compression
@@ -73,6 +75,32 @@ sudo systemctl restart systemd-swap
7375
journalctl -u systemd-swap -f
7476
```
7577

78+
### Status Output (as root)
79+
80+
```
81+
Zswap:
82+
enabled: true
83+
compressor: zstd
84+
zpool: zsmalloc
85+
max_pool_percent: 45%
86+
87+
=== Pool Statistics (debugfs) ===
88+
pool_size: 234567890 (223.7 MiB)
89+
stored_pages: 58432 (228.2 MiB uncompressed)
90+
pool_utilization: 48%
91+
compress_ratio: 98%
92+
93+
=== Writeback Statistics ===
94+
written_back_pages: 1234 (4.8 MiB)
95+
pool_limit_hit: 0
96+
97+
=== Effective Swap Usage ===
98+
kernel_reported_used: 300.0 MiB
99+
in_zswap_pool (RAM): 228.2 MiB
100+
actual_disk_used: 71.8 MiB
101+
swap_in_ram: 76%
102+
```
103+
76104
## Configuration
77105

78106
Edit `/etc/systemd/swap.conf`:
@@ -105,16 +133,21 @@ zram_writeback_dev= # Partition or empty for auto loop
105133
zram_writeback_size=1G # Auto backing file size
106134

107135
################################################################################
108-
# SwapFC - Dynamic swap files (btrfs)
136+
# SwapFC - Dynamic swap files
109137
################################################################################
110138
swapfc_chunk_size=512M # Size of each swap file
111139
swapfc_max_count=32 # Maximum swap files
112140
swapfc_free_ram_perc=35 # Create when free RAM < this %
113141
swapfc_free_swap_perc=25 # Create more when free swap < this %
114-
swapfc_path=/swapfc/swapfile # Path (must be btrfs)
142+
swapfc_path=/swapfc/swapfile # Path for swap files
115143

116-
# Btrfs compression (experimental)
117-
swapfc_use_btrfs_compression=0 # Uses loop device over sparse file
144+
# Sparse files (thin provisioning) - ENABLED BY DEFAULT
145+
# Swap files appear full size but only allocate disk space when written.
146+
# Ideal with zswap: pages stay in RAM, disk is only used on writeback.
147+
# swapfc_use_sparse_disable=1 # Uncomment to pre-allocate disk space
148+
149+
# Btrfs compression mode (experimental)
150+
swapfc_use_btrfs_compression=0 # Double compression: zswap + btrfs
118151
```
119152

120153
## Custom Swap Location
@@ -141,6 +174,21 @@ zram_writeback_dev=/dev/sda5
141174

142175
Requires kernel compiled with `CONFIG_ZRAM_WRITEBACK`.
143176

177+
## Sparse Files (Thin Provisioning)
178+
179+
By default, swap files are created as sparse files:
180+
181+
- Files appear as 512M but start with 0 bytes on disk
182+
- Disk blocks are allocated only when data is actually written
183+
- With zswap, most pages stay compressed in RAM
184+
- Disk is only used when zswap pool is full (writeback)
185+
186+
To disable and pre-allocate all disk space:
187+
188+
```ini
189+
swapfc_use_sparse_disable=1
190+
```
191+
144192
## File Locations
145193

146194
| Path | Description |
@@ -161,3 +209,4 @@ Requires kernel compiled with `CONFIG_ZRAM_WRITEBACK`.
161209
## License
162210

163211
GPL-3.0-or-later
212+

0 commit comments

Comments
 (0)