-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
py/malloc,rp2: Add mutex for tracked allocations. #16071
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
py/malloc,rp2: Add mutex for tracked allocations. #16071
Conversation
743143c
to
c30ac5e
Compare
Code size report:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #16071 +/- ##
=======================================
Coverage 98.54% 98.54%
=======================================
Files 169 169
Lines 21890 21898 +8
=======================================
+ Hits 21572 21580 +8
Misses 318 318 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
c30ac5e
to
c2db4be
Compare
Rebased, re-tested. The bug this fixes is no longer easy to reproduce, but I believe it still exists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this on RPI_PICO2_W, running the new test both before and after the patch in this commit. It passes. Also tested the test on ESP32_GENERIC, and it passes there.
I agree that even if the test passes without the patch here, it's still worth having this fix merged. It should be very minimal (unmeasurable) in terms of cost to performance.
c2db4be
to
cdd94ba
Compare
Rebased, addressed comments, re-ran the new unit test on RPI_PICO_W (still passes). |
cdd94ba
to
01d6315
Compare
Fixes thread safety issue that could cause memory corruption on ports with (MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL) - currently only rp2 and unix have this configuration. Adds unit test for TLS sockets that exercises this code path. I wasn't able to make this fail on rp2, the race condition window is pretty narrow and may not have a direct impact on a quiet system. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
Signed-off-by: Angus Gratton <angus@redyak.com.au>
01d6315
to
79abdad
Compare
Note: This draft PR is currently one commit stacked on top of #16015, will need rebase after the linked PR is merged.(Done.)Summary
As discussed in this comment, non-GIL threaded ports (i.e. rp2) need some thread safety protection around tracked allocations. This PR reuses the GC mutex for this purpose.
Testing
Trade-offs and Alternatives
m_tracked_malloc_init
function to initialise the mutex.