|
| 1 | +::: info |
| 2 | +This English version is translated by **Gemini 3 Flash**. |
| 3 | +::: |
| 4 | + |
| 5 | +# Linux Low Memory Optimization |
| 6 | + |
| 7 | +## Enable SWAP |
| 8 | + |
| 9 | +1. Check current SWAP status |
| 10 | + ```bash |
| 11 | + sudo swapon --show |
| 12 | + ``` |
| 13 | + |
| 14 | +2. Create SWAP file |
| 15 | + ```bash |
| 16 | + fallocate -l 4G /swapfile |
| 17 | + ``` |
| 18 | + |
| 19 | +3. Set permissions |
| 20 | + ```bash |
| 21 | + chmod 600 /swapfile |
| 22 | + ``` |
| 23 | + |
| 24 | +4. Format and enable SWAP |
| 25 | + ```bash |
| 26 | + mkswap /swapfile |
| 27 | + swapon /swapfile |
| 28 | + ``` |
| 29 | + |
| 30 | +5. Set auto-mount on boot |
| 31 | + ```bash |
| 32 | + echo '/swapfile none swap sw 0 0' | tee -a /etc/fstab |
| 33 | + ``` |
| 34 | + |
| 35 | +## Enable ZRAM |
| 36 | + |
| 37 | +### Debian / Ubuntu |
| 38 | + |
| 39 | +1. Install |
| 40 | + ```bash |
| 41 | + apt update |
| 42 | + apt install zram-tools -y |
| 43 | + ``` |
| 44 | + |
| 45 | +2. Modify configuration file |
| 46 | + ```bash |
| 47 | + nano /etc/default/zramswap |
| 48 | + ``` |
| 49 | + |
| 50 | + Add or modify the following: |
| 51 | + |
| 52 | + ```bash |
| 53 | + # Use zstd compression algorithm for the best balance of speed and ratio |
| 54 | + ALGO=zstd |
| 55 | + |
| 56 | + # Use 60% of total memory as ZRAM size |
| 57 | + PERCENT=60 |
| 58 | + |
| 59 | + # [Crucial] Set priority to 100. |
| 60 | + # As long as this is higher than disk Swap (usually -2), the system will prioritize ZRAM. |
| 61 | + PRIORITY=100 |
| 62 | + ``` |
| 63 | + |
| 64 | + Press `Ctrl+O` Enter to save, `Ctrl+X` to exit. |
| 65 | + |
| 66 | +3. Restart service |
| 67 | + ```bash |
| 68 | + systemctl daemon-reload |
| 69 | + systemctl restart zramswap |
| 70 | + ``` |
| 71 | + |
| 72 | +### CentOS / Arch Linux |
| 73 | + |
| 74 | +Recommended to use `zram-generator` for these systems. |
| 75 | + |
| 76 | +1. Install |
| 77 | + ```bash |
| 78 | + # CentOS 8/9, Fedora, AlmaLinux, Rocky Linux |
| 79 | + dnf install zram-generator -y |
| 80 | + |
| 81 | + # Arch Linux |
| 82 | + pacman -S zram-generator |
| 83 | + ``` |
| 84 | + |
| 85 | +2. Modify configuration file |
| 86 | + Create or edit `/etc/systemd/zram-generator.conf`: |
| 87 | + |
| 88 | + ```ini |
| 89 | + [zram0] |
| 90 | + # Use 60% of total memory |
| 91 | + zram-size = ram * 0.6 |
| 92 | + # Use zstd compression algorithm |
| 93 | + compression-algorithm = zstd |
| 94 | + # Higher priority than disk Swap |
| 95 | + swap-priority = 100 |
| 96 | + ``` |
| 97 | + |
| 98 | +3. Start service |
| 99 | + ```bash |
| 100 | + systemctl daemon-reload |
| 101 | + systemctl start systemd-zram-setup@zram0 |
| 102 | + ``` |
| 103 | + |
| 104 | +### General Optimization |
| 105 | + |
| 106 | +Regardless of the system, it is recommended to adjust `swappiness` to use ZRAM more aggressively. |
| 107 | + |
| 108 | +```bash |
| 109 | +grep -q "vm.swappiness" /etc/sysctl.conf || echo "vm.swappiness=80" | tee -a /etc/sysctl.conf |
| 110 | +sysctl -p |
| 111 | +``` |
| 112 | + |
| 113 | +## Disable Site Isolation (fission.autostart) |
| 114 | + |
| 115 | +For servers with extremely tight memory (e.g., 1GB RAM), if the system still crashes frequently after enabling SWAP and ZRAM, you can try disabling Firefox's Site Isolation as a **last resort**. |
| 116 | + |
| 117 | +::: warning Risk Disclosure |
| 118 | +Disabling Site Isolation reduces the uniqueness of the browser fingerprint, potentially making it easier for high-level anti-bot systems to identify (e.g., by detecting single-process model or inter-process communication delays). Use only when necessary. |
| 119 | +::: |
| 120 | + |
| 121 | +1. Modify `config.yaml`: |
| 122 | + |
| 123 | + ```yaml |
| 124 | + browser: |
| 125 | + # ... |
| 126 | + # Disable site isolation to significantly reduce memory footprint |
| 127 | + fission: false |
| 128 | + ``` |
| 129 | +
|
| 130 | +2. Restart WebAI2API service. |
| 131 | +
|
| 132 | +::: tip Tip |
| 133 | +After completing the configuration, it is recommended to restart the server to ensure all settings take effect. |
| 134 | +::: |
0 commit comments