[systemd-devel] Regarding how to properly use zram on a systemd setup

Alexander E. Patrakov patrakov at gmail.com
Sun Feb 2 05:21:34 PST 2014

02.02.2014 17:23, Pacho Ramos wrote:
> Hello
> After reading:
> http://www.chromestory.com/2013/03/google-enabling-zram-for-chrome-os-by-default/
> http://lwn.net/Articles/545244/
> I was wondering what would be the best way to use zram on a setup
> running systemd. This is because I have found a lot of scripts, unit
> files... but I don't know what is the best approach (at least from an
> "upstream point of view"):
> http://mystilleef.blogspot.com.es/2011/10/enable-zram-in-fedora.html
> http://software.opensuse.org/package/systemd-zram-service
> https://aur.archlinux.org/packages/zramswap/
> I found this thread:
> http://lists.freedesktop.org/archives/systemd-devel/2012-November/007444.html
> In that one Lennart suggest that maybe some action from util-linux
> maintainers could help but, after that message, I don't see anything
> newer (maybe we could report that suggestion to util-linux maintainers
> to other place... or maybe a better solution was found later :/)
> Thanks a lot for your help and suggestions

Here is what I use. I don't claim this to be the best or even 
officially-approved solution. But this is based on the existing Gentoo 
documentation, found at 
http://wiki.gentoo.org/wiki/Zram#Using_existing_tools :)

$ cat /etc/udev/rules.d/10-zram.rules
KERNEL=="zram[0-9]", SUBSYSTEM=="block", DRIVER=="", ACTION=="add", 
ATTR{disksize}=="0", ATTR{disksize}="1536M", RUN+="/sbin/mkswap 

$ cat /etc/fstab
# /etc/fstab: static file system information.
<snip irrelenavt lines>
/dev/zram0      none            swap            pri=10,discard  0 0
/dev/zram1      none            swap            pri=10,discard  0 0
/dev/zram2      none            swap            pri=10,discard  0 0
/dev/zram3      none            swap            pri=10,discard  0 0

Note that "discard" is essential here (and not mentioned in the Gentoo 
wiki) so that zram returns once-used compressed swap to the system.

$ cat /etc/modprobe.d/zram.conf
options zram num_devices=4

$ cat /etc/modules-load.d/zram.conf

Alexander E. Patrakov

More information about the systemd-devel mailing list