Commit 5ef3a61
committed
Add random-walk controller state to FTP parallel GC (tracking only)
Phase 6 step 2 of bringing the free-threaded parallel GC to feature
parity with the GIL parallel GC. The GIL build adopted the random-walk
adaptive worker controller in Phase 5; this commit adds the same
controller state and the same shared update call to the FTP build, so
both run identical worker-allocation logic.
Changes:
- _PyGCThreadPool gains adaptive_workers, prev_cost_per_obj_ns,
explore_rng fields (mirroring _PyParallelGCState on the GIL side).
- _PyGC_ThreadPoolInit initialises them: adaptive_workers = min(4,
num_workers), prev_cost = 0, rng = _PyGC_RandomWalkSeed().
- gc_free_threading.c::gc_collect_internal calls
_PyGC_RandomWalkUpdate after cleanup_end_ns is recorded — same
algorithm as the GIL build via the shared helper introduced in
77c1247.
What this commit does NOT yet do (and why):
adaptive_workers is tracked but NOT yet used to skip work on idle
workers. The natural place — an early return in thread_pool_do_work
for worker_id >= adaptive_workers — deadlocks because FTP's work
functions (update_refs, mark_heap, scan_heap, propagate) use
internal phase_barriers that require ALL num_workers participants
to arrive. Skipping the work skips the phase_barriers and the active
workers wait forever for the missing ones. The barrier-vs-condvar
dispatch mismatch is what blocks this; the next commit replaces
FTP's barrier dispatch with per-worker condvars (mirror of Phase 5.3
on the GIL side), and at that point adaptive_workers naturally takes
effect because idle workers don't wake at all.
So: this commit is "controller state and call wiring", not "dispatch
behaviour change". The state evolves identically to the GIL build; the
observed worker count is still num_workers until the dispatch refactor
lands.
Verified: FTP build, all 5 parallel-GC test files pass (177 tests,
7 platform skips). Smoke test (20 collections with 4 workers) completes
without hang.1 parent 12a3440 commit 5ef3a61
3 files changed
Lines changed: 47 additions & 0 deletions
File tree
- Include/internal
- Python
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
339 | 347 | | |
340 | 348 | | |
341 | 349 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
2726 | 2727 | | |
2727 | 2728 | | |
2728 | 2729 | | |
| 2730 | + | |
| 2731 | + | |
| 2732 | + | |
| 2733 | + | |
| 2734 | + | |
| 2735 | + | |
| 2736 | + | |
| 2737 | + | |
| 2738 | + | |
| 2739 | + | |
| 2740 | + | |
| 2741 | + | |
| 2742 | + | |
| 2743 | + | |
| 2744 | + | |
| 2745 | + | |
2729 | 2746 | | |
2730 | 2747 | | |
2731 | 2748 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
1657 | 1658 | | |
1658 | 1659 | | |
1659 | 1660 | | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
1660 | 1676 | | |
1661 | 1677 | | |
1662 | 1678 | | |
| |||
1791 | 1807 | | |
1792 | 1808 | | |
1793 | 1809 | | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
1794 | 1816 | | |
1795 | 1817 | | |
1796 | 1818 | | |
| |||
0 commit comments