Visitar URL original
Keep automatic GC requests local to each interpreter by 1ndahous3 · Pull Request #8902 · RustPython/RustPython · GitHub
Skip to content

Keep automatic GC requests local to each interpreter - #8902

Merged
youknowone merged 1 commit into
RustPython:mainfrom
1ndahous3:gc_interpreter_scaling
Sep 29, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
1ndahous3:gc_interpreter_scaling

Conversation

@1ndahous3

@1ndahous3 1ndahous3 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Keep automatic collection requests with the interpreter whose allocations triggered them, preventing another VM from consuming the request and collecting its own objects instead.
  • Preserve pending requests while the collector is busy, without repeatedly entering the bytecode slow path during collection callbacks.
  • Make the counter underflow guard from #8517 atomic, preventing wraparound when untracking an object races with a collection resetting the counter.

Known limitations

Generation lists and stop-the-world coordination remain process-wide.

AI assistance

Written with Codex (GPT-6), reviewed by a human before submission.

Summary by CodeRabbit

  • Bug Fixes
    • Automatic memory cleanup is now handled more safely during concurrent activity, reducing the risk of incorrect memory accounting.
    • Cleanup requests are preserved when another cleanup is in progress and handled at a safe point in execution.
    • Cleanup requests made during callbacks are retained for a subsequent collection.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: RustPython/RustPython/.coderabbit.yml

Review profile: CHILL

Plan: Advanced

Run ID: b2e8ad3c-7252-4469-bfa0-52be45f3bcba

📥 Commits

Reviewing files that changed from the base of the PR and between a7d75d2 and 3b43f09.

📒 Files selected for processing (3)
  • crates/vm/src/gc_state.rs
  • crates/vm/src/signal.rs
  • crates/vm/src/vm/mod.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Threaded automatic GC requests are now associated with individual interpreters and run through the VM bytecode-loop breaker. GC count decrements use a checked atomic update to avoid decrementing an already-zero count.

Changes

Garbage collection scheduling

Layer / File(s) Summary
Schedule and run interpreter-local collections
crates/vm/src/gc_state.rs, crates/vm/src/signal.rs, crates/vm/src/vm/mod.rs
Threaded allocation schedules GC on the allocating interpreter. The VM checks whether that interpreter’s request is ready and runs generation-0 collection. The global GC signal helpers are removed. Tests cover request ownership, a busy collector, and disabled collection.
Keep GC count decrements within bounds
crates/vm/src/gc_state.rs
release_count uses a checked atomic update. A concurrent test races decrements against counter resets.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant AllocatingInterpreter
  participant GcInterpreterState
  participant VirtualMachine
  participant GlobalCollectionLock
  AllocatingInterpreter->>GcInterpreterState: Schedule request at gen0 threshold
  VirtualMachine->>GcInterpreterState: Check collection_ready()
  GcInterpreterState->>GlobalCollectionLock: Check collector lock
  GcInterpreterState-->>VirtualMachine: Report readiness when unlocked
  VirtualMachine->>GcInterpreterState: Run collect(0)
Loading

Suggested reviewers: youknowone

Merge Risk: ⚪ Minimal · up to 3b43f

No established issue remains that would prevent merging after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 3b43f

The request now stays with the interpreter that triggered it, and collection still uses the existing coordination controls. No newly exposed security path was established. Collection can still be delayed when an interpreter stops executing bytecode.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — Code able to drive allocations can trigger an automatic GC request for its interpreter. A resulting collection still coordinates with threads process-wide, while object selection remains ownership-filtered.

Trust Boundaries and Controls

  • observed — The new dispatch checks the current VM's GC state. Existing enablement and collector-lock checks remain in the collection path; the two-interpreter test checks that servicing one VM does not consume the other's request.

Resilience and Maintainability Implications

  • inferred — A pending request is retryable after collector contention, but automatic servicing requires a later bytecode safepoint on that interpreter. The reviewed evidence does not establish prompt finalization for an interpreter that executes no further bytecode.

Hardening Proposals

  • proposed — For hosts that rely on prompt GC finalization, establish a resource-bound policy for interpreters that stop reaching bytecode safepoints.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: automatic GC requests remain local to the interpreter that triggered them.
Docstring Coverage ✅ Passed Docstring coverage is 86.67% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 3 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@youknowone
youknowone merged commit b09402a into RustPython:main Sep 29, 2026
30 checks passed
@1ndahous3
1ndahous3 deleted the gc_interpreter_scaling branch September 29, 2026 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants