本帖最后由 demo 于 2026-6-8 15:59 编辑
To optimize memory performance in Zorin OS, it is recommended to enable ZRAM while disabling the traditional disk-based swap file, as ZRAM creates a compressed swap space in RAM that is significantly faster and reduces lag.
Enabling ZRAM
Install the necessary tools and configure the compression algorithm and memory percentage:
- sudo apt install zram-tools
- echo -e "ALGO=zstd\nPERCENT=70" | sudo tee -a /etc/default/zramswap
- sudo service zramswap reload
复制代码
Disabling Traditional Swap
To prevent conflict and ensure ZRAM is used exclusively, disable the existing swap file: Open /etc/fstab and comment out the swap line (e.g., #/swapfile). Run sudo swapoff /swapfile to deactivate it immediately. - Reboot the system to apply changes.
Optimizing Swappiness
Set the swappiness value to 10 to prioritize RAM usage and reduce swap activity, which improves responsiveness: - echo 'vm.swappiness=10' | sudo tee /etc/sysctl.d/99-swappiness.conf
- sudo sysctl -p /etc/sysctl.d/99-swappiness.conf
复制代码
Setup Zswap in Zorin OS
To setup zswap on Zorin OS, you must first ensure a swap file exists, then configure the kernel parameters in GRUB to enable compression and memory pooling.
1. Verify or Create Swap FileZorin OS typically uses a swap file. Verify it exists with free -h. If missing, create one: - <blockquote>sudo fallocate -l 4G /swapfile
复制代码
2. Configure GRUB for ZswapEdit the GRUB configuration to enable zswap with the lz4 compressor and z3fold pool: - sudo nano /etc/default/grub
复制代码
Add the following to the GRUB_CMDLINE_LINUX_DEFAULT line: - zswap.enabled=1 zswap.compressor=lz4 zswap.max_pool_percent=50 zswap.zpool=z3fold
复制代码
Save the file and update GRUB:
3. Update InitramfsEnsure the compression modules are loaded at boot: - sudo su
- echo lz4 >> /etc/initramfs-tools/modules
- echo lz4_compress >> /etc/initramfs-tools/modules
- echo z3fold >> /etc/initramfs-tools/modules
- update-initramfs -u
- exit
复制代码
4. Reboot and VerifyReboot your system. Verify zswap is active by running: - cat /sys/module/zswap/parameters/enabled
复制代码
A output of Y confirms zswap is enabled. You can check compression ratios and pool usage via /sys/kernel/debug/zswap/.
来自圈子: Demo俱乐部 |