Repository navigation
startup: probe DirectStorage destinations instead of walking them with VirtualQuery - #2685
Conversation
…h VirtualQuery destination_writable walked the destination with VirtualQuery. On the title's multi-gigabyte regions each query scans to the end of the region, which cost the storage worker about 10 ms of kernel time per request during the first load. Probe one byte per page with an atomic OR of zero under SEH instead (x2w_local::probe_writable, the write twin of probe_readable). It faults where a write would, changes no byte, and re-arms a guard page it trips. The test now also checks the guard bit after the refusal and that probed pages past the data keep their bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
R0Y00
left a comment
There was a problem hiding this comment.
The measured VirtualQuery cost is worth fixing. I ran a source-built MSVC /O2 witness against this head. With a vectored observer, VirtualQuery produced 0 guard notifications. probe_writable refused the same protected page and restored PAGE_GUARD, but the observer saw 1 first-chance guard exception before the local handler. A second case used a FILE_MAP_COPY page followed by PAGE_NOACCESS. The probe stopped after 4096 of 8192 bytes yet QueryWorkingSetEx showed the first page changed from shared to private, with the byte unchanged. Please keep non-touch validation for unproven page ranges. Any fast path needs a stable classification that establishes ordinary writable backing across the full range. Preserve the queue failure and no-touch controls, including zero guard notifications and an earlier copy-on-write page remaining shared when a later page refuses the request. See the Microsoft guard-page and vectored-exception-handler documentation.
Review of R0Y00#2685: the write probe raised a first-chance guard-page exception that a vectored handler sees, and it gave a copy-on-write page its private copy even when a later page refused the request. Remove probe_writable. destination_writable now reads page attributes only: one QueryWorkingSetEx per 512 pages accepts a destination whose pages are all valid, PAGE_READWRITE or PAGE_EXECUTE_READWRITE and not guarded; any other page goes to the VirtualQuery walk from main, unchanged. The test adds a first vectored handler that must see no guard-page exception on any refusal, a copy-on-write page followed by a no-access page whose first page must stay shared, and a committed but untouched destination that takes the fallback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the witness. Both findings reproduce here: the new test below fails on the previous head's DLL with
Load cost of the main executable's first load: one release build of
Limits:
This reply was prepared with AI assistance (Claude); the runs are mine. |
R0Y00
left a comment
There was a problem hiding this comment.
This head addresses both previous refusals. The Windows Release queue test passed all 15 cases, including zero first-chance guard notifications, the refused copy-on-write request retaining its shared page, and a cold writable destination completing through the fallback. A separate MSVC /O2 witness ran the exact working-set helper across 513 resident pages. It accepted the interval, accepted the first 512 pages, then refused the interval after PAGE_GUARD was set on page 513. The guard remained armed and the observer saw zero exceptions.
Change
Fixes #2684 (DirectStorage destination check costs ~10 ms of kernel time per request).
destination_writable(#1672) keeps its verdicts but no longer callsVirtualQuery. It probes one byte per 4 KiB page of the declared capacity with an atomic OR of zero under a structured exception handler.local_log.h:x2w_local::probe_writable, the write twin ofprobe_readable(same bounds, same guard re-arm). An OR of zero faults where a write would and changes no byte, also against a concurrent writer.xcrdapi.cpp:destination_writablecallscommit_lazyas before, thenprobe_writable.docs/startup-runtime.md: the destination section describes the probe and its cost.probe_readablealready avoidsVirtualQueryfor the same reason. Its comment says that on the title's multi-gigabyte regions one query takes about a millisecond because it walks the region. startup: prove slot 133 placements without walking the allocation #1766 (slot 133 placements) and d3d12: do not wrap large allocations for unplaced memory SRVs #2611 (unplaced memory SRVs) avoid the same scan in the D3D12 stand-in.QueryWorkingSetExreports protection only for resident pages, so it would still need theVirtualQueryfallback; region information has no current protection.probe_readableinlocal_log.h(text conflict only, if it lands first). startup: stop probing unmapped guest memory from the texture and no-op paths #2245 answers readability of unmapped memory from xmem; this probe faults only on a refusal.Verification
Windows 10 22H2, i7-4790K, RTX 3080 Ti; dev and release; commit
975f4872(onb2564017).70/70 passed in each, with no capability skips.
startup_dstorage_destination: the existing read-only, guard, no-access and short-commit refusals and the writable and copy-on-write successes all pass unchanged. New: the guard page is stillPAGE_GUARDafter its refusal; a writable destination with a three-page capacity and one page of data succeeds with the two probed, unwritten pages unchanged.guard page lost its guard bit; with an OR of 1 instead of 0 it fails the new case (a byte past the data changed) and the four refusal cases (first page was written).XCRDAPI.dlldiffers; stand-in CPU time from!runawayevery 20 s):VirtualQuerycheckdestination not writablerefusals, device removalThe confirm presses landed at different times in the two runs, so the end-to-end times are indicative; the per-request kernel time does not depend on them.
Evidence and follow-up
VirtualAllocand a pagefile-backed mapping in the test); no title data.commit_lazyalready covered the whole capacity. A local counter (not in this PR) measured this in one startup run (220 s, first load and the streaming that follows): 81,873 destination checks, 1,595,238 probed pages, 0 pages past the last written page. Every declared capacity ended in the same page as the data.Checklist
docs/startup-runtime.md)AI-assisted: the change, tests and this description were written with Claude; I ran the startup A/B.
🤖 Generated with Claude Code