Repository navigation
Description
Problem
Follow-up to #502, which landed GPU passthrough at the worker level. A pool requests N GPUs and every actor container gets all of them. The ActorTemplate containers have no say in the device layout, so device assignment is coupled to the worker.
Per Benjamin Elder (@BenTheElder) (review), device assignment should move into the ActorTemplate so it is decoupled from the worker and can control which containers in an actor receive the devices.
Use cases
Actors are pod-shaped (multiple containers, one gVisor sandbox, shared netns), so per-container resource control unlocks:
- Accelerator container plus CPU-only sidecar. The model or trainer container claims the accelerator (
nvidia.com/gpu,amd.com/gpu, an FPGA); the logging, proxy, or metrics sidecar next to it claims none. Today every sidecar is handed the device nodes. - Security isolation. An untrusted or user-supplied sidecar is denied device access as defense in depth. Today it silently receives whatever the pod holds (
/dev/nvidia*, an SR-IOV VF), widening the attack surface that feat: CDI-based NVIDIA GPU passthrough into gVisor actor containers #502 otherwise works to keep narrow. The same applies to memory and CPU: a runaway sidecar can currently consume the whole pod budget and starve the container that matters. - Devices split across containers. On a multi-device node, worker containers each claim a distinct GPU for data-parallel or shard-per-container work over the shared netns.
Proposed API
Declare resources per-container using the standard Kubernetes limits shape. The pool reserves capacity; each container claims from it.
kind: WorkerPool
spec:
sandboxClass: gvisor
template:
resources:
limits:
nvidia.com/gpu: "2" # pool reserves 2 GPUs on the node (unchanged; this is what schedules onto a GPU node)
containers:
- name: trainer
image: pytorch@sha256:...
resources:
limits:
nvidia.com/gpu: "2" # this container claims both
memory: 8Gi
- name: sidecar-logger
image: fluentbit@sha256:...
resources:
limits:
memory: 256Mi # capped, and no gpu injected (today it would wrongly get both)One new field on Container:
// Resources for this container, including device-plugin resources such as
// nvidia.com/gpu.
// +optional
Resources *ContainerResources `json:"resources,omitempty"`
// ContainerResources are the resource limits for one actor container.
type ContainerResources struct {
// Limits is the maximum amount of compute resources allowed, including
// device-plugin resources such as nvidia.com/gpu.
//
// +optional
Limits corev1.ResourceList `json:"limits,omitempty"`
}The YAML matches vanilla Kubernetes per-container limits, and reusing corev1.ResourceList keeps it device-generic for free: extended resources already cover RDMA, FPGA, and others.
Limits only
ContainerResources deliberately does not reuse corev1.ResourceRequirements, which also carries requests and claims.
A restore needs at least the footprint that was captured — micro-VM guest RAM comes back from the memory snapshot, and under gVisor the saved pages would be faulted into a smaller cgroup. A soft request cannot express "must have this much to come back at all".
Adding requests later is additive and non-breaking if a use case appears. The obvious one is cpu.weight, relative priority between sibling containers under contention.
Scope
- Add
resourcestoActorTemplate.Container, asContainerResources(limits only). - CEL validation: extend the existing
sandboxClass == 'gvisor'guard to the container level. The type already restricts this to limits, so there is nothing else to reject at admission. - At assignment time, reject an actor whose container
nvidia.com/gpulimits sum to more than the assigned pool's reservation. This cannot be CEL: the reservation lives on theWorkerPool, and the template selects workers by label, so one template may match several pools with different reservations. - Plumb the per-container limits through
WorkerAssignmenttoateom. - In
ateom, setspec.Linux.Resourceson the OCI spec from the container's limits, and partition the pod's assigned GPUs across the containers that request them, the way the device plugin does in real Kubernetes, instead of the unconditional per-containermaybeInjectGPU. The partition must be deterministic, ordered by container. - Update the API guide.
The cgroup machinery already exists: ensureContainerCgroupsPath gives every actor container its own cgroup leaf, so cpu.max, memory.max and friends are present and unset.
Risks
- Device identity is not stable across resume. CDI names are pod-local, so on restore the actor may land on different physical devices with new UUIDs and PCI IDs. Injection already re-runs on the restore path, so device paths are re-resolved. Remaining care:
- an app that cached a device UUID or PCI ID before snapshot sees a different one after;
- the container-to-device partition must be deterministic so a container keeps its ordinal across resume.
- Pool reservation stays the scheduling knob. Keep the pool's
resources.limits.nvidia.com/gpuas the reservation and validate that the containers' sum does not exceed it, rather than deriving the pool total from containers. Smaller change, single scheduling knob.
Open questions
Can per-container CPU and memory be enforced? gvisor/gvisor#190 suggests cgroup limits land on the sandbox rather than the container, since one sentry backs them all. Micro-VM actors have a real guest kernel, so it may work there. Worth settling before the field covers more than devices.
Out of scope
- DRA. Dynamic Resource Allocation (
resource.k8s.io, GA in 1.34) is the home for physical index pinning, topology co-allocation, and device sharing such as MIG and time-slicing. If those are needed, revisit through a DRAResourceClaimrather than extending counts. - CPU pinning.
cpuset.cpusexists on the per-container cgroup, but counts cannot express it and it belongs with topology above. Under gVisor it would also pin the sentry's host threads rather than CPUs the sandboxed app sees. - Non-GPU device classes. The surface allows them; the implementation lands with the first such device.
- Snapshot and restore of live device state, such as a live CUDA context. Tracked separately by Snapshot/restore for GPU actors (suspend/resume with a live CUDA context) #779.
References
- GPU support for gVisor actors #627: GPU support for gVisor actors, the parent this follows up.
Activity
BenTheElder commentedon Aug 6, 2026
It also unlocks a possible future where we are not 1:1 with actor : pod.
I'm wondering how much requests vs limits makes sense and if we should allow requests at this stage. Like what would it mean if you requested 2GI for uVM and then on restore got only 1?
cc Julian Gutierrez Oschmann (@juli4n)
eliranw commentedon Aug 8, 2026
I agree limits only fits better, restore needs at least the same amount of memory, and for devices it’s based on limits anyway. I’ll update the design.
Separately I looked at whether per-container cpu/memory is even enforceable in gVisor, saw this gvisor/gvisor#190. Are cgroup limits in gVisor at the sandbox level only? Seems like it might be an issue
BenTheElder commentedon Aug 9, 2026
We might have to just implement it as close to k8s pod semantics as we can then. cc nybidari
nybidari commentedon Aug 12, 2026
gVisor does not enforce memory or CPU limits at container level. The limits are written in the per-container cgroups, but the gVisor sentry will not enforce the limits.
We could implement some way to enforce memory limits like:
This is for memory only, for CPU enforcement it would be much difficult to enforce as it requires throttling based on the limits.
Per-container CPU and memory limits for micro-VM actors (#859)
BenTheElder commentedon Sep 1, 2026
I didn't realize we still didn't have per-actor device selection (have been focused elsewhere) but this is a blocker for #1266 / #1283
BenTheElder commentedon Sep 1, 2026
I think we need to reach out to Kubernetes WG Device Management folks to discuss our device management API, I know a few we can talk to.
I'm worried we're going to find
label: counttoo simplistic later when we need to make sure we only resume onto compatible harder (see also #779)I'm thinking we should drop support temporarily, with the intention to:
With 2) being the bigger concern. We want to start offering some API compatibility soon and I don't want to rush the API. I have something thrown together that plumbs based on label/count down to the actor that sort of naturally maps to what we have now:
main...BenTheElder:substrate:actor-device-requests
It's not terrible, but I don't think it leaves us room to express concepts like sharing between containers later.
BenTheElder commentedon Sep 1, 2026
I spoke for a bit with with John Belamaric today, I think my main take-away is that we should do a stripped down version of DRA and we should put some thoughts into things like allocating along PCI groups within the mega-worker (#1283) ...
BenTheElder commentedon Sep 2, 2026
#1389 -- I don't like regressing, but I think we should model this API, then reintroduce. Hopefully in parallel we know what we need to reintroduce to uVM at the same time.
BenTheElder commentedon Sep 2, 2026
DeviceMetadata => worker sets it's own capacity (#1283) with device info => schedule to it?
Some way to model info beyond count ... and make sure we can schedule back to appropriate workers?
eliranw commentedon Sep 2, 2026
After contacting the GPU snapshot/restore folks, the following should be same, at least for now, in cuda-checkpoint scenarios:
eliranw commentedon Sep 2, 2026
Also you need to have enough memory allocated in the container to hold the cuda snapshot pre-suspend, this changes per device count and amount of device memory
mortent commentedon Sep 16, 2026
As mentioned by others in an earlier comment, I think modeling this on DRA would be the best way to go. A solution based on the Device Plugin misses out on several of the features that were introduced in DRA, including support for topology alignment.
I think we should move to a two-tier scheduling model for accelerators, built on top of DRA.
Tier 1: Infrastructure Scheduling via Native Kubernetes DRA
At the worker-provisioning layer,
WorkerPoolleverages Kubernetes DRA directly:resourceClaimstoWorkerPoolPodTemplate(mirroringcorev1.PodResourceClaim).kube-schedulerand the cluster's DRA drivers handle physical device allocation, alignment, and device co-location when provisioning standby worker pods.ateomonly needs to consume pre-existing specs. This eliminates the need to mount host toolchains and run nvidia-ctk, removing vendor-specific CLI dependencies from our worker images.Tier 2: Fast Actor-on-Worker Scheduling (DRA-Inspired)
We can't use DRA directly here, but I think we can come up with an API that looks similar to DRA, keeping it as simple as possible.
ResourceClaims contain the details about the allocated devices.ActorTemplateDevice API: Work is needed to design the device API onActorTemplate, but we believe it should be modeled on Kubernetes DRA APIs. But probably avoid the more advanced features like CEL expressions. This keeps the mental model consistent across both tiers.ateapischeduler matches the template's device requirements against pre-allocated worker devices, claims the worker, and hands the specific CDI device list to the sandbox runtime.ateomcan selectively inject assigned devices into specific containers via standard OCI device cgroups rather than broadcasting all devices actor-wide. This directly enables the per-container device selection requested in this issue (and opens the door to slicing devices among multiple actors on a worker in the future) with no runtime or driver hacks.This would allow us to leverage the functionality already available in DRA and DRA drivers and avoid duplicating logic in Agent Substrate. If this seems like a good direction, I'm interested in looking more into what the ActorTemplate Device API can look like.
eliranw commentedon Sep 16, 2026
Agree on modeling the ActorTemplate device API similarly to DRA. Currently the attributes are the part we are missing at least from the GPU perspective, since #779 needs a resumed actor to land on a card with constraints such as the same GPU type, and extended resources cannot say that.
On tier 1, this is what we did in #502, just with extended resources. The pool requests
nvidia.com/gpu,kube-scheduler lands the worker on a GPU node, and the pre-installed device plugin handed that worker its specific devices using CDI.A small thing I'm not sure will work is removing the host toolchain. In the case of the GPU DRA driver, it generates its specs with the same nvcdi library as the non-DRA driver, so they carry the same
nvidia-cdi-hookcreateContainer hooks pointing at a host path, and those hooks have to run against the actor's rootfs rather than the worker pod's. The binary still has to be reachable inside the worker, either mounted from the host like we did or baked into the ateom image.There's also the multi actor workers work by Benjamin Elder (@BenTheElder), I think the interesting point there is which actor holds which device(s) on a worker. I'd be happy to discuss an ActorTemplate Device API in any case.
eliranw commentedon Sep 29, 2026
Morten Torkildsen (@mortent) PTAL at the design doc I wrote on this subject https://docs.google.com/document/d/1cxS-ZH62mrTjJUBIGsM6lCu18HYMLBkY48IkRMpnK44/edit?tab=t.0#heading=h.jaawkdvaf37t
Stop implying real DRA/Substrate integration solves live GPU attach