RHEL8 enables zRAM
Introduction to zRAM
https://adtxl.com/index.php/archives/337.html
zRAM (compressed memory) means to 内存中
open up a piece of memory 区域压缩数据
... that is to say, assuming that the original 150MB
thing that can 可用内存
be put down now ... itself will not improve and ... Just let less be, in order to get ...and this will .180MB
内存容量
运行速度
后台程序
系统砍掉
更多任务运行
压缩动作
加重CPU负担
验证
zRAM is widely used on Android phones 应用
.
This document 实测
also applies toCentos7
0. Install kernel extensions – not required
# 安装内核扩展包
dnf install -y kernel-modules-extra
1. Enable zram kernel module
# 加载zram模块
modprobe zram
# 在系统启动时自动加载zram内核模块
echo zram >/etc/modules-load.d/zram.conf
# 指定ZRAM设备的数量为1
echo "options zram num_devices=1" >/etc/modprobe.d/zram.conf
# 检查内核是否启用zram
lsmod | grep zram
# 查看内核是否支持zram
modinfo zram
2. Configure the size of the zRAM partition
https://www.jianshu.com/p/c9d0423d7149
官方
It is recommended to use 总内存
as 30%-50%
, zram
as 压缩率
calculated 50%
, the memory will increase 30%-50%
around.
https://wertherzhang.com/zram/#zram
# 创建一个新文件
vim /etc/udev/rules.d/99-zram.rules
In that file, paste the following (modify the disksize attribute to suit your needs):
KERNEL=="zram0", ATTR{
disksize}="2048M",TAG+="systemd"
Restart udev
service
# 重启udev服务
systemctl restart systemd-udevd.service
重启udev服务
After that, the device will appear /dev/zram0
, but only 重启OS
after可用
3. Disable the original swap partition or original swap file
In /etc/fstab
the file, 注释
drop /swap.img
the first line (add a # sign).
4. Adjust kernel configuration
https://zhuanlan.zhihu.com/p/484408336/etc/sysctl.conf
# 优化zarm磁盘读取
vm.page-cluster = 0
# 让内存更有序
## 当页框碎片指数低于该阈值会触发碎片整理
## 默认是 500(介于 0 和 1000 之间的值)
vm.extfrag_threshold = 0
# 使内核配置生效
sysctl -p
5. Create a zram service file
vim /etc/systemd/system/zram.service
[Unit]
Description=Swap with zram
After=multi-user.target
[Service]
Type=oneshot
RemainAfterExit=true
ExecStartPre=/sbin/mkswap /dev/zram0
ExecStart=/sbin/swapon /dev/zram0
ExecStop=/sbin/swapoff /dev/zram0
[Install]
WantedBy=multi-user.target
Enable zram
service
# 重载配置文件
systemctl daemon-reload
# 启用服务
systemctl enable --now zram
6. Check if zRAM is working properly
重启系统
After that, check zRAM
if it works properly
# 查看zRAM加载情况
zramctl
# 检查zRAM是否正常工作
cat /proc/swaps
Now, you should see /dev/zram0
it being treated as swap.