Skip to content

api: ignore negative values in SetLinuxCPUPeriod - #362

Open
pandaWall wants to merge 1 commit into
containerd:mainfrom
sig-cloudnative:make-SetLinuxCPUPeriod-take-an-unsigned-value
Open

pandaWall wants to merge 1 commit into
containerd:mainfrom
sig-cloudnative:make-SetLinuxCPUPeriod-take-an-unsigned-value

Conversation

@pandaWall

Copy link
Copy Markdown
Contributor

The CPU period (like the realtime period, whose setter already takes uint64) is semantically unsigned. The int64 signature combined with the UInt64() wrapper silently converted negative values into garbage 64-bit values (e.g. -1 becoming 18446744073709551615), which then failed container creation inside runc with errors that give no hint about the plugin-side cause.

Change both ContainerUpdate.SetLinuxCPUPeriod and
ContainerAdjustment.SetLinuxCPUPeriod to take a uint64 argument. The setters have no in-repo callers outside tests, so no call sites need updating. Out-of-tree plugins calling these setters with a signed value will now fail to compile instead of producing a broken adjustment at runtime, which is the desired failure mode.

Add a test covering the value round-trip through both setters.

@klihub

klihub commented Nov 18, 2026

Copy link
Copy Markdown
Member

...

Change both ContainerUpdate.SetLinuxCPUPeriod and ContainerAdjustment.SetLinuxCPUPeriod to take a uint64 argument...
...

Changing it this way would be a backward incompatible API change, for not much real gain.
This is a cgroup v1 cpu.cfs_period_us parameter with an accepted range [1000 - 1000000] so there is no need for an uint64 range. IIUC, when on cgroup v2 the corresponding 'converted' cpu.max $PERIOD parameter has the same range, so no need for uint64 there either.

The various other components/interfaces are already inconsistent about this. For instance, CRI uses an int64 on the wire, and I think that's why we unfortunately ended up with an int64 for the function signature, and converting it to uint64.

So I wouldn't break the API for this. Maybe simply ignore negative numbers (since we can't return an error) and document it.

The CPU period is semantically unsigned: the kernel accepts cfs_period_us
values in the range [1000, 1000000] (and the cgroup v2 cpu.max $PERIOD
counterpart has the same range). The setter's int64 signature dates back
to CRI using int64 on the wire. Combined with the UInt64() wrapper it
silently converted negative values into garbage 64-bit values (e.g. -1
becoming 18446744073709551615), which then failed container creation
inside runc with an error that gives no hint about the plugin-side cause.

Since the setter cannot return an error, ignore negative values instead
of recording a broken value, and document the behavior. The API stays
backward compatible.

Add tests covering both the value round-trip and the ignored negative
value for both ContainerUpdate and ContainerAdjustment.

Signed-off-by: pandaWall <mangosteen922@126.com>
@pandaWall
pandaWall force-pushed the make-SetLinuxCPUPeriod-take-an-unsigned-value branch from d8d78c8 to 0f9d2db Compare November 19, 2026 05:24
@pandaWall pandaWall changed the title api: make SetLinuxCPUPeriod take an unsigned value api: ignore negative values in SetLinuxCPUPeriod Nov 19, 2026
@pandaWall

Copy link
Copy Markdown
Contributor Author

...

Change both ContainerUpdate.SetLinuxCPUPeriod and ContainerAdjustment.SetLinuxCPUPeriod to take a uint64 argument...
...

Changing it this way would be a backward incompatible API change, for not much real gain. This is a cgroup v1 cpu.cfs_period_us parameter with an accepted range [1000 - 1000000] so there is no need for an uint64 range. IIUC, when on cgroup v2 the corresponding 'converted' cpu.max $PERIOD parameter has the same range, so no need for uint64 there either.

The various other components/interfaces are already inconsistent about this. For instance, CRI uses an int64 on the wire, and I think that's why we unfortunately ended up with an int64 for the function signature, and converting it to uint64.

So I wouldn't break the API for this. Maybe simply ignore negative numbers (since we can't return an error) and document it.

Well, that makes sense. I was testing the offline mixed mode function in my own environment. I mistakenly set the CPU period to a negative value. I have re-adjusted the new submission. I have changed the title to a more appropriate one.

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.

2 participants