Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(profiling): add more GIL assertions to memalloc #12000

Merged
merged 1 commit into from
Jan 17, 2025

Conversation

nsrip-dd
Copy link
Contributor

@nsrip-dd nsrip-dd commented Jan 17, 2025

The first GIL assertion I added, to memalloc_add_event, has not tripped
yet on a test application. One the one hand, it's reassuring that we
always see the GIL in that part of the code. On the other hand, there
are other parts of the memory profiler that could in theory be called
concurrently where I didn't add the assertion: when stopping the
profiler, and when iterating over the events to aggregate them. Add GIL
assertions to those points. The goal is ultimately to understand why we
needed to add locks to the profiler to prevent it from crashing, given
that the GIL exists.

Checklist

  • PR author has checked that all the criteria below are met
  • The PR description includes an overview of the change
  • The PR description articulates the motivation for the change
  • The change includes tests OR the PR description describes a testing strategy
  • The PR description notes risks associated with the change, if any
  • Newly-added code is easy to change
  • The change follows the library release note guidelines
  • The change includes or references documentation updates if necessary
  • Backport labels are set (if applicable)

Reviewer Checklist

  • Reviewer has checked that all the criteria below are met
  • Title is accurate
  • All changes are related to the pull request's stated goal
  • Avoids breaking API changes
  • Testing strategy adequately addresses listed risks
  • Newly-added code is easy to change
  • Release note makes sense to a user of the library
  • If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
  • Backport labels are set in a manner that is consistent with the release branch maintenance policy

Sorry, something went wrong.

Verified

This commit was signed with the committer’s verified signature.
nsrip-dd Nick Ripley
The first GIL assertion I added, to memalloc_add_event, has not tripped
yet on a test application. One the one hand, it's reassuring that we
always see the GIL in that part of the code. On the other hand, there
are other parts of the memory profiler that could in theory be called
concurrently where I didn't add the assertion: when stopping the
profiler, and when iterating over the events to aggregate them. Add GIL
assertions to those points.  The goal is ultimately to understand why we
needed to add locks to the profiler to prevent it from crashing, given
that the GIL exists.
Copy link
Contributor

CODEOWNERS have been resolved as:

ddtrace/profiling/collector/_memalloc.c                                 @DataDog/profiling-python

@nsrip-dd nsrip-dd added the changelog/no-changelog A changelog entry is not required for this PR. label Jan 17, 2025
@datadog-dd-trace-py-rkomorn
Copy link

Datadog Report

Branch report: nick.ripley/more-gil-assertions
Commit report: 1e58b3f
Test service: dd-trace-py

✅ 0 Failed, 130 Passed, 1468 Skipped, 4m 19.34s Total duration (35m 29.02s time saved)

@pr-commenter
Copy link

pr-commenter bot commented Jan 17, 2025

Benchmarks

Benchmark execution time: 2025-01-17 16:59:54

Comparing candidate commit 1e58b3f in PR branch nick.ripley/more-gil-assertions with baseline commit f67a358 in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 394 metrics, 2 unstable metrics.

@nsrip-dd nsrip-dd marked this pull request as ready for review January 17, 2025 18:07
@nsrip-dd nsrip-dd requested a review from a team as a code owner January 17, 2025 18:07
Copy link
Contributor

@taegyunkim taegyunkim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memalloc module has 4 functions, start(), stop(), heap(), iter_events(). You've added the assert to stop() and iter_events() in this PR. Was there any specific reason to leave heap()?

@nsrip-dd
Copy link
Contributor Author

memalloc module has 4 functions, start(), stop(), heap(), iter_events(). You've added the assert to stop() and iter_events() in this PR. Was there any specific reason to leave heap()?

Fair point. For now I'm focusing just on the allocation profiler stuff and not heap because we found that the crashes went away when adding locks to just the allocation profiler.

@nsrip-dd nsrip-dd merged commit ef4c997 into main Jan 17, 2025
652 of 654 checks passed
@nsrip-dd nsrip-dd deleted the nick.ripley/more-gil-assertions branch January 17, 2025 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/no-changelog A changelog entry is not required for this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants