startup: count DirectStorage page requests by where they end in the heartbeat #1857
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1864"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T19:45:46Z.
What
The DirectStorage stand-in (
src/startup_stubs/xcrdapi.cpp) now counts page-destination requests by wherepage_offset + destination_sizeends against the first 64 KiB page: inside it, exactly at its end, or past it. Each group is split into completed and failed. The heartbeat prints the counts as a third line, after the failure-cause line from #1781:Nothing else changes. Outcomes, statuses, ordering, the totals line, the failure-cause line and the per-request text are all as before. This is the page-shape follow-up mentioned in #1198 ("Page-shape counts can follow separately").
Refs #1198
Refs #1758
Why
Counts from local loading runs (aggregates only), split by where each page-destination request ends:
page_offset + dest_sizeEvery destination-capacity failure in those runs had the "ends exactly at the page end" shape: a zlib stream longer than
dest_size. These numbers were collected with a local diagnostic. This PR makes the same split available in any heartbeat, so other runs can be compared without that patch. The numbers are only the motivation. This PR does not change any outcome, and it does not explain why that shape fails or what the title expects for it.Change
options & (1ull << 21).page_offsetis the low 16 bits of the u64 at +0x10, anddestination_sizeis the u32 at +0x18. Both are read exactly asexecute_requestandqueue_enqueue_requestread them.end = u64(page_offset) + destination_size. Because the sum is 64-bit it cannot wrap.end < 0x10000is inside,== 0x10000is at the page end,> 0x10000is past it. A destination size of 0 ends at its offset, so it counts as inside.execute_request, after the existingfaileddecision, using the same expression:failedmeans failed, and anything else exceptemptymeans completed (the request was written).empty(source size 0 or null destination) is neither completed nor failed, so it is not counted. This matches howemptyis not a failure on the totals line.run_entry, beforeexecute_request) counts as failed for its shape.fail_entry) also counts as failed.failed=.fail_unstarted: the queue could not record or start them, and Submit failed them) are not counted, because they never ran. TheirUnrecordedrecord also does not keep the request bytes. So the page failed counts can be lower than the page share offailed=under out-of-memory. The fixture states and checks the normal case.LONG[3][2]array updated withInterlockedIncrement. There is no allocation and no lock on the worker path. The heartbeat samples the array alongside the failure causes and prints it only when the totals line prints.inflated=,options=,commit peak=,->,Queue::EnqueueStatus,entry typeorheartbeat:text:tools/startup/live_view.pysends any line containingheartbeatto its frames branch, which needsheartbeat: <n> frames, so it ignores this line.RE_DSTORAGE_*patterns intools/startup/triage_run.pymatch it.HEARTBEATregex intests/startup_heartbeat_check.pyneedscommit peak=on the same line.startup_heartbeat_commitstill passes.docs/startup-runtime.mdhas a new Findings entry, "DirectStorage page-request ends (#1198)", and the heartbeat paragraph now mentions the third line.Tests
New fixture
tests/startup_storage_page_end_counts.cpp. It is a sibling ofstartup_storage_failure_countsand compilesxcrdapi.cppinto itself.Page writes go through
x2w_xmem_write_physical, so the fixture loads the built xmem shim ($<TARGET_FILE:xmem_shim>) asxmem.dlland takes two page tokens fromXMemAllocatePhysicalPagesunderX2W_XMEM_PERMISSIVE. It uses no device or GPU. All requests use memory sources, so the chunked-stream cache does not apply.One Submit carries these requests. Each is followed by its status entry, and a fence closes the Submit.
run_entry); unknown option bitemptypage request; a linear request that completesExpected counts: inside 2/3, at-page-end 3/2, past 1/3. They are chosen so that swapping any two shapes changes at least one count.
The fixture checks:
failed=total - 1 linear failure;Environment: Windows 11 Home 10.0.26300, MSVC 19.44.35221 x64, CMake 4.5.0 / Ninja,
devpreset. Commit5b5d9260onbbadc76d(upstream/main).Result: both tests pass (2/2).
Result: 17/17 passed, including
startup_storage_failure_counts(+ control),startup_heartbeat_commit,startup_triage_run,startup_storage_worker_start,startup_dstorage_destinationandcpu_native_dstorage.Result: 239 tests, 235 passed, 0 failed, 4 skipped. The skips are capability skips (77):
startup_view_heap_warp,startup_view_heap_hardware,startup_logical_view_warpandstartup_logical_view_hardware.Results:
docs_links_check.py: 18 Markdown files, 370 links, pass.bidi_controls_check.py: 1325 tracked files, no bidirectional controls.Negative controls
Registered.
startup_storage_page_end_counts_one_bucket_control(--mutate one-bucket,WILL_FAIL) expects every page request at the page end. It fails as intended:Manual mutant 1, recorded and reverted.
==and>swapped inpage_end, soif (end > 0x10000) return PageEnd::at_page_end;:Manual mutant 2, recorded and reverted. A 32-bit sum,
const u64 end = page_offset + destination_size;:Check of the log assertion, reverted. Expecting "missing page grant token" for the page-write failure gives
FAIL: outcome "missing page grant token" logged 1 times, expected 2.Not covered
startup_heartbeat_commitruns the real heartbeat, but it does not assert the third line.x2w_xmem_write_physicalreturning success. It does not read back page contents;startup_stub_consumercovers that.fail_entry(a request whose run threw) path is counted by the code but not exercised by this fixture.🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:49:46Z.
Review: COMMENTED
Review of
5b5d9260(merge basebbadc76d;origin/mainis now5a6ad936, andgit merge-treeof the two merges cleanly). Comment only, not an approval.Verdict
No P1 or P2 found. The change is counting only, the arithmetic cannot wrap, and the heartbeat line cannot be mistaken for the existing parsed line. Three P3 notes. Clean-room and title-neutral: the numbers in the description are aggregates, the fixture is source-built, and no title code or data is involved.
Overflow and page arithmetic
end = u64{page_offset} + destination_sizewithpage_offsetalready masked to 16 bits anddestination_sizea u32: the largest sum is 0xFFFF + 0xFFFFFFFF, far below 2^64, so it cannot wrap. The thresholds are< 0x10000inside,== 0x10000at the end,> 0x10000past it, with a size of 0 landing inside. The two reads (request + 0x10as u64,request + 0x18as u32) lie within the 0x48-byteEntry::bytes, and they are the same readsexecute_requestalready does.Behaviour-neutral
In
execute_requestthe only change to existing logic is hoistingstrcmp(outcome, "empty")intoempty;failedis the same expression. The new counter call sits aftercount_failure, so a failed request adds tofailed=and to a page counter from the same decision. Statuses, ordering,E_FAILonpending, and the per-request log text are untouched.Counted once
run_entryunreadable-page-array path: counts failed and returns beforeexecute_request, so no second count.run_entrygoes tofail_entry, which counts failed only forEntry::request(the counter itself ignores requests without bit 21). Aftercount_page_requestthe only thing left inexecute_requestis logging, so I see no route to a double count.fail_unstarteddoes not callfail_entry, so entries that never started are not counted, as stated.Heartbeat format
The new line is printed after the causes line, from the same sample. It carries no
commit peak=, so the regex intests/startup_heartbeat_check.py(which requirescommit peak=…) cannot match it, and no other script readsx2w-dstorage heartbeat. The 384-byte buffer is enough: the fixed text is under 200 bytes and six%ldadd at most about 66 more.P3
fail_entrybranch (a request whose run threw) is not exercised by the fixture. The description says so.execute_requestalready parsed. It works, and a future change to one decoder would need the other changed too.startup_heartbeat_commitruns the real heartbeat thread but does not assert the third line, so only the formatter is checked, not that the thread prints it.Commands run (Linux, Python 3.14.8)
python -B tests/docs_links_check.py: Self-test passed. Checked 18 Markdown files and 370 links.python -B tests/bidi_controls_check.py: Self-test passed. Checked 1325 tracked source, script and build/CI files: no bidirectional controls.git diff --check origin/main...HEAD: clean.git grep "dstorage heartbeat": only the stand-in, its two fixtures and the docs.x86_64-w64-mingw32-g++ -fsyntax-only tests/startup_storage_page_end_counts.cpp: stops atlocal_log.h:72(__except, MSVC SEH). The fixture and its manual mutants cannot be built here, so I could not run any mutation. Everything above about the C++ is from reading the diff.Not run
startup_storage_page_end_countsand its_one_bucket_control(Windows/MSVC, xmem shim), and the author's mutants. I neither confirm nor dispute their results; the mutants described (swapped==/>, 32-bit sum) are the right ones for the arithmetic above.AI-assisted; commands listed were executed locally.