runtime: always commit fresh slot in section_for() #3366
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!3366
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3364"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@KelboLive on GitHub · 2026-11-28 14:04 UTC · original
KelboLive:fix/xmem-fresh-slot-clean-2→main· +1 −1 · 1 files · 1 commits · closed without mergingIn \section_for(), when creating a new slab for a fresh page, \make_slab\ commits offset 0 of the slab. The original code only committed the target slot (at \slot.offset) when !first_slot_committed\ was true — which never happens because \make_slab\ returns false if committing offset 0 fails.
This left fresh slots at non-zero offsets uncommitted in non-lazy mode, causing access faults on first use. Remove the !first_slot_committed\ guard so the target slot is always committed before recording it.
Fixes: #3357
@R0D4X on GitHub · 2026-11-28 14:13 UTC · original · reviewed
I checked PR 3364 at commit
97fcd1eb27b8f17670990f174e56b4308673e63fon Windows 11 Pro 26H2 (build10.0.26300.0), MSVC19.44.35230.0.nvidia-smireportedNVIDIA GeForce RTX 5080, 621.40; D3D WARP/hardware lines reportedMicrosoft Basic Render Driver, debug layer enabled, driver10.0.26100.9818, andNVIDIA GeForce RTX 5080, debug layer enabled, driver32.0.16.2140.Logic:
first_slot_committedis false for fresh slots taken from an existing slab and true only whenmake_slabcommits the first slot, so the old guard did not suppress the commit for fresh slots from existing slabs. The unconditionalcommit_slot(..., false)is harmless and is covered by the commit, lazy/off, and page-run checks below.Environment setup and configure:
Build:
Selected tests:
Result: 13/13 passed in dev, 13/13 passed in release, no skips. Hardware lines reported
NVIDIA GeForce RTX 5080, debug layer enabledwith driver32.0.16.2140; WARP lines reported debug layer enabled with driver10.0.26100.9818.Targeted mutations (all reverted, then clean rebuild and rerun above):
if (!defer && !commit_slot(slot.slab, slot.offset, false)) {->if (!defer && false && !commit_slot(slot.slab, slot.offset, false)) {Result:
1/1 Test #49: xmem_mapped_pages_commit .........***Exception: SegFault 0.11 sec,0% tests passed, 1 tests failed out of 1,49 - xmem_mapped_pages_commit (SEGFAULT).const bool defer = !need_commit && lazy_commit();->const bool defer = !need_commit;Result:
AssertionError: off: a page was left lazy,0% tests passed, 1 tests failed out of 1.if (!commit_slot(slot.slab, slot.offset, true)) return nullptr;->if (!commit_slot(slot.slab, slot.offset, false)) return nullptr;Result:
100% tests passed, 0 tests failed out of 1; this probe did not change the selected outcome and was reverted.No blocking defect found in the change itself.
AI-assisted; commands listed were executed locally.
@Leyukaka on GitHub · 2026-11-29 00:10 UTC · original
Reviewed
97fcd1ebby its diff andsrc/xmem_mapped_pages.cpp/src/xmem_slab_slots.hon main51472392. The guard removed here does not skip commits of non-zero fresh slots:first_slot_committedis set only inmake_slab, andtake_freshcallsmake_slabonly when it opens a new slab, then hands out offset 0, whichmake_slabhas just committed. For a fresh slot taken from an existing slab the flag stays false, and main's line 359 already commitsslot.offset.commit_slotfails, the slot is unwound andsection_forreturnsnullptrwhere main returns the slab.&& falsemutation in the review above disables that line for every fresh slot, including the non-zero ones main already commits there, so it does not exercise the guard; restoring the guard gives main's code.If the body describes an observed failure, a repro or a fixture that fails on main would settle it. Otherwise a comment at line 359 saying the flag implies
slot.offset == 0would make that explicit. Not mergeable as is at97fcd1eb.@JohnConnorNPC on GitHub · 2026-11-29 12:52 UTC · original
Re-reviewed at
97fcd1eb27against main77d1ba4d(by readingsrc/xmem_mapped_pages.cppandsrc/xmem_slab_slots.h).git merge-treeexits 0. CI: 3 success, 2 skipped. I agree with the analysis above. On main,first_slot_committedis true only whentake_freshhas just opened a slab and handed out offset 0, whichmake_slabhas already committed. So no non-zero fresh slot is left uncommitted, and this change adds a secondMapViewOfFile/VirtualAlloc/UnmapViewOfFileof offset 0 for each new slab. Points not raised yet:MUST
deferis false (lazy commit not requested, or its handler not installed). If that second commit fails,unwind_freshruns andsection_forreturnsnullptr, where main returns the slab it has already committed. So the change adds a failure path and fixes no observed fault. Without a repro or a fixture that fails on main, it shouldn't merge. If the goal is clarity, a comment at that line stating "flag ⇒slot.offset == 0, already committed" keeps main's behaviour.SHOULD
2. The same commit is also in #3368. Whatever happens here, it should come out of #3368 so the two don't land twice or diverge.
Holding, not merging.
AI-assisted.
@KelboLive on GitHub · 2026-11-29 16:20 UTC · original
Closing: the change is not correct, so it should not go in as written.
section_for()creates a new slab throughmake_slab, which commits offset 0:take_fresh()(src/xmem_slab_slots.h) callsmake()only when it opens a slab (slabs_.empty() || fresh_used_ == slots_per_slab), and then resetsfresh_used_ = 0, so the slot it returns is atfresh_used_ * slot_bytes_— offset 0 of the slab just committed. On that pathfirst_slot_committedis true and the later commit is correctly skipped.A slot at a non-zero offset always comes from an existing slab. There
make()does not run,first_slot_committedstays false, andmainalready commitsslot.offset.So
!first_slot_committedis not dead state — it is the guard that stops a secondcommit_slotof offset 0 for every new slab. Removing it leaves the default xmem path doing one extra map plus commit per new slab and fixes nothing. The PR description reads the condition the other way round.No fixture showed a slot left uncommitted, which is what this would have needed. If one exists, a test that faults on
mainand passes here would be the way to reopen this.Pull request closed