Skip to content

oci: correct sub-core CPU quota mapping and add cpuset to cpu_cores affinity#102

Merged
congwang-mk merged 2 commits into
mainfrom
oci-cpu-resource-mapping
Jun 13, 2026
Merged

oci: correct sub-core CPU quota mapping and add cpuset to cpu_cores affinity#102
congwang-mk merged 2 commits into
mainfrom
oci-cpu-resource-mapping

Conversation

@congwang-mk

Copy link
Copy Markdown
Contributor

Summary

Improves OCI CPU resource mapping in sandlock-oci, correcting one mapping and adding a missing one. Two focused commits.

1. Map only enforceable sub-core CPU quota to max_cpu throttle

cpu.quota/cpu.period was mapped with ((quota/period)*100).min(100.0). The .min(100.0) silently discarded any >= 1-core request, and combined with core's if cpu_pct < 100 guard a >= 1-core quota became max_cpu = 100, which core reads as no limit at all.

  • Sub-core (quota < period): map to 1-99%, flooring to 1 so a tiny fraction isn't truncated to 0 (and silently dropped to "no limit").
  • >= 1 core: left unmapped. max_cpu is a coarse global SIGSTOP/SIGCONT wall-clock duty cycle, not a bandwidth controller, and a multi-core allowance can't be expressed as a 1-100 value. A multi-core cap belongs on affinity, not this throttle.

2. Map cpu.cpus cpuset to cpu_cores affinity

OCI cpu.cpus (e.g. "0-3,7") was dropped entirely. It maps exactly to core's cpu_cores (sched_setaffinity), so this is genuine, non-approximate multi-core enforcement, and it is what the field means.

  • New parse_cpuset helper: comma-separated indices and inclusive ranges, sorted and de-duplicated; malformed/empty input drops to None (no partial pinning).
  • New OciPolicy.cpu_cores field, wired through from_spec and to_sandbox.

Testing

9 new unit tests (CPU quota cases + cpuset parsing + end-to-end mapping). Full sandlock-oci suite: 37 passed, clean build.

Out of scope

A pure multi-core quota with no cpu.cpus present (the approximate pin-to-N-cores hack) is intentionally not implemented, its bandwidth-vs-pinning tradeoff is a separate design decision.

Signed-off-by: Cong Wang <cwang@multikernel.io>
Signed-off-by: Cong Wang <cwang@multikernel.io>
@congwang-mk

Copy link
Copy Markdown
Contributor Author

@sachin2605 Please take a look. Thanks!

@congwang-mk congwang-mk merged commit e5daee1 into main Jun 13, 2026
12 checks passed
@congwang-mk congwang-mk deleted the oci-cpu-resource-mapping branch June 13, 2026 00:43
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.

1 participant