用zswap和zram彻底解决高I/O引起的卡顿,复制文件无比流畅
Tofloor
poster avatar
rekees2020
deepin
2020-07-22 05:03
Author
本帖最后由 rekees2020 于 2020-7-21 21:05 编辑

zswap就是系统要进行swap的时候,先把要swap的数据压缩一下放在内存里,能减少对硬盘swap的读写,提高性能
zram是在内存中虚拟一个swap设备,也能提高性能
zswap用swap-control-gui直接设置,作者几年前在社区里发过
但是这个软件在deepin 20上无法设置zram

可以用以下方法设置zram--
(如果同时有用于休眠的swap分区,其优先级会高于zram,理论上可以修改/etc/fstab,降低swap分区优先级,但我机器上这样设置不生效,swap分区优先级为-2,zram优先级为-3,zram形同虚设,可以写开机自动运行脚本,用swapoff和swapon命令关闭再打开swap分区,这样zram优先级就成-2,swap分区优先级就成-3)

How to enable zRAM
The zRAM module is controlled by systemd, so there's no need for an fstab entry. And since everything is already installed out of the box, we only need to create a few files and modify one.
Open a terminal window and create a new file with the command:
sudo nano /etc/modules-load.d/zram.conf
In that file, add the word:
zram
Save and close the file.

Next, create a second new file with the command:
sudo nano /etc/modprobe.d/zram.conf
In that file, paste the line:
options zram num_devices=1
Save and close the file.
Next, we need to configure the size of the zRAM partition. Create a new file with the command:
sudo nano /etc/udev/rules.d/99-zram.rules
In that file, paste the following (modifying the disksize attribute to fit your needs):
KERNEL=="zram0", ATTR{disksize}="512M",TAG+="systemd"
Save and close the file.

In order for zRAM to run, we need to create a systemd unit file. Create this file with the command:
sudo nano /etc/systemd/system/zram.service
In that file, paste the following contents:
[Unit]Description=Swap with zramAfter=multi-user.target[Service]Type=oneshot RemainAfterExit=trueExecStartPre=/sbin/mkswap /dev/zram0ExecStart=/sbin/swapon /dev/zram0ExecStop=/sbin/swapoff /dev/zram0[Install]WantedBy=multi-user.target
Save and close the file.
Enable the new unit with the command:
sudo systemctl enable zram
Reboot the machine.

How to find out if zRAM is working
Once the system reboots, log back in. From a terminal window, issue the command:
cat /proc/swaps

Reply Favorite View the author
All Replies
avatar
rekees2020
deepin
2020-07-22 05:06
#1
zram的大小并不是直接独占,而是动态分配,这样也不用担心浪费内存
Reply View the author
avatar
Hello
deepin
2020-07-22 05:54
#2
建议官方集成到系统里,
我先来
圣上请采纳吾等建议
圣上万岁!!!
Reply View the author
avatar
Hello
deepin
2020-07-22 05:57
#3
顺便请愿,在正式版新终端请加回终端主题和各种颜色的蒙版
白色丑,透明花,玻璃乱眼睛
加上蒙版主题最完美
请加回蒙版主题!!!
Reply View the author
avatar
Hello
deepin
2020-07-22 05:59
#4
来都来了
请愿圣上将僵直特效和窗口摆动特效加入dde
请愿圣上能够允许我们拖动默认分区扩大roota和rootb,对默认分区进行微调,像ubuntu一样
请愿圣上加上新的双显卡方案
臣跪下了!
Reply View the author
avatar
rekees2020
deepin
2020-07-22 06:00
#5
https://bbs.deepin.org/post/197502
建议官方集成到系统里,
我先来
圣上请采纳吾等建议

这两个东西,系统里本来就有的,只是没有设置
如果能默认设置一下,开箱体验更好,很多用户就不用踩坑,比如我就被这个问题困扰了好久,一度还有点怀念Windows
Reply View the author
avatar
Hello
deepin
2020-07-22 06:00
#6
请愿圣上开发64位的deepinwine5,
让大火玩上deepinwine-epic
请愿。。。。。
Reply View the author
avatar
Hello
deepin
2020-07-22 06:11
#7
官方只要给一个大火使用这个功能的开关就好了。。真的挺好的功能
Reply View the author
avatar
lenke
deepin
2020-07-22 06:12
#8
如果上nvme协议的固态硬盘
是不是就不卡了?
Reply View the author
avatar
rekees2020
deepin
2020-07-22 06:20
#9
https://bbs.deepin.org/post/197502
如果上nvme协议的固态硬盘
是不是就不卡了?

