[systemd-devel] systemd-way for initialization zram swap

Maksim 'max_posedon' Melnikau maxposedon at gmail.com
Mon Nov 19 11:47:45 PST 2012


Hello, there is a nice concept of using "level one" swap in compressed
memory - zram ( http://code.google.com/p/compcache/ ).
I would like to have it auto initialized in my system,  and even more,
I think it is very nice concept and almost all embedded and desktop
should have this enabled.
I tried google a solution for it, and find some "bash-style"
implementation (
http://mystilleef.blogspot.com/2011/10/enable-zram-in-fedora.html ),
which I didn't like.
I would like to "re-implement" in systemd way, and looking for help.

Q1: Could somebody suggest better solution, then below?
Q2: Could we have smth like this in upstream, much simplified for
users? General rule could be: create N zram swap disks, and assign Y
ram for each, where N=count of CPUs, Y=ALL RAM/N/2

My solutioon:
1. use tmpfiles.d to initialize disk size
2. use fstab to notify system about swap disks
3. use udev rules, for mkswap at boot

# cat /proc/cmdline
BOOT_IMAGE=/kernel-genkernel-x86_64-3.6.6-gentoo root=/dev/sda7 ro
rootfstype=btrfs pcie_aspm=force acpi_backlight=vendor
nouveau.perflvl_wr=7777 zram.num_devices=4 init=/bin/systemd

# cat /etc/udev/rules.d/70-zram.rules
KERNEL=="zram*", ACTION=="add", RUN="/sbin/mkswap /$root/$name"

# cat /etc/tmpfiles.d/zram.conf
w /sys/block/zram0/disksize - - - - 1073741824
w /sys/block/zram1/disksize - - - - 1073741824
w /sys/block/zram2/disksize - - - - 1073741824
w /sys/block/zram3/disksize - - - - 1073741824

# cat /etc/fstab | grep swap
/dev/zram0                                swap            swap
sw,pri=1                                 0       0
/dev/zram1                                swap            swap
sw,pri=1                                 0       0
/dev/zram2                                swap            swap
sw,pri=1                                 0       0
/dev/zram3                                swap            swap
sw,pri=1                                 0       0

It works well,

# journalctl -o short | grep zram
Nov 19 22:31:08 m_melnikau-M11xR3 kernel: zram: Creating 4 devices ...
Nov 19 22:31:08 m_melnikau-M11xR3 systemd[1]: Expecting device
dev-zram0.device...
Nov 19 22:31:08 m_melnikau-M11xR3 systemd[1]: Expecting device
dev-zram1.device...
Nov 19 22:31:08 m_melnikau-M11xR3 systemd[1]: Expecting device
dev-zram2.device...
Nov 19 22:31:08 m_melnikau-M11xR3 systemd[1]: Expecting device
dev-zram3.device...
Nov 19 22:31:10 m_melnikau-M11xR3 systemd[1]: Found device /dev/zram1.
Nov 19 22:31:10 m_melnikau-M11xR3 systemd[1]: Activating swap /dev/zram1...
Nov 19 22:31:10 m_melnikau-M11xR3 kernel: Adding 1048572k swap on
/dev/zram1.  Priority:1 extents:1 across:1048572k SS
Nov 19 22:31:10 m_melnikau-M11xR3 systemd[1]: Found device /dev/zram0.
Nov 19 22:31:10 m_melnikau-M11xR3 systemd[1]: Activating swap /dev/zram0...
Nov 19 22:31:10 m_melnikau-M11xR3 systemd[1]: Activated swap /dev/zram1.
Nov 19 22:31:10 m_melnikau-M11xR3 kernel: Adding 1048572k swap on
/dev/zram0.  Priority:1 extents:1 across:1048572k SS
Nov 19 22:31:10 m_melnikau-M11xR3 systemd[1]: Activated swap /dev/zram0.
Nov 19 22:31:10 m_melnikau-M11xR3 systemd[1]: Found device /dev/zram2.
Nov 19 22:31:10 m_melnikau-M11xR3 systemd[1]: Activating swap /dev/zram2...
Nov 19 22:31:10 m_melnikau-M11xR3 systemd[1]: Found device /dev/zram3.
Nov 19 22:31:10 m_melnikau-M11xR3 kernel: Adding 1048572k swap on
/dev/zram2.  Priority:1 extents:1 across:1048572k SS
Nov 19 22:31:10 m_melnikau-M11xR3 systemd[1]: Activating swap /dev/zram3...
Nov 19 22:31:10 m_melnikau-M11xR3 kernel: Adding 1048572k swap on
/dev/zram3.  Priority:1 extents:1 across:1048572k SS
Nov 19 22:31:10 m_melnikau-M11xR3 systemd[1]: Activated swap /dev/zram2.
Nov 19 22:31:10 m_melnikau-M11xR3 systemd[1]: Activated swap /dev/zram3.
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** ADDING
/sys/devices/virtual/block/zram0
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** UPDATING
/sys/devices/virtual/block/zram0
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** ADDED
/sys/devices/virtual/block/zram0
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** ADDING
/sys/devices/virtual/block/zram1
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** UPDATING
/sys/devices/virtual/block/zram1
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** ADDED
/sys/devices/virtual/block/zram1
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** ADDING
/sys/devices/virtual/block/zram2
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** UPDATING
/sys/devices/virtual/block/zram2
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** ADDED
/sys/devices/virtual/block/zram2
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** ADDING
/sys/devices/virtual/block/zram3
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** UPDATING
/sys/devices/virtual/block/zram3
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** ADDED
/sys/devices/virtual/block/zram3
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** CHANGING
/sys/devices/virtual/block/zram0
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** UPDATING
/sys/devices/virtual/block/zram0
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** CHANGED
/sys/devices/virtual/block/zram0
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** CHANGING
/sys/devices/virtual/block/zram1
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** UPDATING
/sys/devices/virtual/block/zram1
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** CHANGED
/sys/devices/virtual/block/zram1
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** CHANGING
/sys/devices/virtual/block/zram2
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** UPDATING
/sys/devices/virtual/block/zram2
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** CHANGED
/sys/devices/virtual/block/zram2
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** CHANGING
/sys/devices/virtual/block/zram3
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** UPDATING
/sys/devices/virtual/block/zram3
Nov 19 22:32:22 m_melnikau-M11xR3 dbus-daemon[2126]: **** CHANGED
/sys/devices/virtual/block/zram3


More information about the systemd-devel mailing list