2.8 KiB
::: info This English version is translated by Gemini 3 Flash. :::
Linux Low Memory Optimization
Enable SWAP
-
Check current SWAP status
sudo swapon --show -
Create SWAP file
fallocate -l 4G /swapfile -
Set permissions
chmod 600 /swapfile -
Format and enable SWAP
mkswap /swapfile swapon /swapfile -
Set auto-mount on boot
echo '/swapfile none swap sw 0 0' | tee -a /etc/fstab
Enable ZRAM
Debian / Ubuntu
-
Install
apt update apt install zram-tools -y -
Modify configuration file
nano /etc/default/zramswapAdd or modify the following:
# Use lz4 compression algorithm for the best balance of speed and ratio ALGO=lz4 # Use 60% of total memory as ZRAM size PERCENT=60 # [Crucial] Set priority to 100. # As long as this is higher than disk Swap (usually -2), the system will prioritize ZRAM. PRIORITY=100Press
Ctrl+OEnter to save,Ctrl+Xto exit. -
Restart service
systemctl daemon-reload systemctl restart zramswap
CentOS / Arch Linux
Recommended to use zram-generator for these systems.
-
Install
# CentOS 8/9, Fedora, AlmaLinux, Rocky Linux dnf install zram-generator -y # Arch Linux pacman -S zram-generator -
Modify configuration file Create or edit
/etc/systemd/zram-generator.conf:[zram0] # Use 60% of total memory zram-size = ram * 0.6 # Use lz4 compression algorithm compression-algorithm = lz4 # Higher priority than disk Swap swap-priority = 100 -
Start service
systemctl daemon-reload systemctl start systemd-zram-setup@zram0
General Optimization
Regardless of the system, it is recommended to adjust swappiness to use ZRAM more aggressively.
grep -q "vm.swappiness" /etc/sysctl.conf || echo "vm.swappiness=20" | tee -a /etc/sysctl.conf
sysctl -p
Disable Site Isolation (fission.autostart)
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.
::: warning Risk Disclosure 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. :::
-
Modify
config.yaml:browser: # ... # Disable site isolation to significantly reduce memory footprint fission: false -
Restart WebAI2API service.
::: tip Tip After completing the configuration, it is recommended to restart the server to ensure all settings take effect. :::