ReviewOS

zig-utils/zig-js

TSan: keep constructing GC slab slots private

#128
Closed chris opened this 9 days ago ·
9 days ago

Dependency: zig-utils/zig-gc#29 Related: #96

Evidence

Fresh main run 29464204902 failed tsan-threadfuzz-midgc with three races from the same allocation-publication gap:

  • zig-gc headerForInteriorAddress read header magic while a mutator's allocator zeroed a fresh cell slab;
  • the same classifier read header size during initialization;
  • claimMark touched the mark bit while the slot was still being initialized.

The binding's owned-slab classifier currently treats every issued slot as classifiable. Slot reservation happens under the size-class lock before zig-gc initializes the header after allocation returns, so a conservative stack scan can observe private construction memory. This is distinct from #96's correctly diagnosed convergence-witness failure.

Evidence: https://github.com/zig-utils/zig-js/actions/runs/29464204902/job/87513830801

Acceptance

  • Track header-published slots separately from issued/free backing slots under the existing size-class lock.
  • Make exact payload and conservative-interior classifiers return only published slots.
  • Publish only after zig-gc initializes the complete header; unpublish before magic clear/reuse.
  • Preserve batch allocation, reuse accounting, bulk teardown, owned header validation, and collector performance.
  • Add focused fresh/reused/batch/parallel transition coverage.
  • Pass focused normal and TSan mid-GC checks, then one fresh full-main gate.
9 days ago

Implemented the downstream classifier half in 58c70821 on main (with zig-gc 466718d): issued slab slots now remain owned_empty until zig-gc release-publishes a fully initialized header, and sweep/deinit withdraw publication before finalization or reuse. Focused validation passed: 16/16 parallel_gc tests and the exact owned-slot publication test under TSan (2/2, no leaks). Keeping this open for the batched full TSan/mid-GC CI gate.

9 days ago

Performance follow-up 17624edf publishes a same-size VM allocation batch under one bucket lock (zig-gc 092d8d7). Focused batch + 16/16 parallel-GC tests pass. Five-sample object-churn probe after rebuilding: median ~81.7 ms single and ~1.56 s shared/8, versus accepted README baseline 80.38 ms and 1.923 s; the race fix therefore does not regress the shared benchmark and materially improves that probe.

9 days ago

Completed by 58c70821 and 17624edf with zig-gc 466718d / 092d8d7. Focused owned-slot TSan, 16/16 parallel-GC tests, and CI tsan-threadfuzz-midgc in run 29465812082 all passed; the job ran suppression-free for 12m45s and directly covered the original magic/size/mark construction races. The later run failure was the separate Date compiler-lowering issue #126.

Sign in to comment on this issue.