-
Notifications
You must be signed in to change notification settings - Fork 278
Add LinuxContainer block I/O resources #739
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
Open
chrisgeo
wants to merge
2
commits into
apple:main
Choose a base branch
from
full-chaos:feat/chaos-1380-blkio-runtime
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+183
−3
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // Copyright © 2025-2026 Apple Inc. and the Containerization project authors. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import ContainerizationOCI | ||
|
|
||
| /// Block I/O resource limits applied to the container cgroup. | ||
| public struct LinuxBlockIO: Sendable { | ||
| /// The relative weight of the cgroup for block I/O. Valid range is 10 to 1000. | ||
| public var weight: UInt16? | ||
| /// The relative weight applied to tasks of the cgroup but not their descendant cgroups. | ||
| public var leafWeight: UInt16? | ||
| /// Per-device weight overrides. | ||
| public var weightDevice: [LinuxWeightDevice] | ||
| /// Per-device read rate limits in bytes per second. | ||
| public var throttleReadBpsDevice: [LinuxThrottleDevice] | ||
| /// Per-device write rate limits in bytes per second. | ||
| public var throttleWriteBpsDevice: [LinuxThrottleDevice] | ||
| /// Per-device read rate limits in IO operations per second. | ||
| public var throttleReadIOPSDevice: [LinuxThrottleDevice] | ||
| /// Per-device write rate limits in IO operations per second. | ||
| public var throttleWriteIOPSDevice: [LinuxThrottleDevice] | ||
|
|
||
| public init( | ||
| weight: UInt16? = nil, | ||
| leafWeight: UInt16? = nil, | ||
| weightDevice: [LinuxWeightDevice] = [], | ||
| throttleReadBpsDevice: [LinuxThrottleDevice] = [], | ||
| throttleWriteBpsDevice: [LinuxThrottleDevice] = [], | ||
| throttleReadIOPSDevice: [LinuxThrottleDevice] = [], | ||
| throttleWriteIOPSDevice: [LinuxThrottleDevice] = [] | ||
| ) { | ||
| self.weight = weight | ||
| self.leafWeight = leafWeight | ||
| self.weightDevice = weightDevice | ||
| self.throttleReadBpsDevice = throttleReadBpsDevice | ||
| self.throttleWriteBpsDevice = throttleWriteBpsDevice | ||
| self.throttleReadIOPSDevice = throttleReadIOPSDevice | ||
| self.throttleWriteIOPSDevice = throttleWriteIOPSDevice | ||
| } | ||
|
|
||
| /// Convert to OCI format for transport. | ||
| public func toOCI() -> ContainerizationOCI.LinuxBlockIO { | ||
| ContainerizationOCI.LinuxBlockIO( | ||
| weight: self.weight, | ||
| leafWeight: self.leafWeight, | ||
| weightDevice: self.weightDevice.map { $0.toOCI() }, | ||
| throttleReadBpsDevice: self.throttleReadBpsDevice.map { $0.toOCI() }, | ||
| throttleWriteBpsDevice: self.throttleWriteBpsDevice.map { $0.toOCI() }, | ||
| throttleReadIOPSDevice: self.throttleReadIOPSDevice.map { $0.toOCI() }, | ||
| throttleWriteIOPSDevice: self.throttleWriteIOPSDevice.map { $0.toOCI() } | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| /// A per-device block I/O weight override. | ||
| public struct LinuxWeightDevice: Sendable { | ||
| /// The major device number. | ||
| public var major: Int64 | ||
| /// The minor device number. | ||
| public var minor: Int64 | ||
| /// The relative weight applied to the device. Valid range is 10 to 1000. | ||
| public var weight: UInt16? | ||
| /// The relative weight applied to tasks of the cgroup but not their descendant cgroups. | ||
| public var leafWeight: UInt16? | ||
|
|
||
| public init( | ||
| major: Int64, | ||
| minor: Int64, | ||
| weight: UInt16? = nil, | ||
| leafWeight: UInt16? = nil | ||
| ) { | ||
| self.major = major | ||
| self.minor = minor | ||
| self.weight = weight | ||
| self.leafWeight = leafWeight | ||
| } | ||
|
|
||
| /// Convert to OCI format for transport. | ||
| public func toOCI() -> ContainerizationOCI.LinuxWeightDevice { | ||
| ContainerizationOCI.LinuxWeightDevice( | ||
| major: self.major, | ||
| minor: self.minor, | ||
| weight: self.weight, | ||
| leafWeight: self.leafWeight | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| /// A per-device block I/O throughput limit. | ||
| public struct LinuxThrottleDevice: Sendable { | ||
| /// The major device number. | ||
| public var major: Int64 | ||
| /// The minor device number. | ||
| public var minor: Int64 | ||
| /// The rate limit applied to the device. | ||
| public var rate: UInt64 | ||
|
|
||
| public init(major: Int64, minor: Int64, rate: UInt64) { | ||
| self.major = major | ||
| self.minor = minor | ||
| self.rate = rate | ||
| } | ||
|
|
||
| /// Convert to OCI format for transport. | ||
| public func toOCI() -> ContainerizationOCI.LinuxThrottleDevice { | ||
| ContainerizationOCI.LinuxThrottleDevice( | ||
| major: self.major, | ||
| minor: self.minor, | ||
| rate: self.rate | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer we don't use the OCI types directly (it gives us a little wiggle room to add various knobs). You can add a new LinuxBlockIO type in Containerization and use this and just convert to the oci variant like we do for other things in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback.
Does this new shape align with what you were imagining?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dcantah @chrisgeo see apple/container#1512 (comment) for thoughts on
containerUX as well.