-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add io weight control on image operator #26
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
base: v1.7
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -166,6 +166,23 @@ type MetricsConfig struct { | |||||||||
| // CgroupConfig provides cgroup configuration | ||||||||||
| type CgroupConfig struct { | ||||||||||
| Path string `toml:"path"` | ||||||||||
| // Blkio configures block IO control for containerd operations (cgroups v2) | ||||||||||
| Blkio BlkioConfig `toml:"blkio"` | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // BlkioConfig provides block IO configuration for cgroups v2 | ||||||||||
| type BlkioConfig struct { | ||||||||||
| // Weight is the IO weight value (10-1000) for image pull, unpack, and commit operations. | ||||||||||
| // Set to 0 to disable IO weight control. Default is 0 (disabled). | ||||||||||
|
||||||||||
| // Set to 0 to disable IO weight control. Default is 0 (disabled). | |
| // Set to 0 to disable IO weight control. Default is 0 (disabled). Any non-zero value | |
| // outside the valid range (10-1000) will be treated as invalid, causing IO weight | |
| // control to be disabled and a warning to be emitted. |
Copilot
AI
Jan 7, 2026
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.
The Weight field is defined as int which allows negative values. Since the valid range is 10-1000 (or 0 to disable), negative values don't make semantic sense. Consider changing the type to uint16 to match the internal Config type and prevent invalid negative values from being specified in configuration files.
| Weight int `toml:"weight"` | |
| Weight uint16 `toml:"weight"` |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -33,6 +33,7 @@ import ( | |||||||||||||||||||||||||
| "github.com/containerd/containerd/services" | ||||||||||||||||||||||||||
| "github.com/containerd/containerd/services/warning" | ||||||||||||||||||||||||||
| "github.com/containerd/containerd/snapshots" | ||||||||||||||||||||||||||
| "github.com/containerd/containerd/sys/blkiorun" | ||||||||||||||||||||||||||
| "github.com/containerd/log" | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -165,7 +166,13 @@ func (s *service) Commit(ctx context.Context, cr *snapshotsapi.CommitSnapshotReq | |||||||||||||||||||||||||
| if cr.Labels != nil { | ||||||||||||||||||||||||||
| opts = append(opts, snapshots.WithLabels(cr.Labels)) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| if err := sn.Commit(ctx, cr.Name, cr.Key, opts...); err != nil { | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Run with configured IO weight (if enabled) | ||||||||||||||||||||||||||
| _, err = blkiorun.Go(func() (struct{}, error) { | ||||||||||||||||||||||||||
| return struct{}{}, sn.Commit(ctx, cr.Name, cr.Key, opts...) | ||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||
| return nil, errdefs.ToGRPC(err) | ||||||||||||||||||||||||||
|
Comment on lines
+171
to
176
|
||||||||||||||||||||||||||
| _, err = blkiorun.Go(func() (struct{}, error) { | |
| return struct{}{}, sn.Commit(ctx, cr.Name, cr.Key, opts...) | |
| }) | |
| if err != nil { | |
| return nil, errdefs.ToGRPC(err) | |
| _, commitErr := blkiorun.Go(func() (struct{}, error) { | |
| return struct{}{}, sn.Commit(ctx, cr.Name, cr.Key, opts...) | |
| }) | |
| if commitErr != nil { | |
| return nil, errdefs.ToGRPC(commitErr) |
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.
The Weight field is typed as
intin BlkioConfig but is being cast touint16here. This could cause issues if a negative value is provided in the configuration. Consider validating that blkioConfig.Weight is non-negative before casting, or change the BlkioConfig.Weight field type to uint16 to prevent negative values at the configuration level.