Skip to content

feat(api): Add blkio cgroup tuning via --blkio flag#1595

Draft
chrisgeo wants to merge 3 commits into
apple:mainfrom
full-chaos:feat/chaos-1380-blkio-flags
Draft

feat(api): Add blkio cgroup tuning via --blkio flag#1595
chrisgeo wants to merge 3 commits into
apple:mainfrom
full-chaos:feat/chaos-1380-blkio-flags

Conversation

@chrisgeo
Copy link
Copy Markdown
Contributor

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

Closes #1512.

Adds block I/O cgroup tuning to container run / container create so
compose translators (e.g. container-compose) can pass through Docker
Compose service.blkio_config instead of warn-skipping it.

The CLI shape follows the grouped, repeatable key=value form proposed in
#1512 (comment):

container run --blkio weight=500 ...
container run --blkio device=/dev/sda,weight=700,leaf-weight=300 ...
container run --blkio device=/dev/sda,read-bps=1048576,write-bps=1048576 ...
container run --blkio device=/dev/sda,read-iops=1000,write-iops=1000 ...

The device= value accepts either an absolute host path (resolved via
stat(2) for major/minor) or a literal <major>:<minor>. Keys allowed
on a per-device spec: weight, leaf-weight, read-bps, write-bps,
read-iops, write-iops. Keys allowed on a global spec (no device=):
weight, leaf-weight. Parser rejects unknown keys, conflicting
global weights, and global-only keys mixed onto device-less specs.

Runtime plumbing

Block I/O propagates as ContainerConfiguration.Resources.blockIO
(serialised as ContainerizationOCI.LinuxBlockIO) and is converted to
Containerization.LinuxBlockIO at the runtime boundary in
RuntimeService.configureContainer.

Dependency

Depends on apple/containerization#739, which introduces
Containerization.LinuxBlockIO (the Sendable wrapper around the OCI
type) and wires it into LinuxContainer.Configuration. While that PR is
unmerged this branch pins containerization to the PR branch
(full-chaos/containerization@feat/chaos-1380-blkio-runtime,
revision 3d009df). Before merge, the pin must be moved back to
apple/containerization at whatever revision lands #739.

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

swift build clean, swift test --filter ParserTest passes
(105 tests, 5 new):

  • testResourcesBlockIOFlags — combined global + per-device + throttle
  • testResourcesBlockIOAcceptsMajorMinorLiteraldevice=8:0 literal
  • testResourcesRejectsInvalidBlockIOWeight — weight outside 10..1000
  • testResourcesRejectsUnknownBlockIOKey — typo detection
  • testResourcesRejectsGlobalKeyOnDeviceSpecread-bps without device=

container run --help confirmed renders the new --blkio flag.

chrisgeo added 3 commits May 23, 2026 17:16
Two changes addressing review feedback from
apple/containerization#739 and
apple#1512 (comment):

1. Adopt the new `Containerization.LinuxBlockIO` wrapper added in
   containerization PR apple#739 (pin advanced to 3d009df). The wire format in
   `ContainerConfiguration.Resources.blockIO` stays as the Codable
   `ContainerizationOCI.LinuxBlockIO`; `RuntimeService.configureContainer`
   converts to the wrapper at the boundary via the new
   `toContainerizationBlockIO` helper.

2. Replace the six separate `--blkio-*` / `--device-*` flags with a
   single repeatable `--blkio` flag using key=value[,key=value] syntax,
   per apple#1512 (comment):

       --blkio weight=500
       --blkio device=/dev/sda,weight=700,leaf-weight=300
       --blkio device=/dev/sda,read-bps=1048576,write-bps=1048576
       --blkio device=/dev/sda,read-iops=1000,write-iops=1000

   Device values accept either an absolute host path (resolved via stat(2))
   or a literal `<major>:<minor>`. Parser rejects unknown keys, conflicting
   global weights, and global-only keys appearing on device-less specs.

Tests cover the combined spec, major:minor literal, invalid-weight,
unknown-key, and global-only-on-device-spec error paths.
Comment thread Package.swift
],
dependencies: [
.package(url: "https://github.com/apple/containerization.git", exact: Version(stringLiteral: scVersion)),
.package(url: "https://github.com/full-chaos/containerization.git", branch: scVersion),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will remove before merge.

Comment thread .gitignore
_serve/
.vscode/**
.worktrees/**
.worktress/**
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will remove before merge.

Comment thread Package.resolved
Comment on lines 2 to 20
@@ -13,10 +13,10 @@
{
"identity" : "containerization",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/containerization.git",
"location" : "https://github.com/full-chaos/containerization.git",
"state" : {
"revision" : "db5b5b98405d53543f69105087130ffd623a5b9a",
"version" : "0.32.2"
"branch" : "feat/chaos-1380-blkio-runtime",
"revision" : "3d009dfc2724fc924dd18ca2014b5e839d554163"
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will revert before merge.

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.

[Request] Add blkio/cgroup BFQ tuning flags to container run/create

1 participant