[systemd-devel] systemd-213: regression with zram
Kai Krakow
hurikhan77 at gmail.com
Mon Jun 9 10:44:56 PDT 2014
Alexander E. Patrakov <patrakov at gmail.com> schrieb:
> 09.06.2014 19:26, Kai Krakow wrote:
>> Alexander E. Patrakov <patrakov at gmail.com> schrieb:
>>
>>> I have upgraded systemd from 212 to 213 on two my Gentoo boxes, and see
>>> the same regression here: zram swap space does not get activated. It
>>> looks like systemd tries to activate swap before the RUN+=mkswap part of
>>> the udev rule finishes.
>>>
>>> Here are the relevant lines from my configuration files. Are they indeed
>>> supposed to work, or were working only by pure luck?
>>
>> I switched to zswap because of this. This also looks more appropriate for
>> my workload. Maybe that's an option? At least if you do have a physical
>> swap device (and in that cased I'd prefer zswap over zram).
>
> Please don't persuade me to hide or tolerate bugs. Even if zswap is more
> appropriate, I would like to get a comment on my zram issue from systemd
> maintainers.
I didn't mean to persuade you but zram looks a little bit broken to me with
respect to configuration. So if zswap would be an option for you, it might
be the way to go instead of trying to work around quirks that cannot be
fixed easily. Of course, it is only an option if you also use a physical
swap device.
I had most success with putting zram statically into the kernel and put the
"num_devices" parameter into the kernel cmdline. But still you need to
"mkswap" these unprepared devices first - and that's not that easy with
systemd. I gave up on that part because it never worked out as expected and
instead went with zswap. However, that is a few months ago now and there
might be options to make it work now.
But even before systemd (with openrc), I had to mkswap first, then swapon. I
wasn't able to handle this automatically and reliably just through fstab.
The whole process of configuring the device first, then formatting the
device, and only then use it, makes it almost impossible to use it the way
systemd does things (execute on discovery).
The best way to go with systemd is probably by creating a service template
that does the above steps (configure, prepare, use) and depends on disovery
of the devices. Then enable as many service instances as you need and do not
put them into fstab. Something like:
# /etc/systemd/system/zram-swap at .service
...
[Service]
EnvironmentFile=/etc/conf.d/zram
ExecStartPre=echo -n $((1024*1024*$SIZE)) >/sys/block/%I/disksize
ExecStartPre=/sbin/mkswap /dev/%I
ExecStart=swapon /dev/%I
ExecStop=swapoff /dev/%I
$ systemctl enable zram-swap at zram{0,1,2,3}.service
I'm leaving out the [Unit] block and the dependencies to be used because I
have no way to test such a setup here. So it is left as an excercise. ;-)
But I think that's the only way to go. You cannot use it in fstab because
the device is just not ready at the time when systemd parses through fstab.
--
Replies to list only preferred.
More information about the systemd-devel
mailing list