Skip to content

Disable GC zeal allocation counter when retrying after GC#13278

Merged
fitzgen merged 1 commit into
bytecodealliance:mainfrom
fitzgen:issue-13263
May 5, 2026
Merged

Disable GC zeal allocation counter when retrying after GC#13278
fitzgen merged 1 commit into
bytecodealliance:mainfrom
fitzgen:issue-13263

Conversation

@fitzgen
Copy link
Copy Markdown
Member

@fitzgen fitzgen commented May 5, 2026

With a GC zeal allocation counter of 1, we would otherwise indefinitely fail to allocate, even after we did the GC that the counter triggered, when we tried to allocate again the GC zeal counter would force-return another OOM.

Instead, we temporarily disable the GC zeal allocation counter in retry_after_gc_async on the retry path. This resets the counter after we have done our second-attempt allocation, giving the desired sequence of events for gc_zeal_alloc_counter=1 where we GC once on every retry_after_gc_async call:

  • Attempt to allocate
    • Fails with GC OOM due to gc_zeal_alloc_counter going from 1 to 0
    • gc_zeal_alloc_counter reset to 1
  • Disable gc_zeal_alloc_counter
  • Do GC-or-growth
  • Retry allocation
    • Succeeds or fails without interference from the gc_zeal_alloc_counter
  • Re-enable gc_zeal_alloc_counter=1 so everything repeats on the next retry_after_gc_async call

Fixes #13263

With a GC zeal allocation counter of `1`, we would otherwise indefinitely fail
to allocate, even after we did the GC that the counter triggered, when we tried
to allocate again the GC zeal counter would force-return another OOM.

Instead, we temporarily disable the GC zeal allocation counter in
`retry_after_gc_async` on the retry path. This resets the counter after we have
done our second-attempt allocation, giving the desired sequence of events for
`gc_zeal_alloc_counter=1` where we GC once on every `retry_after_gc_async` call:

* Attempt to allocate
  * Fails with GC OOM due to `gc_zeal_alloc_counter` going from `1` to `0`
  * `gc_zeal_alloc_counter` reset to `1`
* Disable `gc_zeal_alloc_counter`
* Do GC-or-growth
* Retry allocation
  * Succeeds or fails without interference from the `gc_zeal_alloc_counter`
* Re-enable `gc_zeal_alloc_counter=1` so everything repeats on the next
  `retry_after_gc_async` call

Fixes bytecodealliance#13263
@fitzgen fitzgen requested a review from a team as a code owner May 5, 2026 17:39
@fitzgen fitzgen requested review from alexcrichton and removed request for a team May 5, 2026 17:39
@fitzgen fitzgen added this pull request to the merge queue May 5, 2026
Merged via the queue into bytecodealliance:main with commit 0446acb May 5, 2026
48 checks passed
@fitzgen fitzgen deleted the issue-13263 branch May 5, 2026 19:00
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.

GC trap: no capacity for allocation of 0 bytes

2 participants