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

refactor cgroup to allow multiple properties per controller #4387

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mancio-aws
Copy link

@mancio-aws mancio-aws commented Jan 19, 2024

The previous Cgroup implementation used a separate object per every cgroup property. This lead to additional calls to create_dir_all and writes to cgroup.procs, especially in cgroupsv2 where there is only one hierarchy.

This change prevents the duplication by refactoring the code into:

  • CgroupConfiguration: this holds multiple cgroup properties in multiple cgroup controllers and hierarchies
  • Cgroup: this holds the configuration for a hierarchy and holds multiple properties
  • CgroupProperty: a file to value mapping of the cgroup properties to be written.

The CgroupBuilder is changed to a CgroupConfigurationBuilder so that the setup of the Cgroup is abstracted away from the environment.

Additionally, in the CgroupV2 the available controllers read from cgroup.controllers are cached to avoid multiple unnecessary reads.

Same as #4384 but without the hacky integ test

Fixes: #2856

Changes

...

Reason

...

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following
Developer Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.

PR Checklist

  • If a specific issue led to this PR, this PR closes the issue.
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • API changes follow the Runbook for Firecracker API changes.
  • User-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.
  • New TODOs link to an issue.
  • Commits meet contribution quality standards.

  • This functionality cannot be added in rust-vmm.

Copy link

codecov bot commented Jan 19, 2024

Codecov Report

Attention: 15 lines in your changes are missing coverage. Please review.

Comparison is base (b56d201) 81.52% compared to head (de87c40) 81.63%.

Files Patch % Lines
src/jailer/src/cgroup.rs 91.42% 9 Missing ⚠️
src/jailer/src/env.rs 45.45% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4387      +/-   ##
==========================================
+ Coverage   81.52%   81.63%   +0.11%     
==========================================
  Files         241      241              
  Lines       29296    29322      +26     
==========================================
+ Hits        23883    23938      +55     
+ Misses       5413     5384      -29     
Flag Coverage Δ
4.14-c5n.metal 78.92% <87.06%> (+0.12%) ⬆️
4.14-c7g.metal ?
4.14-m5d.metal ?
4.14-m5n.metal 78.91% <87.06%> (+0.12%) ⬆️
4.14-m6a.metal 78.04% <87.06%> (+0.13%) ⬆️
4.14-m6g.metal 77.00% <87.06%> (+0.14%) ⬆️
4.14-m6i.metal 78.91% <87.06%> (+0.12%) ⬆️
4.14-m7g.metal 77.00% <87.06%> (+0.14%) ⬆️
5.10-c5n.metal 81.61% <87.06%> (+0.12%) ⬆️
5.10-c7g.metal ?
5.10-m5d.metal ?
5.10-m5n.metal 81.60% <87.06%> (+0.12%) ⬆️
5.10-m6a.metal 80.82% <87.06%> (+0.13%) ⬆️
5.10-m6g.metal 79.93% <87.06%> (+0.13%) ⬆️
5.10-m6i.metal 81.60% <87.06%> (+0.12%) ⬆️
5.10-m7g.metal 79.93% <87.06%> (+0.13%) ⬆️
6.1-c5n.metal 81.61% <87.06%> (+0.12%) ⬆️
6.1-c7g.metal ?
6.1-m5d.metal ?
6.1-m5n.metal 81.60% <87.06%> (+0.12%) ⬆️
6.1-m6a.metal 80.82% <87.06%> (+0.13%) ⬆️
6.1-m6g.metal 79.93% <87.06%> (+0.13%) ⬆️
6.1-m6i.metal 81.60% <87.06%> (+0.12%) ⬆️
6.1-m7g.metal 79.93% <87.06%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

This commit adds a new unit test that checks that cgroupv1
can set a simple property.

Signed-off-by: Riccardo Mancini <mancio@amazon.com>
The previous Cgroup implementation used a separate object per
every cgroup property. This lead to additional calls to
create_dir_all and writes to cgroup.procs, especially in
cgroupsv2 where there is only one hierarchy.

This change prevents the duplication by refactoring the code into:
 - CgroupConfiguration: this holds multiple cgroup properties in
     multiple cgroup controllers and hierarchies
 - Cgroup: this holds the configuration for a hierarchy and holds
     multiple properties
 - CgroupProperty: a file to value mapping of the cgroup properties
     to be written.

The CgroupBuilder is changed to a CgroupConfigurationBuilder so that
the setup of the Cgroup is abstracted away from the environment.

Additionally, in the CgroupV2 the available controllers read from
cgroup.controllers are cached to avoid multiple unnecessary reads.

Signed-off-by: Riccardo Mancini <mancio@amazon.com>
@pb8o pb8o self-assigned this Feb 1, 2024
@pb8o pb8o marked this pull request as ready for review February 1, 2024 15:44
@pb8o pb8o added Priority: Low Indicates that an issue or pull request should be resolved behind issues or pull requests labelled ` Status: Awaiting author Indicates that a pull request requires author action Type: Performance Status: Awaiting review Indicates that a pull request is ready to be reviewed and removed Status: Awaiting author Indicates that a pull request requires author action labels Feb 1, 2024
Copy link
Contributor

@pb8o pb8o left a comment

Choose a reason for hiding this comment

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

Mostly good to go from my side, just a few minor comments and I think we need a solution for that unreachable!.

let cgroup = CgroupV2::new(file, value, id, parent_cg, path)?;
Ok(Box::new(cgroup))
let CgroupConfiguration::V2(cgroup_conf_v2) = &mut self.cgroup_conf else {
unreachable!()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we return an error here?

CgroupConfigurationImpl::<T>(HashMap::new())
}

/// TODO
Copy link
Contributor

Choose a reason for hiding this comment

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

leftover?


writeln_special(location, pid)?;

Ok(())
}
}

impl<T: Cgroup> CgroupConfigurationImpl<T> {
/// TODO
Copy link
Contributor

Choose a reason for hiding this comment

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

leftover?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Low Indicates that an issue or pull request should be resolved behind issues or pull requests labelled ` Status: Awaiting review Indicates that a pull request is ready to be reviewed Type: Performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Duplicated attach_pid and create_dir_all on cgroup v2
2 participants