nefelim4ag / systemd-swap

Script for creating hybrid swap space from zram swaps, swap files and swap partitions.
GNU General Public License v3.0
546 stars 81 forks source link

long boot times with zram_count=16 #200

Open mabod opened 3 years ago

mabod commented 3 years ago

I am using endeavourOS with systemd-swap 4.4.0-2.

Since the last update I experienced very long boot times of almost 2 min. For me it seemed to be related to the systemd update to 247.4-2. A similar issue is reported for systemd https://github.com/systemd/systemd/issues/15316

The solution mentioned there is also working for me:

sudo pacman -S dbus-broker
sudo systemctl enable dbus-broker.service

But in the meantime I did more investigations and found that systemd-swap has something to do with it.

This is the config I used to use:

zram_enabled=1
zram_size=$(( RAM_SIZE / 8 ))
zram_count=${NCPU}
zram_alg=lz4

This creates 16 zram devices with 502 MB each. (64 GB of RAM)

Without dbus-broker I get very long start times like

48.988s systemd-swap.service

with dbus-broker enabled the start time is much faster.

3.805s systemd-swap.service

But if I set zram_count=1, which creates one zram device of size 7,9 GB. the start time is even faster even without dbus-broker:

1.659s systemd-swap.service

Why is that? What is the dependency to dbus-broker all about?

vilgotf commented 3 years ago

First thing, you should always use only one zram device since there's no performance improvement from having multiple (this should be documented). Secondly I'd recommend systemd/zram-generator if you only use zram (should also be documented).

I'll keep this issue in mind, but don't expect any patches soon.

mabod commented 3 years ago

First thing, you should always use only one zram device since there's no performance improvement from having multiple (this should be documented).

That is interesting because the default behavior is actually that it creates ${NCPU} zram devices. I just tested it by commenting the zram_count in the config file. Shouldnt the default then be just one zram device?

And it does not explain where the dependency to dbus-broker is coming from: 49 s without dbus-broker compared to 4 s with dbus-broker is a big difference.

HidingCherry commented 3 years ago

Please read this: https://www.kernel.org/doc/html/latest/admin-guide/blockdev/zram.html#set-max-number-of-compression-streams

Since we have multiple streams per zram device - there is no use to have multiple zram devices. An exception might be with multiple NUMA devices? Although - I don't know if the kernel takes this into account.

polarathene commented 2 years ago

The referenced systemd issue got resolved, bug was identified as something missed during 2016 commit. PR was merged recently for upcoming v251 release of systemd.

dbus-broker avoided the issue as it doesn't try to do some logic that dbus-daemon was doing (which IIRC was timing out from a deadlock or something like that), dbus-daemon also queues messages differently I think, so your experience with multiple devices vs single was likely related to behaviour with that?

Should be safe to close issue? (unless you want to wait for v251 release and broader availability)

mabod commented 2 years ago

From my point of view it can be closed. Thank you! But can you share a link to the systemd PR here?

polarathene commented 2 years ago

can you share a link to the systemd PR here?

https://github.com/systemd/systemd/pull/22552