如何使用zRam?

我按照webupd8.org上的描述安装了zRam。我是通过终端安装的。这样就可以了吗,还是我需要进行一些配置之类的操作?zram-enabler会自动完成所有工作,还是我需要设置一些参数?

从链接中提供的内容来看,似乎可以直接使用。 - Mahesh
7个回答

这是整个关于在Ubuntu中使用zRam的教程。

zRam is a code inside kernel, that once activated, creates a RAM based block device which acts as a swap disk, but is compressed and stored in memory, allowing very fast I/O and increasing the amount of memory available before the system starts swapping to disk.

zRam is integrated into the Linux kernel 3.2 and above, so it's included already in Ubuntu 12.04.

Previously on my 2GB machine, without zRAM, when i open lots of browser tabs, the system start choking, while HDD start copying data to SWAP causing a total slowdown. Now after activating zRam, instead of freezing after running out of RAM, the system worked like nothing happened. I didn't notice any difference at all. It looked just like adding more RAM ;)

From my experience, zRam is useful for people using computers with 1GB or 2GB RAM. Since zRam is compressing data, it require some processor resources. Not much, but always. For that reason i do not recommend to use it with old processors. Also if you have 4GB RAM most likely it won't be necessary to use it.

To activate it, type in terminal:

sudo apt-get install zram-config

To remove [type the following]:

sudo dpkg --purge zramswap-enabler
sudo dpkg --purge zram-config

2来源:http://mintnext.blogspot.co.uk/2012/11/increase-performance-with-zram.html - sourcejedi
zRam基本上是一种权衡,如果你的CPU太强大,而你的RAM量不够的话。最好是在CPU上投资少一点,在RAM上投资多一点,但如果你已经犯了这个错误,zRam可以帮助你。 - undefined

就像Sergey "Shnatsel" Davidoff在那篇博客文章中引用的那样,这个软件包安装了一个脚本,可以将其作为服务运行。该脚本会自动配置自身,并自动启动服务。不需要进一步的配置。可以通过以下方式手动控制该服务:
sudo service zramswap start|stop|status|restart|reload|force-reload

如果你用文件管理器打开deb包,你会发现只有两个文件被安装了。
/etc/init/zramswap.conf
/etc/init.d/zramswap

一起附带一些文档文件。 DEBIAN 目录包含软件包元数据和初始化服务的命令。这就是软件包中的全部内容。相应的设备按照以下方案命名:/dev/zram[0-9] 你是通过 PPA 安装的吗?我建议你这样做。

是的,我确实通过PPA安装了它。谢谢你的回答。你完美地回答了我的问题。所以我不需要每次开机时都启动它,对吧?它会自动启动,对吧? - Varun Venkatesh
没错。 - LiveWireBT
1在Ubuntu 12.04+版本中,现在可以通过sudo apt-get install zram-config进行安装。 - Sameer Puri

安装后,服务守护程序将立即启动。您可以在终端中输入以下命令来验证:
cat /proc/swaps

如果你有一个活动的交换分区/文件,应该会有一些/dev/XXX条目,并且至少有一个名称中带有"swap"的条目(我们系统上每个处理器核心都会有一个)。如果没有,请尝试重新启动并再次输入命令。

没有进一步的操作需要进行。



确保重新启动Ubuntu并检查Zram是否在启动时启动。
按照之前提到的说明,使用“cat /proc/swaps”命令来检查。
如果你没有看到列出你的zram交换设备(在我的情况下也是如此),那么请执行以下操作:
sudo su  
update-rc.d zramswap defaults

这将把zram列为启动服务。
重新启动并检查是否在启动时启动。

在我的Ubuntu 14.04 VPS上,我需要运行以下命令:

sudo apt-get install linux-image-extra-$(uname -r)
sudo apt-get install zram-config

第一行安装了zram内核模块。

请注意,在Ubuntu 21.10中,默认情况下(在树莓派上)已删除了zram模块,以减小initramfs的大小。因此,您需要采取额外的步骤来在树莓派上启用zram:
sudo apt install linux-modules-extra-raspi

另请参阅:在Ubuntu 21.10(树莓派4)上不再起作用的问题#71