Skip to content

Commit

Permalink
Let the swap unit remain survive shutdown
Browse files Browse the repository at this point in the history
Swap units have automatic dependencies of Before=swap.target,shutdown.target,
Conflicts=shutdown.target. By adding DefaultDependencies=no, Before=swap.target,
we effective drop the negative dependency with shutdown.target and allow the
swap device to survive shutdown.

There is no need to bring down the swap device during shutdown. This wastes
work, because any remaning pages need to be dropped or decompressed and moved
to normal memory. Normally this is very quick, but the report says that it
takes 15–20 seconds in their case.

Closes #191.
  • Loading branch information
keszybz committed Nov 21, 2024
1 parent 597d429 commit d69ff7b
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,12 @@ fn handle_zram_swap(output_directory: &Path, device: &Device) -> Result<()> {
[Unit]
Description=Compressed Swap on /dev/{zram_device}
Documentation=man:zram-generator(8) man:zram-generator.conf(5)
DefaultDependencies=no
Requires=systemd-zram-setup@{zram_device}.service
After=systemd-zram-setup@{zram_device}.service
Before=swap.target
[Swap]
What=/dev/{zram_device}
Expand Down
4 changes: 4 additions & 0 deletions tests/01-basic/run.expected/units/dev-zram0.swap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
[Unit]
Description=Compressed Swap on /dev/zram0
Documentation=man:zram-generator(8) man:zram-generator.conf(5)

DefaultDependencies=no

[email protected]
[email protected]
Before=swap.target

[Swap]
What=/dev/zram0
Expand Down
4 changes: 4 additions & 0 deletions tests/02-zstd/run.expected/units/dev-zram0.swap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
[Unit]
Description=Compressed Swap on /dev/zram0
Documentation=man:zram-generator(8) man:zram-generator.conf(5)

DefaultDependencies=no

[email protected]
[email protected]
Before=swap.target

[Swap]
What=/dev/zram0
Expand Down
4 changes: 4 additions & 0 deletions tests/04-dropins/run.expected/units/dev-zram0.swap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
[Unit]
Description=Compressed Swap on /dev/zram0
Documentation=man:zram-generator(8) man:zram-generator.conf(5)

DefaultDependencies=no

[email protected]
[email protected]
Before=swap.target

[Swap]
What=/dev/zram0
Expand Down
4 changes: 4 additions & 0 deletions tests/04-dropins/run.expected/units/dev-zram2.swap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
[Unit]
Description=Compressed Swap on /dev/zram2
Documentation=man:zram-generator(8) man:zram-generator.conf(5)

DefaultDependencies=no

[email protected]
[email protected]
Before=swap.target

[Swap]
What=/dev/zram2
Expand Down
4 changes: 4 additions & 0 deletions tests/06-kernel-enabled/run.expected/units/dev-zram0.swap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
[Unit]
Description=Compressed Swap on /dev/zram0
Documentation=man:zram-generator(8) man:zram-generator.conf(5)

DefaultDependencies=no

[email protected]
[email protected]
Before=swap.target

[Swap]
What=/dev/zram0
Expand Down
4 changes: 4 additions & 0 deletions tests/09-zram-size/run.expected/units/dev-zram0.swap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
[Unit]
Description=Compressed Swap on /dev/zram0
Documentation=man:zram-generator(8) man:zram-generator.conf(5)

DefaultDependencies=no

[email protected]
[email protected]
Before=swap.target

[Swap]
What=/dev/zram0
Expand Down
4 changes: 4 additions & 0 deletions tests/10-example/run.expected/units/dev-zram0.swap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
[Unit]
Description=Compressed Swap on /dev/zram0
Documentation=man:zram-generator(8) man:zram-generator.conf(5)

DefaultDependencies=no

[email protected]
[email protected]
Before=swap.target

[Swap]
What=/dev/zram0
Expand Down
4 changes: 4 additions & 0 deletions tests/11-obsolete/run.expected/units/dev-zram0.swap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
[Unit]
Description=Compressed Swap on /dev/zram0
Documentation=man:zram-generator(8) man:zram-generator.conf(5)

DefaultDependencies=no

[email protected]
[email protected]
Before=swap.target

[Swap]
What=/dev/zram0
Expand Down
4 changes: 4 additions & 0 deletions tests/11-obsolete/run.expected/units/dev-zram1.swap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
[Unit]
Description=Compressed Swap on /dev/zram1
Documentation=man:zram-generator(8) man:zram-generator.conf(5)

DefaultDependencies=no

[email protected]
[email protected]
Before=swap.target

[Swap]
What=/dev/zram1
Expand Down

0 comments on commit d69ff7b

Please sign in to comment.