Skip to content

fix(nvidia): reject gpumem-percentage of 0 - #10

Closed
Wangmin362 wants to merge 3 commits into
base/oss-master-c343242from
fix/gpumem-percentage-zero
Closed

fix(nvidia): reject gpumem-percentage of 0#10
Wangmin362 wants to merge 3 commits into
base/oss-master-c343242from
fix/gpumem-percentage-zero

Conversation

@Wangmin362

@Wangmin362 Wangmin362 commented Jul 27, 2026

Copy link
Copy Markdown
Owner

What type of PR is this?

/kind bug

What this PR does / why we need it:

nvidia.com/gpumem-percentage: 0 is accepted today. The scheduler then computes memreq = Totalmem * 0 / 100 = 0, so the pod fits any card no matter how full it is, gets booked with 0 memory, and the device plugin injects CUDA_DEVICE_MEMORY_LIMIT_0=0m — which HAMi-core treats as "no limit" (do_init_device_memory_limits leaves the limit at 0 and oom_check returns early). The container can use the whole card while the scheduler still thinks it is free and keeps placing other pods on it; those pods then hit a real driver OOM inside their own quota.

This rejects 0 at admission and clamps it to 100 in GenerateResourceRequests, the same way out-of-range values are already handled. The clamp is not just a fallback for pods that skip the webhook: the webhook only walks pod.Spec.Containers, so an init container is never validated, while GenerateResourceRequests still runs for it — there the clamp is the only guard.

Which issue(s) this PR fixes:
NONE

Special notes for your reviewer:

Verified on two clusters, one pod per case in a throwaway namespace.

On a Tesla V100-PCIE-32GB node (HAMi 2.9.0 + hami-core):

  • gpumem-percentage: 0 → allocation annotation GPU-00552014-...,NVIDIA,0,0, container env CUDA_DEVICE_MEMORY_LIMIT_0=0m, and an 8 GiB torch allocation succeeded (host nvidia-smi showed 8501 MiB in use, booked as 0). hami-core itself logs invalid device memory limit CUDA_DEVICE_MEMORY_LIMIT_0=0m and then runs with no limit.
  • while that pod was holding its 8 GiB, a second pod asking for gpumem: 30000 on the same UUID was still admitted, and its allocation died with cuMemoryAllocate failed res=2 / torch.OutOfMemoryError — its own view said 29 GiB were free.
  • control gpumem: 2000 on a 1080 Ti → env 2000m, i.e. a 2000 MiB cap: an oversized 4 GiB allocation is rejected as expected, so the limiter itself works.

I also ran a before/after A/B with two shadow schedulers built from this branch — identical except for these two lines — each with its own namespace, scheduler name and no webhook, filtering on a single real GPU node. Same pod spec every time:

before after
empty card, gpumem-percentage: 0 booked as ...,NVIDIA,0,0 booked as ...,NVIDIA,32768,0
same card with 32000/32768 MiB booked by a running pod scheduled anyway, booked as 0 Pending, 1 nodes CardInsufficientMemory
/webhook AdmissionReview carrying percentage 0 allowed: true allowed: false, must be an integer between 1 and 100

The new tests fail on master and pass here.

This PR was written primarily by Claude Code, and I reviewed and tested it.

Does this PR introduce a user-facing change?:

Pods requesting nvidia.com/gpumem-percentage: 0 are now rejected at admission instead of silently running with no GPU memory limit.

@Wangmin362
Wangmin362 force-pushed the fix/gpumem-percentage-zero branch 2 times, most recently from efaadd9 to 5db8987 Compare July 27, 2026 13:59
imantaba and others added 3 commits July 28, 2026 04:50
…AMi#2105)

* fix(scheduler): scope per-type device list in fitInDevices

When a single container requested more than one device type, the devs
accumulator was declared once outside the per-type loop and never reset,
so the second type's allocation entry inherited the first type's devices.
Append each requested type's own devices (tmpDevs[k.Type]) directly to
its devinput entry so a type records only its own devices.

Signed-off-by: imantaba <itn.taba@gmail.com>

* test(scheduler): cover multi-device-type partition in fitInDevices

Signed-off-by: imantaba <itn.taba@gmail.com>

---------

Signed-off-by: imantaba <itn.taba@gmail.com>
* fix webhook to deny privileged containers

Signed-off-by: Jay2006sawant <jay242902@gmail.com>

* check privileged init containers before scheduler bypass

Signed-off-by: Jay2006sawant <jay242902@gmail.com>

* deny privileged containers only when gpu resources are requested

Signed-off-by: Jay2006sawant <jay242902@gmail.com>

---------

Signed-off-by: Jay2006sawant <jay242902@gmail.com>
A container asking for nvidia.com/gpumem-percentage: 0 passes validation, so
the scheduler computes memreq = Totalmem * 0 / 100 = 0. The pod fits any card
regardless of how full it is, is booked with 0 memory, and the device plugin
injects CUDA_DEVICE_MEMORY_LIMIT_0=0m, which HAMi-core reads as no limit. The
container can then use the whole card while the scheduler still counts the card
as free and keeps placing other pods on it, which OOM for real.

Reject 0 at admission and clamp it to 100 in GenerateResourceRequests for pods
that skip the webhook, same as the existing out-of-range handling.

Signed-off-by: wangmin <wangmin@riseunion.io>
@Wangmin362
Wangmin362 force-pushed the fix/gpumem-percentage-zero branch from 5db8987 to 7a5be78 Compare July 28, 2026 06:12
@Wangmin362

Copy link
Copy Markdown
Owner Author

Superseded by the upstream PR: Project-HAMi#2156

@Wangmin362 Wangmin362 closed this Jul 28, 2026
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.

3 participants