@@ -5,28 +5,28 @@ Smart dynamic swap management for Linux, written in Rust.
55## Features
66
77- ** Auto-detection** : Automatically chooses optimal swap strategy for your filesystem
8- - ** Zswap + SwapFC** : Compressed RAM cache with dynamic btrfs swap files
8+ - ** Multi-filesystem** : Supports btrfs, ext4, and xfs for swap files
9+ - ** Zswap + SwapFC** : Compressed RAM cache with dynamic swap files
910- ** Zram + SwapFC** : Alternative mode with zram as primary swap
1011- ** Zram writeback** : Move idle pages from zram to disk (kernel 5.4+)
11- - ** Sparse files (thin provisioning)** : Swap files don't pre-allocate disk space
12- - ** Btrfs optimized** : Optional compression mode for swap data
12+ - ** Fallback support** : Automatically falls back to zram-only if swap files fail
1313- ** Lightweight** : ~ 250 KB binary vs ~ 10 MB Python version
1414
1515## Swap Modes
1616
1717| Mode | Description | Best For |
1818| ------| -------------| ----------|
19- | ` auto ` | Auto-detect: btrfs → zswap+swapfc, other → zram | Most users |
20- | ` zswap+swapfc ` | Zswap cache + dynamic swap files | ** Desktop (btrfs) ** |
19+ | ` auto ` | Auto-detect: btrfs/ext4/xfs → zswap+swapfc, other → zram | Most users |
20+ | ` zswap+swapfc ` | Zswap cache + dynamic swap files | ** Desktop** |
2121| ` zram+swapfc ` | Zram primary + swap files overflow | Memory-constrained |
22- | ` zram ` | Zram only (no disk swap) | Non-btrfs systems |
22+ | ` zram ` | Zram only (no disk swap) | Unsupported filesystems |
2323| ` manual ` | Use explicit settings | Advanced users |
2424
2525### How Each Mode Works
2626
27- ** zswap + swapfc (default for btrfs)** :
27+ ** zswap + swapfc (default for btrfs/ext4/xfs )** :
2828- Zswap compresses pages in RAM before writing to swap
29- - SwapFC creates swap files as sparse files (thin provisioning )
29+ - SwapFC creates pre-allocated swap files (512MB each )
3030- Disk space is only used when zswap pool is full
3131- Best desktop performance with efficient disk usage
3232
@@ -113,12 +113,13 @@ swap_mode=auto
113113
114114# ###############################################################################
115115# Zswap (used in zswap+swapfc mode)
116+ # Modern defaults for desktop Linux (kernel 6.x+)
116117# ###############################################################################
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
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
122123
123124# ###############################################################################
124125# Zram (used in zram modes)
@@ -141,12 +142,10 @@ swapfc_free_ram_perc=35 # Create when free RAM < this %
141142swapfc_free_swap_perc =25 # Create more when free swap < this %
142143swapfc_path =/swapfc/swapfile # Path for swap files
143144
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
145+ # Pre-allocated files (default) - more stable, no loop device needed
146+ swapfc_use_sparse =0 # 0=pre-allocate (default), 1=sparse
148147
149- # Btrfs compression mode (experimental)
148+ # Btrfs compression mode (experimental) and need use loop device
150149swapfc_use_btrfs_compression =0 # Double compression: zswap + btrfs
151150```
152151
@@ -174,21 +173,22 @@ zram_writeback_dev=/dev/sda5
174173
175174Requires kernel compiled with ` CONFIG_ZRAM_WRITEBACK ` .
176175
177- ## Sparse Files (Thin Provisioning)
176+ ## File Allocation Mode
178177
179- By default, swap files are created as sparse files :
178+ By default, swap files are ** pre-allocated ** using ` fallocate ` :
180179
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)
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
185183
186- To disable and pre-allocate all disk space :
184+ To use sparse files (thin provisioning) instead :
187185
188186``` ini
189- swapfc_use_sparse_disable =1
187+ swapfc_use_sparse =1
190188```
191189
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