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 150MBthing 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

image.png

# 查看内核是否支持zram
modinfo zram

image.png


2. Configure the size of the zRAM partition

https://www.jianshu.com/p/c9d0423d7149

官方It is recommended to use 总内存as 30%-50%, zramas 压缩率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 udevservice

# 重启udev服务
systemctl restart systemd-udevd.service

重启udev服务After that, the device will appear /dev/zram0, but only 重启OSafter可用


3. Disable the original swap partition or original swap file

In /etc/fstabthe file, 注释drop /swap.imgthe 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 zramservice

# 重载配置文件
systemctl daemon-reload

# 启用服务
systemctl enable --now zram

6. Check if zRAM is working properly

重启系统After that, check zRAMif it works properly

# 查看zRAM加载情况
zramctl

image.png

# 检查zRAM是否正常工作
cat /proc/swaps

Now, you should see /dev/zram0it being treated as swap.image.png

Guess you like

Origin blog.csdn.net/omaidb/article/details/132324163