Repository navigation
Synchronize CPU and Metal allocator statistics - #16
Merged
Merged
Conversation
added 2 commits
September 29, 2026 14:34
jjang-ai
marked this pull request as ready for review
September 30, 2026 04:15
This was referenced Oct 23, 2026
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.
Allocator statistics were read without synchronization while allocation/completion threads updated them under a mutex. Use relaxed atomic observations for active bytes, peak bytes and the memory limit in the CPU and Metal allocators. Keep existing writer mutexes and allocation thresholds unchanged. Protect Metal cache-size observations with its mutex, and use already-protected direct cache reads internally to avoid recursive locking.
Adds actual allocator regressions for tiny-buffer allocation/free versus statistics reads, and unchanged-value memory-limit writes/peak resets versus readers. Each statistic is an independent observation; this does not introduce an atomic multi-field snapshot.
SOURCE EVIDENCE: Changes are limited to
mlx/backend/no_gpu/allocator.cpp,mlx/backend/metal/allocator.h,mlx/backend/metal/allocator.cppandtests/allocator_tests.cpp, based onqwen4-expafter #15 at795d1b3849b82aaaeccddaa7fce9e0bb76a4f847.LIVE EVIDENCE: Independently rebuilt complete CPU and Metal libraries and the actual existing doctest target with manual Apple Clang ThreadSanitizer instrumentation. Both controls contain the same scheduler-counter fix from #15, isolating allocator changes. All four public changed-file blobs match the tested candidate.
All candidate rows exited 0, with no TSan report and unchanged sources. Separate library builds avoid mixing old allocator objects with changed headers. Actual compiler commands verify instrumentation and backend selection; Metal builds exclude the no-GPU allocator. The two Metal candidate cases were run sequentially for the final proof.
DEVICE=cpuselects the default stream, not the allocator implementation: the Metal runs link and exercise the actual Metal allocator with 4 KiB/8 KiB buffers. CPU candidate binary SHA256:c6cfd9973894fc45f3387f1907eef1a5ec17aa5f49c17bc89579037f47243d02; Metal candidate:d5ad3303d94ac39e5157ad99d5dc0379c088df7f85a90d6a91082a8ae3fef146.This is a manual Clang sanitizer configuration; the upstream macOS
USE_TSANgate remains unchanged. Metal proof is limited to the two allocator cases, with no model/shader execution or full Metal-suite claim. No performance improvement or production crash root cause is claimed. Full CPU scheduler-suite proof includes #15; the allocator source diff remains independent.The published branch includes merged #15. Compared with the complete tested candidate source, the only tracked-file difference is scheduler comment wrapping; all noncomment lines and all allocator/test blobs are identical. No new exact-head binary test is claimed for that comment-only integration difference.