Skip to content

Conversation

@kolyshkin
Copy link
Contributor

This is a combo of #3065 and #3072, fixing issues resulting in kubernetes revert of runc 1.0.0 vendoring.

  1. Fix cgroup v1 GetFreezerState to not report cgroup state as frozen if a parent cgroup is frozen.

    After the fix, we only report the cgroup is frozen if it is frozen directly (and not via an ancestor).
    This is how cgroup v2 GetFreezerState works, so now there's no discrepancy between v1 and v2 behavior.

  2. Fix cgroup/systemd v1 Set to not leave sub-cgroup frozen in case a parent cgroup is frozen.

    This issue mostly stems from the GetFreezerState reporting incorrect state (fixed above).

  3. Cleanup cgroup/systemd v1 freeze/thaw code (do not overwrite cgroup resources freezer).

  4. Avoid unnecessary freeze/thaw.

  5. Tests for all the above issues.

Co-authored-by: @odinuge

If a control group is frozen, all its descendants will report FROZEN
in freezer.state cgroup file.

OTOH cgroup v2 cgroup.freeze is not reporting the cgroup as frozen
unless it is frozen directly (i.e. not via an ancestor).

Fix the discrepancy between v1 and v2 drivers behavior by
looking into freezer.self_freezing cgroup file, which, according
to kernel documentation, will show 1 iff the cgroup was frozen directly.

Co-authored-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Odin Ugedal <odin@uged.al>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Comment on lines +283 to +285
if err == nil {
m.cgroups.Resources.Freezer = state
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is necessary, but am inclined to keep this just in case.

kolyshkin and others added 2 commits July 8, 2021 17:29
We do a temporary freeze/unfreeze around setting systemd unit
properties. There are two minor issues around it:

First, m.Freeze method changes m.cgroups.Resources.Frozen field, which
it shouldn't. Fix this by adding/using a method which does not changes
it.

Second, the current code does freeze/thaw unconditionally, meaning it
also freezes the already frozen cgroup (which is a no-op except it still
requires some reads and writes to freezer.state), and thaws the cgroup
which is about to be frozen again. Fix by making freeze/unfreeze
conditional.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This test the issues fixed by the two preceding commits.

Co-Authored-By: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Odin Ugedal <odin@uged.al>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin
Copy link
Contributor Author

As suggested in #3065 (comment), this can be further improved to avoid the freeze entirely if we're sure systemd won't set the deny-all device rule.

Looking at
https://github.com/systemd/systemd/blob/dd376574fd62c6fcf446ee500ca85558a71d645e/src/core/cgroup.c#L1130-L1133
it seems that freeze can be skipped if DevicePolicy is auto (which is the default) AND DeviceAllow list is empty.

@kolyshkin
Copy link
Contributor Author

Split into #3081 and #3082

@kolyshkin kolyshkin closed this Jul 9, 2021
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.

2 participants