Commit ab831fa
committed
🔨 refactor: ● Improve MGLRU and swap configuration for better desktop responsiveness
This commit addresses system slowdown issues caused by aggressive swap
behavior and insufficient anti-thrashing protection across different RAM
profiles.
PROBLEM IDENTIFIED:
- Systems with 8-16GB RAM were classified as "Standard" profile with only
1000ms MGLRU protection, causing excessive thrashing
- Small swap chunk size (512M) created too many swap files, leading to
fragmentation and I/O overhead
- Static RAM-based detection didn't consider actual memory pressure
- VeryHigh profile (>32GB) had only 250ms protection, inadequate for
heavy workstation loads
CHANGES MADE:
1. Increased MGLRU min_ttl values for all profiles (src/autoconfig.rs):
- UltraLow (≤2GB): 5000ms (unchanged)
- Low (2-4GB): 3000ms → 4000ms (+33%)
- Medium (4-8GB): 2000ms → 3000ms (+50%)
- Standard (8-16GB): 1000ms → 3000ms (+200%) [CRITICAL FIX]
- High (16-32GB): 500ms → 2000ms (+300%)
- VeryHigh (>32GB): 250ms → 2000ms (+700%)
2. Increased default swap chunk size (src/autoconfig.rs):
- NVMe/SSD: 512M → 1G (less fragmentation, better performance)
- HDD: 256M → 512M
3. Added dynamic memory pressure detection (src/meminfo.rs):
- New MemoryPressure enum (Low/Medium/High/Critical)
- get_memory_pressure() function based on MemAvailable
- get_available_ram_percent() for accurate memory detection
4. Implemented adaptive MGLRU adjustment (src/autoconfig.rs):
- New recommended_mglru_with_pressure() method
- Increases MGLRU protection based on actual memory pressure:
* Medium pressure (20-40% available): +50%
* High pressure (10-20% available): +100%
* Critical pressure (<10% available): +200%
5. Applied pressure detection at daemon startup (src/main.rs):
- Daemon now detects memory pressure on initialization
- Automatically adjusts MGLRU value based on real system conditions
- Falls back to static values if pressure detection unavailable
6. Updated default configuration documentation (include/swap-default.conf):
- Changed swapfile_chunk_size from 512M to 1G in comments
IMPACT:
Before (16GB RAM system under pressure):
- MGLRU: 1000ms (1 second)
- Chunk size: 512M
- Result: 14 small swap files, excessive thrashing, system slowdown
After (same system):
- MGLRU: 3000-6000ms (3-6 seconds, adaptive)
- Chunk size: 1G
- Result: Fewer larger swap files, better responsiveness, no thrashing
TESTING:
- Verified on 15GB RAM system with high swap usage (13GB/19GB)
- Memory pressure detection working correctly
- MGLRU values now adapt to actual system load
- Backward compatible: manual config values still respected
BENEFITS:
- Better desktop responsiveness across all RAM configurations
- Reduced swap fragmentation and I/O overhead
- Adaptive protection based on actual memory pressure, not just RAM size
- Suitable for light systems (4GB) and heavy workstations (64GB+)
- Maintains efficiency while preventing thrashing
Related issue: System slowdown with automatic swap configuration
Distribution: BigLinux (affects thousands of users)1 parent 0edc6a3 commit ab831fa
4 files changed
Lines changed: 65 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
351 | 351 | | |
352 | 352 | | |
353 | 353 | | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
359 | 359 | | |
360 | 360 | | |
361 | 361 | | |
| |||
366 | 366 | | |
367 | 367 | | |
368 | 368 | | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
369 | 385 | | |
370 | 386 | | |
371 | 387 | | |
| |||
596 | 612 | | |
597 | 613 | | |
598 | 614 | | |
599 | | - | |
| 615 | + | |
600 | 616 | | |
601 | 617 | | |
602 | 618 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
132 | 140 | | |
133 | 141 | | |
134 | 142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
111 | 144 | | |
112 | 145 | | |
113 | 146 | | |
| |||
0 commit comments