refactor: simplify allocation tracker lifecycle#543
Merged
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4d0f3b704e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Use `_instance != nullptr` as the single source of truth for "tracking active", dropping the separate `track_allocations` atomic and the lazy `remaining_bytes_initialized` flag (TLS shrinks 48 -> 40 bytes). The per-thread sampling offset is now applied once in `init_tl_state` instead of on every first allocation. - Make `_instance` a `std::atomic<AllocationTracker *>` with acquire/release ordering and route all accesses through a `get_instance()` helper so publishing and tearing down the instance synchronize correctly with observing threads. - Initialize the starter thread's TLS before publishing `_instance` to avoid a window where other threads observe a non-null instance with half-initialized state. - Defer `pevent_munmap_event` to the next `allocation_tracking_init` (guarded by `mapfd != -1`) so in-flight hooks cannot race with teardown; add default initializers to `PEvent` to make the guard sound. - Call `restore_overrides()` in `allocation_profiling_stop` to pair with `setup_overrides()` on start.
4d0f3b7 to
51371be
Compare
r1viollet
reviewed
Apr 17, 2026
|
|
||
| void allocation_profiling_stop() { | ||
| if (g_state.allocation_profiling_started) { | ||
| restore_overrides(); |
Collaborator
There was a problem hiding this comment.
Good idea, restoring should improve performance for the user.
Document that ddprof_stop_profiling() does not drain in-flight allocation hooks, and that a stop/start sequence requires the caller to quiesce allocation activity to avoid racing with ring buffer re-init. Co-Authored-By: Claude Opus 4.7 (1M context) <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.
What does this PR do?
Use
_instance != nullptras the single source of truth for "tracking active", dropping the separatetrack_allocationsatomic and the lazyremaining_bytes_initializedflag (TLS shrinks 48 -> 40 bytes). The per-thread sampling offset is now applied once ininit_tl_stateinstead of on every first allocation._instanceto avoid a window where other threads observe a non-null instance with half-initialized state.pevent_munmap_eventto the nextallocation_tracking_init(guarded bymapfd != -1) so in-flight hooks cannot race with teardown; add default initializers toPEventto make the guard sound.restore_overrides()inallocation_profiling_stopto pair withsetup_overrides()on start.Possibly fixes #541