Repository navigation
Memory: fix leaks and allocation churn at large sizes - #17
Open
AdvaitTahilyani wants to merge 14 commits into
Open
AdvaitTahilyani wants to merge 14 commits into
AdvaitTahilyani wants to merge 14 commits into
Conversation
A DAG's deletions were stored only for the ranks its nodes touch; the other ranks got an empty DAG. An array whose deletion arrived with a DAG of another rank was never freed: indexing_routines leaked every 2-D DIAG and GATHER result and the 3-D arrays of each routine (+8 GB per repeat at -n 2000, out of device memory on the second repeat at -n 4000). The empty DAGs now carry the deletions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One line per barrier on PE 0: device memory in use, live and retired arrays (device and host-mirror bytes, free-list keys), cached message buffers, pinned and IPC pools, pending per-node states and sends, stored DAGs, compiled kernels and the host heap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Message buffers above 64 MB and the executors' scratch buffers (alloc_buffer) were cudaMalloc'ed and cudaFree'd per use, and the small-block pool stopped caching at 1 GB. cudaMalloc of hundreds of MB got slower with every block the process had freed: richardson_lucy 512^3 spent 49, 314 and 521 ms per repeat in cudaMalloc (426 -> 925 ms steady). Large blocks are now cached by size in 2 MB steps; all cached blocks share a cap of 1/8 of device memory (CNUM_DEVICE_CACHE_MB), and an allocation that fails releases the large blocks and retries. free_buffer fences the device, as the cudaFree it replaces did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
At most 4 retired arrays per key were kept and the rest freed, so DAGs with more temporaries of a shape paid a cudaFree (a device sync) and a cudaMalloc per array. On NVIDIA the free lists now keep up to 64 per key within 1/8 of device memory per PE (CNUM_FREE_LIST_MB); a failed array allocation frees the retired arrays and cached buffers and retries. Retired arrays drop their host mirrors. Zero fills of new and reused arrays were a blocking Kokkos init or deep_copy (device-wide fences); they are now a cudaMemsetAsync on the compute stream, with the comm stream and the default instance ordered after it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Freed blocks went back to their own size class and were never merged, so the 1 GB of IPC slabs fragmented into small blocks and large messages fell back to host staging, more of them each repeat (stencil -n 8192 on 4 GPUs: 12.9 -> 15.4 s). Free lists are ordered sets and a freed block is merged with its free buddy up to a whole slab. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Budgets are fractions of the device split among the processes that share it (counted by the startup probe from PCI bus ids), not per process: small message blocks 1/16 (CNUM_COMM_CACHE_MB), large blocks 1/8 (CNUM_DEVICE_CACHE_MB), retired arrays 1/8 (CNUM_FREE_LIST_MB, now a process-wide counter). The IPC slabs stay separate (in-flight messages, CNUM_GPU_IPC_MB). - Small and large blocks no longer share one budget, so a full large cache does not make every small free a cudaFree; large blocks are evicted least recently freed first, only as many as needed. - A failed allocation (message buffer or array) frees every cached block and all of this PE's retired arrays and retries once; a second failure aborts with the size and the free device memory. Message buffers are allocated outside the pool lock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 6, 2026
adityapb
reviewed
Nov 6, 2026
adityapb
left a comment
Member
There was a problem hiding this comment.
Verdict: approve with nits.
This is a static review. Line numbers are at this PR's head.
I checked these and found them correct:
- IPC buddy merge: alignment, no overlap, no double merge.
- Deletions for empty DAGs.
- Cached large comm blocks: every free happens after a fence, from a stream callback, or at
send_complete. - OOM release: there is a fence before it.
- Reuse: ordered correctly with the async zero-fill.
- [minor] In SMP builds the OOM release only reaches the calling PE's retired arrays, but the budget is per process.
- Where:
release_device_caches(backend.hpp:1116-1127) loops overlocal_partitions(), which isthread_local(:1105-1108). - Scenario: PE A holds the budget in retired arrays. PE B's allocation then fails, the retry frees only B's arrays, and it aborts in
device_oom. - #25 makes this easier to hit.
- Still at #44.
- Where:
- Nits:
- Budget timing: budgets are sized before the IPC probe sets
gpu_sharers(). With 4 processes per GPU, the early caches are 4× too large and are never trimmed. - Free-path cost:
comm_freecallsgetenv(throughdevice_budget) underpool.muon every free, and eviction incomm_free_largeis O(n²). - SMP race: the retired-bytes cap check in
retire_arrayraces between PEs, so the cap can be overshot.
- Budget timing: budgets are sized before the IPC probe sets
…bytes cap, cheaper pool An out-of-memory release now walks every partition in the process (registry with a lock; free_arrays has its own mutex), since the budget is per process. The retired bytes cap reserves atomically. Budget env vars are read once; large-block eviction is O(log n) through an age index; the caches are trimmed when the IPC probe lowers the budgets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Validated: nc build and CPU regress at +p1 and +p2 (orig 15/15, ports 25/25, ops 26/26 each, no problems). The device code is not in the nc build: the GPU translation units touched (gpu_comm, partition_lifecycle, partition_get, executor_core) compile with the GPU flags, but no GPU run was done, so the SMP out-of-memory path is untested at runtime. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #16. Needs UIUC-PPL/charmtyles#8.
CNUM_MEM_STATS=1prints per-PE memory at barriers.richardson_lucy 512³: 986 → 335 ms (flat across repeats); black_scholes_greeks on 4 A100s: 4.1 s → 125 ms.
Tested (full stack): CPU +p1/+p2 15/15 originals, 25/25 ports, 30/30 ops; A100 1 GPU 15/15, 25/25, 30/30 and 4 GPUs (one process per GPU) 15/15, 25/25.
🤖 Generated with Claude Code