我用的.M2固态硬盘,会卡
nvme固态硬盘不知道,但swap到任何固态硬盘都肯定没有swap到内存快

关闭swap是最简单粗暴的办法,但不能保留休眠
用zswap和zram可以尽量不swap到硬盘(zram如果设置大一点,就差不多杜绝swap到硬盘),同时休眠功能是可用的
Reply View the author
avatar
SamLukeYes
deepin
2020-07-22 06:23
#10
查了一下 arch wiki,5.7+的内核默认启用了zswap
Reply View the author
avatar
Hello
deepin
2020-07-22 06:25
#11
https://bbs.deepin.org/post/197502
我用的.M2固态硬盘,会卡
nvme固态硬盘不知道,但swap到任何固态硬盘都肯定没有swap到内存快

问一下,休眠功能。。。。swap为啥能带来休眠功能,什么是休眠功能
Reply View the author
avatar
rekees2020
deepin
2020-07-22 06:32
#12
https://bbs.deepin.org/post/197502
问一下,休眠功能。。。。swap为啥能带来休眠功能,什么是休眠功能

就是把内存里的数据全部写入硬盘,在Linux系统中,就是写入硬盘上的swap分区或文件
而swap另外一个作用是在内存占用达到某个水平时接受从内存移过来的数据,缓解内存不足;硬盘读写太多的时候,即使内存占用很低,系统也会进行这样的行为,硬盘反应不过来,系统就卡了

休眠的作用是,下次开机,之前打开的一切都还在;如果工作中需要打开一大堆软件,查阅乱七八糟的资料,这样是不是很方便?下次不用再一个个打开
Reply View the author
avatar
rekees2020
deepin
2020-07-22 06:33
#13
https://bbs.deepin.org/post/197502
查了一下 arch wiki,5.7+的内核默认启用了zswap

deepin不知道什么时候升级内核
Reply View the author
avatar
Hello
deepin
2020-07-22 06:34
#14
https://bbs.deepin.org/post/197502
就是把内存里的数据全部写入硬盘,在Linux系统中,就是写入硬盘上的swap分区或文件
而swap另外一个作用是 ...

草,休眠原来是swap实现的啊。。。。。。草草草
Reply View the author
avatar
Hello
deepin
2020-07-22 06:35
#15
https://bbs.deepin.org/post/197502
就是把内存里的数据全部写入硬盘,在Linux系统中,就是写入硬盘上的swap分区或文件
而swap另外一个作用是 ...

swap是不是就是书上说的虚拟地址的存储位置啊
Reply View the author
avatar
rekees2020
deepin
2020-07-22 06:40
#16
https://bbs.deepin.org/post/197502
swap是不是就是书上说的虚拟地址的存储位置啊

不知道能不能这样说,感觉有点不准确
swap文件大约相当于Windows的虚拟内存文件,但是Windows里休眠有单独的文件,是分开的
swap分区就是单独划一个分区来做swap
Reply View the author
avatar
mcaoser
deepin
2020-07-22 07:48
#17
其实卡,是给人的感觉,鼠标移不动,窗口打不开这些都会让人觉得卡,要解决的是这些现象,如果IO的优先级略为降低一些,在让人感觉卡的那些环节,将鼠标图标变成类似windows的沙漏图标,IO仅在后台运行,不影响前台的交互体验,不知会不会好些
Reply View the author
avatar
rekees2020
deepin
2020-07-22 07:54
#18
https://bbs.deepin.org/post/197502
其实卡,是给人的感觉,鼠标移不动,窗口打不开这些都会让人觉得卡,要解决的是这些现象,如果IO的优先级略 ...

那就得在交互的时候立即降低当前的高I/O,非交互的程序读写速度降低,比如复制文件变慢,这样硬盘才有能力响应,不然读写能力被耗尽,打开任何东西都会延迟
据说iOS就这样,手指一碰屏幕,整个系统就全副精力应对交互
Reply View the author
avatar
rekees2020
deepin
2020-07-22 07:56
#19
这样也不一定好吧?在保证流畅交互的情况下尽量满足后台需求才理想
Reply View the author
avatar
SamLukeYes
deepin
2020-07-22 16:13
#20
https://bbs.deepin.org/post/197502
如果上nvme协议的固态硬盘
是不是就不卡了?

会的,我的苏菲就是nvme的硬盘,只要在ntfs分区大量读或写就会卡
Reply View the author