Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libct/cg/fs2/freezer: optimize and fix #2955

Merged
merged 3 commits into from
May 20, 2021

Conversation

kolyshkin
Copy link
Contributor

@kolyshkin kolyshkin commented May 14, 2021

fs2.setFreezer improvements:

  1. Optimize it to do 1 open instead of 3 (or 0 instead of 1 in case config.Undefined is passed).
  2. Fix it to actually wait for freeze to be finished.

Please see individual commits for details.

Note: I chose to use simple wait/retry for re-reading cgroup.events. An implementation based on poll(2) or inotify(7) is possible, but it makes things more complicated. If needed, a poll- or inotify-based waiting can be add later.

@kolyshkin kolyshkin marked this pull request as ready for review May 15, 2021 02:31
@kolyshkin kolyshkin added this to the 1.0.0 milestone May 18, 2021
@AkihiroSuda
Copy link
Member

Note: I chose to use simple wait/retry for re-reading cgroup.events. An implementation based on poll(2) or inotify(7) is possible, but it makes things more complicated. If needed, a poll- or inotify-based waiting can be add later.

Could you mention inotify in the code comments as TODO (or just open an issue for inotify), then LGTM

@cyphar
Copy link
Member

cyphar commented May 19, 2021

LGTM aside from Akihiro's nit.

In case configs.Undefined or any wrong value is passed, there is no need
to check whether the freezer is supported.

Move arguments check to the beginning to avoid an unnecessary call to
supportFreezer().

While at it, simplify the "whether to return an error if freezer is not
supported" check.

Signed-off-by: Kir Kolyshkin <[email protected]>
Before this patch, setFreezer does

- open/read/close (to check if the freezer is supported)
- open/write/close (to set the value)
- open/read/close (to check the value)

Three opens is a bit excessive. Refactor to only open the file once:

- open (to check if the freezer is supported)
- write (to set the value)
- seek/read (to check the value)
- close

Signed-off-by: Kir Kolyshkin <[email protected]>
According to cgroup v2 documentation [1]:

> Freezing of the cgroup may take some time; when this action is
> completed, the “frozen” value in the cgroup.events control file will
> be updated to “1” and the corresponding notification will be issued.

Implement polling of cgroup.events, waiting for "frozen 1" to appear.
In case something goes wrong, limit the maximum number of retries and
return "undefined" after some time (currently 10s).

[1] https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html

Signed-off-by: Kir Kolyshkin <[email protected]>
@kolyshkin
Copy link
Contributor Author

Could you mention inotify in the code comments as TODO (or just open an issue for inotify), then LGTM

Added a XXX comment (as this is "maybe TODO" rather than a hard TODO).

(I actually did a poll(2)-based implementation but it looked so horrible I ditched it. Haven't tried inotify yet (although there's already an implementation in libcontainter/notify_linux_v2.go that can possibly be reused.)

Copy link
Member

@cyphar cyphar left a comment

Choose a reason for hiding this comment

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

LGTM.

@kolyshkin
Copy link
Contributor Author

Fedora CI failed during vagrant up; restarted

@AkihiroSuda AkihiroSuda added the status/merge-on-green Merge on CI green label May 20, 2021
@cyphar cyphar closed this in 57d353d May 20, 2021
@cyphar cyphar merged commit 57d353d into opencontainers:master May 20, 2021
@kolyshkin kolyshkin mentioned this pull request Jun 1, 2021
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants