@@ -4,31 +4,31 @@ Smart dynamic swap management for Linux, written in Rust.
44
55## Features
66
7- - ** Auto-detection** : Automatically chooses optimal swap strategy for your filesystem
8- - ** Multi-filesystem** : Supports btrfs, ext4, and xfs for swap files
7+ - ** Auto-detection** : Automatically chooses optimal swap strategy based on filesystem (btrfs/ext4/xfs)
98- ** Zswap + SwapFC** : Compressed RAM cache with dynamic swap files
109- ** Zram + SwapFC** : Alternative mode with zram as primary swap
1110- ** Zram writeback** : Move idle pages from zram to disk (kernel 5.4+)
12- - ** Fallback support ** : Automatically falls back to zram-only if swap files fail
11+ - ** Multi-filesystem ** : Supports btrfs, ext4, and xfs
1312- ** Lightweight** : ~ 250 KB binary vs ~ 10 MB Python version
1413
1514## Swap Modes
1615
1716| Mode | Description | Best For |
1817| ------| -------------| ----------|
1918| ` auto ` | Auto-detect: btrfs/ext4/xfs → zswap+swapfc, other → zram | Most users |
20- | ` zswap+swapfc ` | Zswap cache + dynamic swap files | ** Desktop** |
19+ | ` zswap+swapfc ` | Zswap cache + dynamic swap files | ** Desktop (btrfs) ** |
2120| ` zram+swapfc ` | Zram primary + swap files overflow | Memory-constrained |
22- | ` zram ` | Zram only (no disk swap) | Unsupported filesystems |
21+ | ` zram ` | Zram only (no disk swap) | Non-btrfs systems |
2322| ` manual ` | Use explicit settings | Advanced users |
2423
2524### How Each Mode Works
2625
2726** zswap + swapfc (default for btrfs/ext4/xfs)** :
2827- Zswap compresses pages in RAM before writing to swap
29- - SwapFC creates pre-allocated swap files (512MB each)
30- - Disk space is only used when zswap pool is full
31- - Best desktop performance with efficient disk usage
28+ - Shrinker moves cold pages to disk proactively, freeing RAM
29+ - SwapFC creates pre-allocated swap files with fallocate
30+ - Most data stays in RAM; disk is only used for cold pages
31+ - Best desktop performance with efficient memory usage
3232
3333** zram + swapfc** :
3434- Zram creates compressed block device in RAM (highest priority)
@@ -113,13 +113,12 @@ swap_mode=auto
113113
114114# ###############################################################################
115115# Zswap (used in zswap+swapfc mode)
116- # Modern defaults for desktop Linux (kernel 6.x+)
117116# ###############################################################################
118- zswap_compressor =zstd # lzo lz4 zstd lzo-rle lz4hc (zstd = best)
119- zswap_max_pool_percent =45 # Max % of RAM for pool (20-50 typical)
120- zswap_zpool =zsmalloc # Memory allocator (default upstream)
121- zswap_shrinker_enabled =1 # Evict cold pages to disk (default since 6.8)
122- zswap_accept_threshold =90 # Accept threshold after pool full
117+ zswap_compressor =zstd # lzo lz4 zstd lzo-rle lz4hc
118+ zswap_max_pool_percent =45 # Max % of RAM for pool
119+ zswap_zpool =zsmalloc # Memory allocator
120+ zswap_shrinker_enabled =1 # Move cold pages to disk
121+ zswap_accept_threshold =80 # Accept threshold after pool full
123122
124123# ###############################################################################
125124# Zram (used in zram modes)
@@ -142,10 +141,12 @@ swapfc_free_ram_perc=35 # Create when free RAM < this %
142141swapfc_free_swap_perc =25 # Create more when free swap < this %
143142swapfc_path =/swapfc/swapfile # Path for swap files
144143
145- # Pre-allocated files (default) - more stable, no loop device needed
146- swapfc_use_sparse =0 # 0=pre-allocate (default), 1=sparse
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
147148
148- # Btrfs compression mode (experimental) and need use loop device
149+ # Btrfs compression mode (experimental)
149150swapfc_use_btrfs_compression =0 # Double compression: zswap + btrfs
150151```
151152
@@ -173,22 +174,21 @@ zram_writeback_dev=/dev/sda5
173174
174175Requires kernel compiled with ` CONFIG_ZRAM_WRITEBACK ` .
175176
176- ## File Allocation Mode
177+ ## Sparse Files (Thin Provisioning)
177178
178- By default, swap files are ** pre-allocated ** using ` fallocate ` :
179+ By default, swap files are created as sparse files :
179180
180- - Files reserve 512M on disk immediately
181- - More stable under memory pressure (no loop device needed)
182- - Better for most desktop and server workloads
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)
183185
184- To use sparse files (thin provisioning) instead :
186+ To disable and pre-allocate all disk space :
185187
186188``` ini
187- swapfc_use_sparse =1
189+ swapfc_use_sparse_disable =1
188190```
189191
190- Sparse mode creates files that only allocate disk space when written, but requires a loop device which can cause issues under extreme memory pressure.
191-
192192## File Locations
193193
194194| Path | Description |
0 commit comments