GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-112529: Use atomic operations for `gcstate->collecting` by colesbury · Pull Request #112533 · python/cpython Conversation
|
| void | ||
| _Py_ScheduleGC(PyInterpreterState *interp) | ||
| { | ||
| GCState *gcstate = &interp->gc; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
fyi: _Py_ScheduleGC not public and only called from _PyObject_GC_Link, which already checks gcstate->collecting.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@pablogsal, would you be able to review this? The important bit is the atomically setting cc @nascheme in case you have time and are interested in the GC changes, I would appreciate your feedback as well. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
will review this week 👍 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@pablogsal - gentle reminder, this is awaiting your review |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This looks okay to me. It's a bit hard to see from the diff which code has been moved vs what's been changed. However, it seems to be mostly re-organization with essentially no behaviour change, aside from using the atomics. I'd say it can be merged. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| { | ||
| GC_STAT_ADD(generation, collections, 1); | ||
| #ifdef Py_STATS | ||
| if (_Py_stats) { |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't object_visits be zeroed after the _Py_atomic_compare_exchange_int(&gcstate->collecting check or the check be moved up?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes, thanks!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I think using forward declarations might help to have less moved blocks and make the review easier? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Probably it would but I'd rather the code is cleaner (without the forward decs) and have the patch be messier. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I rewrote the commit to use forward declarations (as suggested by Chris), makes the review easier: Aside from re-ordering the code and addition the forward defs, I didn't change anything. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I finally had time to review this. Apologies for the delay.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
We can probably go with the version with forward references although I don't think it makes a lot of improvements in the final version, is true that the review is easier to do on the diff alone. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The forward ref version was meant only for review purposes. I think we should merge Sam's (this) one. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I fixed the bug pointed out by @chris-eibl. Let me know if you prefer to land the forward references version. If so, I'll merge @nascheme's changes in. Otherwise, I think it's good to go now once the CI passes. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Nah, is good, let's go with this version. Thanks for the patience! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Exactly that was my indention :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…hon#112533) * pythongh-112529: Use atomic operations for `gcstate->collecting` The `collecting` field in `GCState` is used to prevent overlapping garbage collections within the same interpreter. This is updated to use atomic operations in order to be thread-safe in `--disable-gil` builds. The GC code is refactored a bit to support this. More of the logic is pushed down to `gc_collect_main()` so that we can safely order the logic setting `collecting`, the selection of the generation, and the invocation of callbacks with respect to the atomic operations and the (future) stop-the-world pauses. The change uses atomic operations for both `--disable-gil` and the default build (with the GIL) to avoid extra `#ifdef` guards and ease the maintenance burden.
…hon#112533) * pythongh-112529: Use atomic operations for `gcstate->collecting` The `collecting` field in `GCState` is used to prevent overlapping garbage collections within the same interpreter. This is updated to use atomic operations in order to be thread-safe in `--disable-gil` builds. The GC code is refactored a bit to support this. More of the logic is pushed down to `gc_collect_main()` so that we can safely order the logic setting `collecting`, the selection of the generation, and the invocation of callbacks with respect to the atomic operations and the (future) stop-the-world pauses. The change uses atomic operations for both `--disable-gil` and the default build (with the GIL) to avoid extra `#ifdef` guards and ease the maintenance burden.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.