Skip to content

systemd/v2: set MemorySwapMax=0 when disabling swap - #78

Open
kolyshkin wants to merge 1 commit into
opencontainers:mainfrom
kolyshkin:systemd-swap-zero
Open

kolyshkin wants to merge 1 commit into
opencontainers:mainfrom
kolyshkin:systemd-swap-zero

Conversation

@kolyshkin

Copy link
Copy Markdown
Contributor

When memory and memorySwap are set to the same value (i.e. swap is
disabled), ConvertMemorySwapToCgroupV2Value returns 0. The fs2 driver
special-cases this and writes 0 to memory.swap.max, but the systemd
driver only sets MemorySwapMax if swap != 0, treating explicit zero
the same as unset.

As a result, the unit's MemorySwapMax stays at infinity, and the next
systemctl daemon-reload resets memory.swap.max back to max, silently
re-enabling swap for the container.

Set MemorySwapMax=0 in this case, same as fs2 does, and add a test
(which fails without the fix).

Fixes: #74

When memory and memorySwap are set to the same value (i.e. swap is
disabled), ConvertMemorySwapToCgroupV2Value returns 0. The fs2 driver
special-cases this and writes 0 to memory.swap.max, but the systemd
driver only sets MemorySwapMax if swap != 0, treating explicit zero
the same as unset.

As a result, the unit's MemorySwapMax stays at infinity, and the next
systemctl daemon-reload resets memory.swap.max back to max, silently
re-enabling swap for the container.

Set MemorySwapMax=0 in this case, same as fs2 does, and add a test.

Fixes: opencontainers#74
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin
kolyshkin requested a review from a team as a code owner October 2, 2026 06:24
@kolyshkin kolyshkin added this to the 0.1.1 milestone Oct 2, 2026
@kolyshkin
kolyshkin requested a review from thaJeztah October 2, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

systemd/v2: swap disabled via MemorySwap == Memory is not exported as MemorySwapMax, so daemon-reload resets memory.swap.max to max

1 participant