Skip to content

Select devices per-container in the ActorTemplate #752

Open

Description

@eliranw

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 resources to ActorTemplate.Container, as ContainerResources (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/gpu limits sum to more than the assigned pool's reservation. This cannot be CEL: the reservation lives on the WorkerPool, and the template selects workers by label, so one template may match several pools with different reservations.
  • Plumb the per-container limits through WorkerAssignment to ateom.
  • In ateom, set spec.Linux.Resources on 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-container maybeInjectGPU. 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/gpu as 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 DRA ResourceClaim rather than extending counts.
  • CPU pinning. cpuset.cpus exists 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

Activity

  1. BenTheElder commented on Aug 6, 2026

    @BenTheElder
    Collaborator

    Actors are pod-shaped (multiple containers, one gVisor sandbox, shared netns), so per-container device control unlocks:

    It also unlocks a possible future where we are not 1:1 with actor : pod.

    Declare devices per-container using the standard Kubernetes resources shape, the same corev1.ResourceRequirements type the pool already uses. The pool reserves capacity; each container claims from it.

    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)

  2. eliranw commented on Aug 8, 2026

    @eliranw
    CollaboratorAuthor

    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

  3. BenTheElder commented on Aug 9, 2026

    @BenTheElder
    Collaborator

    We might have to just implement it as close to k8s pod semantics as we can then. cc nybidari

  4. nybidari commented on Aug 12, 2026

    @nybidari
    Collaborator

    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:

    • a sidecar inside the worker to monitor the limits
    • outside the worker, maybe ateom can monitor

    This is for memory only, for CPU enforcement it would be much difficult to enforce as it requires throttling based on the limits.

  5. added
    kind/feature
    on Aug 12, 2026
  6. BenTheElder commented on Sep 1, 2026

    @BenTheElder
    Collaborator

    Select devices per-container in the ActorTemplate

    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

  7. BenTheElder commented on Sep 1, 2026

    @BenTheElder
    Collaborator

    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: count too 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:

    1. Figure out how uVM will work GPU passthrough for micro-VM actors #762
    2. Plan out the right API that will allow us to pass to specific containers and schedule to identical hardware for resume (also e.g. sharing between containers?)

    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.

  8. BenTheElder commented on Sep 1, 2026

    @BenTheElder
    Collaborator

    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) ...

  9. BenTheElder commented on Sep 2, 2026

    @BenTheElder
    Collaborator

    #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.

  10. BenTheElder commented on Sep 2, 2026

    @BenTheElder
    Collaborator

    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?

  11. eliranw commented on Sep 2, 2026

    @eliranw
    CollaboratorAuthor

    After contacting the GPU snapshot/restore folks, the following should be same, at least for now, in cuda-checkpoint scenarios:

    1. Driver version
    2. GPU Type
    3. GPU Count
    4. Guest OS - should probably be same in general so linux kernel version is same.
  12. eliranw commented on Sep 2, 2026

    @eliranw
    CollaboratorAuthor

    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

  13. mortent commented on Sep 16, 2026

    @mortent

    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, WorkerPool leverages Kubernetes DRA directly:

    • Pod Claims: Add resourceClaims to WorkerPoolPodTemplate (mirroring corev1.PodResourceClaim).
    • Topology Solved at Pod Placement: kube-scheduler and the cluster's DRA drivers handle physical device allocation, alignment, and device co-location when provisioning standby worker pods.
    • Standard CDI: Because CDI specs are generated on the host by the DRA driver, ateom only 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.

    • Worker Registration: When worker pods register, they capture the topology attributes and CDI identifiers of their allocated DRA devices. The ResourceClaims contain the details about the allocated devices.
    • ActorTemplate Device API: Work is needed to design the device API on ActorTemplate, 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.
    • Fast Matchmaking: The ateapi scheduler 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.
    • Granular Device Scoping: Because CDI defines discrete, individually addressable devices, ateom can 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.

  14. eliranw commented on Sep 16, 2026

    @eliranw
    CollaboratorAuthor

    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-hook createContainer 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area/apiarea/gvisorarea/nodearea/schedulingkind/feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions