|
1 | | -# This file is part of systemd-swap. |
2 | | -# |
3 | | -# Configuration for systemd-swap daemon. |
| 1 | +# Configuration for systemd-swap |
| 2 | +# This file is part of systemd-swap. |
4 | 3 | # See swap.conf(5) for details. |
5 | 4 |
|
6 | 5 | ################################################################################ |
7 | | -# Swap Mode - How swap is configured |
| 6 | +# Swap Mode |
8 | 7 | # |
9 | | -# auto - Auto-detect: btrfs/ext4/xfs → zswap+swapfc, other → zram only |
10 | | -# zswap+swapfc - Zswap cache + swap files (default for btrfs) |
11 | | -# zram+swapfc - Zram (fast) + swap files for overflow |
| 8 | +# auto - Auto-detect best mode (default) |
| 9 | +# - btrfs/ext4/xfs -> zswap + swapfc |
| 10 | +# - others -> zram only |
| 11 | +# zswap+swapfc - Zswap + swap files (best for desktop/btrfs) |
| 12 | +# zram+swapfc - Zram + swap files (good for low RAM) |
12 | 13 | # zram - Zram only (no disk swap) |
13 | | -# manual - Use explicit settings below (legacy mode) |
| 14 | +# manual - Use explicit settings below |
14 | 15 | ################################################################################ |
15 | 16 |
|
16 | 17 | swap_mode=auto |
17 | 18 |
|
18 | 19 | ################################################################################ |
19 | | -# Zswap - Compressed RAM cache for swap pages |
20 | | -# Used in zswap+swapfc mode or manual with zswap_enabled=1 |
21 | | -# |
22 | | -# zswap compresses pages before writing to swap, reducing I/O. |
23 | | -# Requires a backing swap device (swap file or partition). |
| 20 | +# Zswap Settings (used in zswap+swapfc mode) |
24 | 21 | ################################################################################ |
25 | 22 |
|
26 | | -zswap_compressor=zstd # lzo lz4 zstd lzo-rle lz4hc (zstd = best balance) |
27 | | -zswap_max_pool_percent=45 # Max % of RAM for compressed pool (30-50 typical) |
28 | | -zswap_zpool=zsmalloc # Memory allocator (zsmalloc only, z3fold/zbud deprecated) |
29 | | -zswap_shrinker_enabled=1 # Move cold pages to disk proactively (default since 6.8) |
30 | | -zswap_accept_threshold=90 # Accept pages again after pool was full (%) |
| 23 | +zswap_compressor=zstd # Compression algo: zstd, lz4, lzo |
| 24 | +zswap_max_pool_percent=60 # Max RAM for compressed pool |
| 25 | +zswap_zpool=zsmalloc # Allocator |
| 26 | +zswap_shrinker_enabled=1 # Proactively move cold pages to disk |
| 27 | +zswap_accept_threshold=90 # Restart accepting pages when pool drops to X% |
31 | 28 |
|
32 | 29 | ################################################################################ |
33 | | -# Zram - Compressed RAM disk |
34 | | -# Used in zram+swapfc, zram-only modes, or manual with zram_enabled=1 |
35 | | -# |
36 | | -# zram creates a compressed block device in RAM for swap |
37 | | -# Faster than zswap - ideal for desktop systems |
| 30 | +# Zram Settings (used in zram modes) |
38 | 31 | ################################################################################ |
39 | 32 |
|
40 | | -# zram_size supports: 1G, 512M, 50%, 100% (full RAM) |
41 | | -zram_size=80% # Size of zram device |
42 | | -zram_alg=zstd # Compression: lzo lz4 zstd lzo-rle lz4hc |
43 | | -zram_prio=32767 # Swap priority (highest = used first) |
| 33 | +zram_size=80% # Size of zram device (e.g., 50%, 1G) |
| 34 | +zram_alg=zstd # Compression algo |
| 35 | +zram_prio=32767 # Priority (highest) |
44 | 36 |
|
45 | | -# Zram writeback: move idle/incompressible pages to disk |
46 | | -# Requires CONFIG_ZRAM_WRITEBACK in kernel |
47 | | -# When enabled with empty dev, auto-creates sparse file + loop device |
48 | | -zram_writeback=0 # 0=disabled, 1=enabled |
49 | | -zram_writeback_dev= # Backing device (partition or empty for auto loop) |
50 | | -zram_writeback_size=1G # Size of auto-created backing file |
| 37 | +# Zram Writeback (optional, off by default) |
| 38 | +# Moves incompressible/idle pages to backing storage |
| 39 | +zram_writeback=0 |
| 40 | +zram_writeback_size=1G # Initial backing file size |
| 41 | +zram_writeback_max_size=8G # Max size |
| 42 | +zram_writeback_threshold=50 # Trigger when zram is X% full |
51 | 43 |
|
52 | 44 | ################################################################################ |
53 | | -# SwapFC - Dynamic swap file management |
54 | | -# Supports: btrfs, ext4, xfs (auto-detected) |
55 | | -# Used in zram+swapfc, zswap+swapfc modes, or manual with swapfc_enabled=1 |
56 | | -# |
57 | | -# Creates swap files on-demand as memory pressure increases. |
58 | | -# Files are pre-allocated with fallocate for stability. |
| 45 | +# SwapFC - Dynamic Swap Files (used in swapfc modes) |
59 | 46 | ################################################################################ |
60 | 47 |
|
61 | | -# swapfc_chunk_size supports: 1G, 512M, 10% (percentage of RAM) |
62 | | -swapfc_chunk_size=512M # Size of each swap file (512M = good balance) |
63 | | -swapfc_max_count=32 # Maximum number of swap files |
64 | | -swapfc_min_count=1 # Minimum (1 for zswap backing) |
65 | | -swapfc_free_ram_perc=35 # Create swap when free RAM < this % |
66 | | -swapfc_free_swap_perc=25 # Create more swap when free swap < this % |
67 | | -swapfc_remove_free_swap_perc=55 # Remove swap when free swap > this % |
68 | | -swapfc_priority=50 # Swap priority (decreases per file) |
69 | | -swapfc_path=/swapfc/swapfile # Path for swap files |
70 | | -swapfc_frequency=1 # Check interval in seconds |
| 48 | +# Progressive Scaling: Start small, grow as needed |
| 49 | +# e.g. 256M -> 256M -> 512M -> 512M... doubles every 4 files |
| 50 | +swapfc_enabled=1 # Enable swap files |
| 51 | +swapfc_path=/swapfc/swapfile # Directory and filename prefix |
| 52 | +swapfc_chunk_size=256M # Base size |
| 53 | +swapfc_max_chunk_size=32G # Max single file size |
| 54 | +swapfc_max_count=28 # Max number of files |
| 55 | +swapfc_scaling_step=4 # Double size every X files |
71 | 56 |
|
72 | | -# File allocation mode: |
73 | | -# Pre-allocated (default): Uses fallocate, reserves disk space upfront. |
74 | | -# This is the recommended mode for stability under memory pressure. |
75 | | -# swapfc_use_sparse=1 # Uncomment for thin provisioning (advanced, less stable) |
76 | | - |
77 | | -# Btrfs compression mode (experimental, btrfs only): |
78 | | -# Uses loop device over file on compressed btrfs subvolume. |
79 | | -# Enables double compression: zswap (RAM) + btrfs zstd (disk). |
80 | | -swapfc_use_btrfs_compression=0 |
| 57 | +# Triggers |
| 58 | +swapfc_free_ram_perc=35 # Create swap when free RAM < X% |
| 59 | +swapfc_free_swap_perc=25 # Create more when free swap < X% |
| 60 | +swapfc_remove_free_swap_perc=55 # Remove files when free swap > X% |
81 | 61 |
|
82 | 62 | ################################################################################ |
83 | | -# MGLRU - Multi-Gen LRU tuning (kernel 6.1+) |
84 | | -# Protects working set from premature eviction during memory pressure. |
85 | | -# If min_ttl_ms > 0, pages are protected for that duration before eviction. |
86 | | -# This prevents thrashing at the cost of triggering OOM killer if memory |
87 | | -# cannot be maintained. 0 = disabled (kernel default). |
| 63 | +# Advanced / Experimental |
88 | 64 | ################################################################################ |
89 | 65 |
|
90 | | -mglru_min_ttl_ms=1000 # Protection time in ms (0=disabled, 1000=recommended) |
91 | | - |
92 | | -################################################################################ |
93 | | -# Enable/disable settings |
94 | | -# zswap_enabled: Set to 0 to disable zswap (default: 1, enabled when not using zram) |
95 | | -# zram_enabled: Only used in manual mode |
96 | | -# swapfc_enabled: Only used in manual mode |
97 | | -################################################################################ |
| 66 | +# MGLRU Anti-Thrashing (Kernel 6.1+) |
| 67 | +# Protect working set for X ms. 0 to disable. |
| 68 | +mglru_min_ttl_ms=1000 |
98 | 69 |
|
99 | | -zswap_enabled=1 |
100 | | -zram_enabled=0 |
101 | | -swapfc_enabled=0 |
102 | | -swapd_auto_swapon=0 |
| 70 | +# Sparse Files |
| 71 | +# Create files that only use disk space when actually written to. |
| 72 | +# Highly recommended for Zswap mode. |
| 73 | +# swapfc_use_sparse_disable=1 # Uncomment to disable (pre-allocate all space) |
0 commit comments