runtime: fail a DirectStorage request on allocation failure #1403
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1410"
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 tedin7 on 2026-11-24T10:54:27Z.
What
The DirectStorage stand-in's queue worker (
src/startup_stubs/xcrdapi.cpp):catch (...)also fails the request, so a non-standard exception no longer reachesstd::terminate.CreateThreadthread with a stack committed at creation (1 MiB,worker_stack_commit) instead of astd::threadwhose stack grows on demand.startup_storage_alloc_failure(tests/startup_storage_alloc_failure.cpp), registered next tostartup_storage_file_range.docs/startup-runtime.md.When no allocation fails the success path is unchanged: same
run_entrycall, same bookkeeping.Why
Addresses #1199 (item 3 only)
Done-when for this item: an allocation failure in the worker fails the request instead of ending the process.
5e775ddaalready catchesstd::exceptionon the worker, but that was never tested, and the issue reports a stack overflow (0xc00000fd) while the exception was handled. The handler formatted and logged inside the catch, on a stack that is committed page by page. When the system is out of commit, an untouched stack page cannot be committed either, so more stack use at that point can end in a stack overflow even though the stack is shallow. That is the justified defence here. It is a reading of the code, not a measurement.Items 1 (#1270) and 2 (
SEC_RESERVE,src/xmem_mapped_pages.cpp) are not touched. The BCPack decoder is not touched. #1390 also editsxcrdapi.cpp, but one line inexecute_request; this change is in the worker functions, so the hunks do not overlap.Tested
Windows (not run locally):
The check puts its own process under a job commit limit (256 MiB above its commit), then on one queue: a normal request succeeds; a request that declares a 1.5 GiB inflated size fails within 15 s with a failure status and an unchanged destination; a normal request after it returns correct data. It returns 77 where the limit is not enforced or cannot be applied.
Linux, with x86_64-w64-mingw32-g++ 14 and Wine:
xcrdapi.cpp(with a local shim for__try/__except, since mingw lacks them) build. The committed test returns 77 under Wine: Wine does not enforce the job commit limit.operator newthat throwsstd::bad_allocfor allocations of 1 GiB or more, and the test's limit steps were bypassed. With this change: exit 0, the log showsentry type 0 failed: out of memory, then the next request is served.origin/main: exit 0 (the existing catch already handles it, as the log showsstd::bad_alloc).origin/mainwith thetry/catchremoved (the state before5e775dda):terminate called after throwing an instance of 'std::bad_alloc', exit 3.python3 -B tests/docs_links_check.py,python3 -B tests/bidi_controls_check.py,git diff --check: pass.x2w_pipe.py preflight: WARN (file overlap with open PRs only).MSVC and WARP were not run locally.
Unverified
origin/main, because the catch already existed.CreateThreadwith the static runtime, as the heartbeat thread already does).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T10:57:08Z.
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit
6127f0c9(real job-commit-limit enforcement, NOT skipped):--preset dev):ctest --preset dev -R '^startup_storage_alloc_failure$' --no-tests=error --output-on-failure— 1/1 passed (0.05s)/O2(--preset release):ctest --preset release -R '^startup_storage_alloc_failure$' --no-tests=error --output-on-failure— 1/1 passed (0.05s)Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T10:57:19Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
6127f0cℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:03:58Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
6127f0c971ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:10:20Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T11:15:30Z.
Review: CHANGES_REQUESTED
Windows Release passed startup_storage_file_range and startup_storage_alloc_failure on
6bdd33c. That covers a worker servicing the next request after an allocation failure. Two points remain in the new worker-start path:Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T11:40:48Z.
Review: CHANGES_REQUESTED
The constructor catch and worker-start control address part of the previous review.
8e8e372still changes completion ordering. Submit calls fail_unrecorded before queueing earlier recorded entries, so a fence can signal before their writes run, and a failure can reach the wrong status entry. The last-resort allocation failure can still complete from Enqueue. Preserve FIFO across recorded and failed entries, or keep this PR focused on worker-start/worker-body failure and handle enqueue-allocation recovery separately with a mixed-order fixture.Independent Windows Release at this head: startup_storage_file_range and startup_storage_alloc_failure passed, while startup_storage_worker_start failed. The fixture reported that the request after the failure returned wrong data with Enqueue allocation 9 and Submit allocation 1 selected.
Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-11-24T11:19:14Z.
Tested on Windows 11 26200, MSVC 19.42, RTX 4070 Ti (driver 621.35) at c15ff1a:
startup_storage_alloc_failurefailed. Worker startup returned error 1455, and the queue did not recover (hr 0x8007000e).AI-Assisted
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:59:31Z.
Both points are addressed in 3b45fdf9 (on top of
910d428f), together with two escapes the new checks found on the way.Your two points
QueueWorkconstruction:ensure_work()now builds the work inside atry/catch (const std::bad_alloc&)at the queue boundary and treats a throwing constructor like a null result. Thepush_backcalls that can throw the same way inpush()andsubmit()are guarded too, and nothing leaves Enqueue or Submit.E_PENDINGand the fence is untouched until Submit. Submit retries the start once; if it still cannot run, the recorded entries complete withE_OUTOFMEMORYand the fences are signaled there, not earlier.What the Windows runs found while testing this
Entry::tokenswas astd::vector: in MSVC Debug its implicitly noexcept constructors and moves allocate a container proxy, so a failed allocation there ended instd::terminate. It is now aunique_ptr<ULONG_PTR[]>plus a count.pendingbefore the waiting requests were failed, and the next status entry inherited that failure. Once one entry is deferred, later entries now follow it until the next Submit, and Submit handles the stored prefix before the deferred suffix.Checks
startup_storage_worker_start: deterministic start-failure control (pending status and unchanged fence before Submit, failure status and signaled fence after), a retry that starts the worker at Submit, a sweep that fails the N-th allocation at Enqueue and at Submit on the calling thread and on every thread, a page-token path sweep, and 1008 order cases (status first or last, 1 to 9 requests). Against the earlier sources the new controls fail for the expected reasons (std::terminateat the sweep; the leak at 5 requests, Enqueue allocation 8, Submit allocation 1).startup_storage_file_range,startup_storage_alloc_failureandstartup_storage_worker_startpass 3/3 in Debug (--preset dev, 36.14 s total) and in Release /O2 (--preset release, 35.54 s total).Known limits (also in
docs/startup-runtime.md)E_OUTOFMEMORYeven if memory recovered.startup_storage_worker_starttakes about 35 s on Windows against its 60 s timeout (the sweeps dominate). I can trim the sweep bounds if you prefer more headroom on slower runners.Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:03:58Z.
Code review location:
src/startup_stubs/xcrdapi.cpp; line 662If both
CreateThreadcalls fail—for example, when the queue is first used under commit pressure—this only logs and returns the already-publishedself->work.push()andsubmit()then accept entries normally, but no thread drainssubmitted: status entries remainE_PENDINGand fence signals never run. Becauseself->workstays non-null, later calls never retry even after resources recover. Unlike the previousstd::threadconstructor's synchronous failure, this silently turns the failure into an indefinite loading stall. Roll back the work state and propagate the startup failure, or explicitly fail affected requests, rather than accepting work without a consumer.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:10:20Z.
Code review location:
src/startup_stubs/xcrdapi.cpp; line 662Fixed in
6bdd33c4:ensure_work()now allocatesQueueWorkwithnothrowand creates the workerCREATE_SUSPENDED, only publishingself->workonce a worker thread actually starts (deletingQueueWorkand returningnullptrotherwise so later calls can retry). Whenensure_work()returnsnullptr,push()fails unstarted requests (E_OUTOFMEMORYonself->pending), completes status entries withE_OUTOFMEMORYinstead of leavingE_PENDING, and signals fences immediately. Verified instartup_storage_alloc_failure(Debug & Release/O21/1 passed on Win2025).Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T12:30:23Z.
Review: COMMENTED
Release passes the three storage checks at this head. The remaining ordering hole is in submit(): after notifying the worker, Submit processes the failed suffix on its own thread. A status or fence in that suffix can complete while an earlier successfully submitted request is still running, and the suffix can consume the pending error before the worker reports the earlier request. Please serialize suffix completions behind the submitted prefix. A deterministic control can hold the prefix at an event, inject only the suffix allocation failure, and check that destination, status, and fence become visible in queue order.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:41:29Z.
Fixed in
f500398e: Submit now waits, without allocating, until the worker has finished the submitted prefix before it completes the failed suffix (or the entries that could not be moved), so suffix statuses and fences become visible in queue order and see the prefix failures. A Submit made from the worker itself does not wait. startup_storage_worker_start has a new control (suffix_waits_for_prefix): the prefix is a fence held at an event inside the worker, only the suffix storage allocation fails, and the status and suffix fence must stay incomplete while the prefix is held, then complete after the prefix fence. The all-thread allocation sweep now counts only buffer-sized allocations on the worker, because a small one there is the MSVC debug container proxy inside a noexcept vector constructor (it aborted the Debug run at the previous head too).Win2025 Debug and Release /O2: startup_storage_worker_start, startup_storage_alloc_failure and startup_storage_file_range pass 3/3 in both.
Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-11-24T12:53:57Z.
Retested on Windows 11 26200, MSVC 19.42, RTX 4070 Ti at
f500398e: all three pass in both presets.The 1455 worker-start failure from my earlier run is gone.
AI-Assisted
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:56:00Z.
Thanks @SimSalabimse for retesting
f500398eon Windows 11 26200 / MSVC 19.42 / RTX 4070 Ti across both Debug and Release presets!Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T13:07:20Z.
Review: COMMENTED
The held-prefix regression and all three Release cases pass on
f500398e. The remaining gap is the submit cutoff: Submit records prefix_end, releases the queue lock, and later fail_waiting/fail_unrecorded drains the live queues. While the held prefix is running, a producer can enqueue the next batch and the first Submit can complete its status/fence before its own Submit. Please snapshot the batch at the cutoff and ensure ordered completion of that snapshot. Extend the held-prefix test with a second batch enqueued while the first prefix is held; its status and fence should stay pending through the first Submit. Also avoid waiting for prefix completion on the calling thread if the prefix can depend on work submitted after Submit returns. Microsoft DirectStorage guidance: https://github.com/microsoft/DirectStorage/blob/main/Docs/DeveloperGuidance.mdImported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T13:25:37Z.
Review: COMMENTED
Release passes the three storage cases on this head, including the new two-batch cutoff control. One remaining lock issue is in complete_deferred: the completion mutex is held while fail_unstarted calls the fence, and Submit can also enter complete_deferred. This holds a queue lock across a caller-supplied operation and can block a submitting thread behind that operation, or deadlock a callback that submits a deferred entry to the same queue. Please keep one completion owner and invoke fences without holding the serialization mutex. An event-gated fence plus a second Submit that returns while the fence is held can pin this behavior.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T13:48:21Z.
Review: COMMENTED
All three Release storage tests pass on
0b1f880b. The completion flag resolves the lock held across a fence. One ownership case remains: if a Submit thread owns a ready deferred fence and its signal is held, the worker can see completing=true, return from complete_deferred, and dequeue a newer submitted status or fence. Make the deferred and normal completions use the same order. Extend the event control to hold the deferred fence itself and verify that a normal fence from a later Submit cannot signal until it is released.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T13:11:27Z.
Fixed in
9bb7e5ec: Submit now snapshots the failed entries at its cutoff, under the queue lock. That covers the stored entries it could not move and the unrecorded ones. The worker completes the snapshot right after it finishes that Submit's prefix. Snapshots are ordered by Submit, and within one Submit the stored entries come before the unrecorded ones. A later batch enqueued while the prefix is held can no longer be drained or completed by the first Submit.Submit no longer waits for the prefix on the calling thread, so a prefix that depends on work submitted after Submit returns cannot deadlock it. The snapshot reuses the existing records and allocates nothing. If the snapshot storage itself cannot grow, Submit falls back to the earlier wait-then-fail path, which stays in order.
suffix_waits_for_prefixnow holds the prefix at the event and requires the first Submit to return. It then enqueues and submits a second batch (status index 1 plus a fence) while the prefix is held. It checks that both statuses and both extra fences stay pending, and that the prefix, suffix and second-batch fences complete in queue order after release.Windows Server 2025 (Build 26100, MSVC 14.44),
startup_storage_(worker_start|alloc_failure|file_range):dev): 3/3 passed./O2(release): 3/3 passed.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T13:36:27Z.
Fixed in
0b1f880b: complete_deferred no longer holds a mutex across fences. A single completion owner (a flag under the queue lock) takes the snapshot entries, runs fail_unstarted with no lock held, and hands ownership back only when nothing is left; a thread that finds an owner returns at once, so Submit never waits behind a caller-supplied fence and a fence callback that submits a deferred entry cannot deadlock. The regression in tests/startup_storage_alloc_failure.cpp gates a fence on an event, runs a second Submit with a new deferred entry while the fence is held, requires it to return, and requires its status to fail after the fence is released.Win2025 at
0b1f880b: Debug (dev) startup_storage_(worker_start|alloc_failure|file_range) 3/3 passed; Release /O2 3/3 passed.Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-11-24T13:56:03Z.
Retested at
0b1f880bon Windows 11 26200, MSVC 19.42, RTX 4070 Ti (driver 621.35).AI-Assisted
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T14:18:31Z.
@SimSalabimse thank you for the
0b1f880brun on the RTX 4070 Ti. The error 1455 onstartup_storage_alloc_failureunder parallel builds is memory pressure, as you suspected. The test passes when it runs alone.@R0Y00 Fixed in
56ff9b20: the worker no longer starts a newer submitted status or fence while snapshot completions of an earlier Submit are ready or owned by another thread. The worker waits until that owner finishes, and the owner wakes it on release. Deferred and normal completions now use the same order.startup_storage_worker_starthas a new stage,suffix_waits_for_deferred_fence. It holds the deferred fence itself at an event, then enqueues and submits a later batch. That batch's status entry and normal fence must stay unsignaled until the event is released, and then everything completes in queue order.Windows Server 2025 (MSVC 14.44, WARP) at
56ff9b20:startup_storage_file_range,startup_storage_alloc_failureandstartup_storage_worker_startpass, 3/3./O2: the same three tests pass, 3/3.AI-Assisted
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T14:28:46Z.
Retested
56ff9b20on Windows x64 Release (MSVC 19.51). startup_storage_file_range and startup_storage_worker_start passed, including suffix_waits_for_deferred_fence. During the same CTest run, with another build active, startup_storage_alloc_failure crashed after three worker creation failures with Win32 1455, matching SimSalabimse. Three isolated repeats then passed. Keep the PR open until the low-commit path can complete the failed status and fence without an access violation or stack overflow. Please capture the exception code and first frame in the source-built fixture and cover that failure deterministically if possible. The ordered-completion fix should stay.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T14:54:18Z.
@R0Y00 Updated in
5fad2caf4161f2ec3ad14a28c9bd2a800aca8015(the ordered-completion fix andsuffix_waits_for_deferred_fenceare untouched).What changed in
tests/startup_storage_alloc_failure.cppERROR_COMMITMENT_LIMIT) coverage via aCreateThreadIAT hook onXCRDAPI.dll(no real memory pressure needed):Enqueue*calls each fail bothCreateThreadattempts with 1455 (verified againstX2W_TRAP_LOG: 3xqueue worker not started: error 1455), thenSubmitstarts the worker and completes the batch in order.CreateThreadcall fails with 1455 and the default-stack fallback succeeds.CreateThreadcalls fail across two batches and an emptySubmit; status entries complete in queue order withE_OUTOFMEMORY, fences signal only after their preceding status entries, destinations remain untouched, and the same queue recovers onceCreateThreadsucceeds again.256 KiBstack at creation and callSetThreadStackGuarantee(64 KiB) so they do not rely on growing the stack after commit is exhausted.UnhandledExceptionFilterusing only static buffers prints the exception code, faulting address (plus read/write target on access violation), and up to 8 unwound x64 frames (module+offsetviaRtlLookupFunctionEntry/RtlVirtualUnwind) tostderr, then exits with0xE1410.Transparency on the concurrent-build crash
The intermittent crash under a concurrent build did not reproduce on our Windows Server 2025 VM (neither before nor after
5fad2caf). If it triggers again under concurrent build load on MSVC 19.51, the fixture will now record the exception code and first unwound frames onstderr(exit0xE1410) so we can pinpoint the exact fault.Verification at
5fad2caf(Windows Server 2025 Build 26100, MSVC 14.44.35207, D3D12 WARP, 0 warnings)--preset dev):startup_storage_file_range(0.01s),startup_storage_alloc_failure(0.11s),startup_storage_worker_start(37.04s) — 3/3 passed; 2 additionalstartup_storage_alloc_failurerepeats passed (0.11s,0.08s)./O2(--preset release):startup_storage_file_range(0.01s),startup_storage_alloc_failure(0.12s),startup_storage_worker_start(36.82s) — 3/3 passed; 2 additionalstartup_storage_alloc_failurerepeats passed (0.12s,0.11s).Assemble and translate gfx1013 fixtures,Build and test on Windows,Run platform-independent Python checks on Linux).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T15:17:21Z.
Review: APPROVED
Windows Release at
5fad2cafpassed startup_storage_file_range, startup_storage_alloc_failure and startup_storage_worker_start (3/3). The deterministic worker-start failures cover completion order, untouched output and recovery, and the held deferred fence check still passes. The previous real-pressure crash did not recur in this run. The fixture now pre-commits the submitter stacks and reports a diagnostic if it recurs.Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-11-24T15:34:51Z.
Retest of
5fad2caf4161f2ec3ad14a28c9bd2a800aca8015on Windows 11 26200, MSVC 19.42.34435, RTX 4070 Ti driver 621.35.dev
ctest --preset dev --no-tests=error -R '^startup_storage_' --output-on-failureExit code 0. 3 tests passed, 0 failed. Total 37.29 sec.
startup_storage_file_rangestartup_storage_alloc_failurestartup_storage_worker_startrelease
ctest --preset release --no-tests=error -R '^startup_storage_' --output-on-failureExit code 0. 3 tests passed, 0 failed. Total 37.21 sec.
startup_storage_file_rangestartup_storage_alloc_failurestartup_storage_worker_startThe filter matched those three tests.
startup_storage_directory_batchwas not registered becauseINTAKE_PYTHONwas absent.Pressure
startup_storage_alloc_failureran on the release preset while a second checkout of the same commit was compilingcmake --build --preset release --clean-first. ctest started with 19cl.exeprocesses and ended with 34, and that build was still running.ctest --preset release --no-tests=error -R '^startup_storage_alloc_failure$' --output-on-failure --repeat until-fail:5Exit code 0. Five passes: 0.14 sec, 0.14 sec, 0.14 sec, 0.27 sec, 0.34 sec. Total 1.08 sec.
The ctest output had no
error 1455lines and no crash report. The test did not exit0xE1410.Isolated controls
The same release command, one run at a time, after that build had exited and with no
cl.exerunning:AI-Assisted