mirror of
https://github.com/Comfy-Org/comfy-aimdo.git
synced 2026-11-04 23:37:21 +00:00
[GH-ISSUE #128] Redundant full-deficit eviction on every allocation causes multi-hour VRAM thrash under sustained oversubscription #50
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Comfy-Org/comfy-aimdo#50
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sugarkrill on GitHub (Oct 22, 2026).
Original GitHub issue: https://github.com/Comfy-Org/comfy-aimdo/issues/128
Title: Redundant full-deficit eviction on every allocation causes multi-hour VRAM thrash under sustained oversubscription
Summary
Under sustained VRAM oversubscription on Windows, several allocation call sites each unconditionally re-run a full
vbars_free(budget_deficit(X))against the current reported deficit before attempting their own allocation — even thoughbudget_deficit()'s underlying data source is itself explicitly throttled and only refreshes every ~2s. On a hot allocation path (cuMemAllocAsync, invoked on every PyTorch allocation during model compute), this means hundreds of calls per second can each redundantly re-trigger a multi-GB evict-and-reload cycle against a deficit value that hasn't changed since the last check. The result is a GPU that reports ~100% utilization at a small fraction of its rated power draw (observed: ~59W vs. 150-220W under real compute), with VRAM usage pinned near capacity, for anywhere from 20 minutes to 2+ hours, before either completing or hitting an OOM.Environment where this was reproduced
08b37eec3)--disable-dynamic-vram's equivalent legacy path involved (the thrash is in this shared allocation code, not specific to any one caller)Root cause
Five call sites call
vbars_free(budget_deficit(X))directly, with no debounce:src/model-vbar.c,vbar_fault()— the per-fault "stopgap" callsrc/malloc-graph.c,create_page()src/vrambuf.c,vrambuf_grow()src/pyt-cu-plug-alloc-async.c,aimdo_cuda_malloc()andaimdo_cuda_malloc_async()budget_deficit()itself is cheap to call, but its WDDM-backed component (poll_budget_deficit()insrc-win/shmem-detect.c) only actually refreshes its view of GPU memory usage once every 2000ms (the non-Windowscuda_budget_deficit()insrc/control.chas the identical 2000ms throttle). Between refreshes, every call to any of the five sites above sees the same deficit value and re-runs a fullvbars_free()eviction for it — even though a very recent call already acted on that exact number. On Windows specifically, this is compounded by WDDM's reported "usage" bundling pinned host memory (used for the demand-paged weight-streaming staging buffer) in with VRAM under one combined budget, so the deficit this loop is reacting to is frequently much larger than the true in-use VRAM — but that inflation is a separate issue from the redundant-call bug itself, which would waste cycles even against an accurate deficit number.Proposed fix
Replace the five raw calls with a single throttled helper that shares one per-device timestamp, gated to the same 2000ms cadence the deficit data itself refreshes on. When it does run, it still evicts the full deficit it computes — this only suppresses the immediate repeat calls that would otherwise act on stale data. Each call site's existing OOM-retry fallback (the unthrottled, bounded
vbars_free()call used when the first allocation attempt still fails) is untouched, so correctness in the genuine-OOM case is unaffected.Diff against v0.5.6 (
08b37eec3):Validation performed
nvidia-smi dmontelemetry and DEBUG-level aimdo logs cross-referenced by timestamp.torch.OutOfMemoryErrorwhen the request genuinely doesn't fit — no thrash, no hang, process remains stable and responsive throughout both outcomes.Disclosure
This investigation and patch were produced with AI assistance (Claude Code) under my direction and review — the root-cause analysis, patch design, and validation testing were done interactively with an AI agent, not purely by hand. Flagging this so you can weigh the review accordingly.