Skip to content

Don't keep the deferred-free context in the package image - #782

Merged
maleadt merged 2 commits into
mainfrom
tb/stale-deferred-free-context
Nov 25, 2026
Merged

maleadt merged 2 commits into
mainfrom
tb/stale-deferred-free-context

Conversation

@maleadt

@maleadt maleadt commented Nov 25, 2026

Copy link
Copy Markdown
Member

The GPU part of the precompilation workload frees pool memory with the DEFER_FREE policy, which records the context in oneL0.deferred_frees. The workload cleanup reset the other driver state but not that one, so when the context was still alive while the image was written, the package image kept it. After loading, oneL0.deferred_frees.context.value is then a ZeContext with a null handle (seen on an Iris Xe host; whether it happens depends on GC timing during precompilation). The next failed allocation reclaims memory, sweeps deferred frees in that context, and segfaults in zeMemAllocHost. In a full test run this showed up as worker crashes and a failing "SIGSEGV handler chaining" test.

This PR resets deferred_frees both in the workload cleanup and in oneL0.initialize, next to the extension properties cache, which is reset there for the same reason. The test checks in a fresh process that nothing is recorded right after using oneAPI.

It also fixes the "error in running finalizer: KeyError" printed while precompiling: a stream created by the workload can be finalized after the cleanup forgot the report slabs (here at exit), and returning its slot to the missing slab list threw. Such a slot is now dropped, and the cleanup clears the slabs under the pool lock that the finalizer takes.

The precompilation workload frees memory with the DEFER_FREE policy, which
records the context in `oneL0.deferred_frees`. The workload cleanup did not
reset it, so when the context was still alive while the image was written, the
image kept it, with a null handle once loaded. Reclaiming memory after a failed
allocation then swept deferred frees in that context, and crashed in
zeMemAllocHost.

Reset it both after the workload and when initializing the driver, like the
extension properties cache.
The workload cleanup forgets the report slabs, but a stream it created can
still be finalized afterwards, typically at exit, where returning its slot
failed with a KeyError. Such a slot belongs to a forgotten slab, so drop it.
Also clear the slabs under the pool lock, which such a finalizer takes.
@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.87%. Comparing base (592513a) to head (f4abf25).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #782      +/-   ##
==========================================
+ Coverage   86.71%   86.87%   +0.15%     
==========================================
  Files          55       55              
  Lines        5143     5099      -44     
==========================================
- Hits         4460     4430      -30     
+ Misses        683      669      -14     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maleadt
maleadt merged commit 206cec6 into main Nov 25, 2026
5 checks passed
@maleadt
maleadt deleted the tb/stale-deferred-free-context branch November 25, 2026 19:05
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.

1 participant