Memory: bound queued host work and reclaim idle staging before world-load allocations fail #2629

Open
opened 2026-11-26 04:07:24 +00:00 by pickles976 · 5 comments
pickles976 commented 2026-11-26 04:07:24 +00:00 (Migrated from github.com)
Contributor

Imported from ivall/xcl. Originally posted by pickles976 on 2026-11-26T04:07:24Z.


Triage request: goal:world-load (#1833). Let a loader that can finish serially spend longer loading rather than allocate several jobs’ peak scratch space at once. Please start with one measured XCL-owned buffer path, not a replacement allocator or a change to the console memory profile.

Why not just set a process cap? In #1566, a 13,824 MB process cap refused required texture pages during startup; the title died twice at 11.7 s. On our 16 GiB Linux / Wine 11.0 / RTX 4060 Laptop GPU (8 GiB), #1831’s isolated enforcement test assigned a 64 MiB job limit but a 128 MiB commit still succeeded. Neither refusal nor unenforced limits provide backpressure. Separately, a contributor on #542 reported nearly identical ~40 GB commit peaks with 4 vs 15 compiler workers, but ~28 GB with three upload/detile changes together. That makes transient copies worth measuring, not proof they dominate on every 16 GiB host.

Proposed first slice

  1. On the XCL_ACTIVITY tick, expose capacity held by upload/detile staging: reserved but not allocated, active (including fence-pinned), and idle/reusable, with high-water marks. Count backing allocations once, including capacity retained in pools, not views or just payload length. Compare these with process commit, resident memory and local/non-local GPU memory as distinct series. If staging is small at the load peak, publish that result and pick the measured owner instead.
  2. Opt in with e.g. XCL_HOST_STAGING_BUDGET_MIB (unset/0: unchanged; positive MiB converted once to bytes). For participating owners, reserved + active + idle must not exceed the configured bytes. Reserve the job’s peak simultaneous input/output/scratch before materializing it. Reuse an idle allocation or drop reconstructible idle backing before asking for more. Hold the charge through completion, including GPU fences and aliases. Never discard dirty guest data or memory still in use. Releasing a buffer means it is reusable or freed, not a claim that OS RSS immediately fell.
  3. Bound pending descriptors by count as well as payloads by bytes; defer at ingress, not after copying into an unbounded waiting list. Preserve dependency and retirement order. Do not wait holding allocator, queue or submit locks, on a thread needed to retire the work, or while holding a partial reservation needed by another job. Completion, cancellation, failure and device loss must unblock waiters. If one job cannot fit, chunk only when the format permits it; otherwise fail through the existing operation’s error path with owner, required and available bytes. No indefinite retry, partial success, or silently skipped upload.

Fit with existing work. Keep title_memory_mb guest-visible; #1566/#1831 address whole-process commit, #640/#1773 GPU pages and residency. DirectStorage already has XCL_DSTORAGE_MEMORY_BUDGET_MIB and ordered retirement: reuse that policy if integrating it later, with both limits checked in one admission decision, not two blocking reservations. Compiler parallelism (#542/#2624) can be tuned independently; opaque DXC/driver allocations are not enforceable staging bytes. This is not a maximum on RSS, title CRT allocations, worker processes or driver memory. If required live data alone exceeds physical RAM, a longer wait is not a fix.

What would demonstrate it works?

  • Deterministic two-producer fixture: both jobs fit individually but not together. Peak stays within budget, second job makes progress after retirement, and both outputs match the unlimited path byte-for-byte. Force a delayed fence and prove its backing is not recycled early. Exercise idle trim, cancellation, oversize and shutdown with a waiter; none may leak credit or hang. No new gate when unset.
  • Guarded parent/head comparison with identical cache state, inputs and workload: report staging peak, bytes reclaimed, waits/time, process/scope peak, minimum available RAM and last completed load stage. Repeat with cold and warm caches distinguished. On this 16 GiB Wine machine keep the 9 GiB scope, 512 MiB swap ceiling and 2 GiB system headroom guard; don't approach a kernel OOM to demonstrate one. If the stock vkd3d integration (#175) stops the title earlier, report fixture evidence only. Lower staging usage with unchanged total pressure is useful negative evidence, not proof of gameplay.

Maintainer decision requested: does an activity-counter patch for upload/detile staging followed by an opt-in admission patch for the measured owner fit the world-load roadmap?

AI assistance: OpenAI Codex reviewed existing reports and drafted this proposal. The linked Wine cap result is a local fixture; the other XCL load measurements are attributed above. No retail data attached.

<!-- greyfinch-sync:ivall/xcl:issue:6619283940 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2639). Originally posted by [pickles976](https://github.com/pickles976) on 2026-11-26T04:07:24Z. --- **Triage request: `goal:world-load` (#1833).** Let a loader that can finish serially spend longer loading rather than allocate several jobs’ peak scratch space at once. Please start with one measured XCL-owned buffer path, not a replacement allocator or a change to the console memory profile. **Why not just set a process cap?** In [#1566](https://github.com/xcl-dev/xcl/issues/1566#issuecomment-7140271276), a 13,824 MB process cap refused required texture pages during startup; the title died twice at 11.7 s. On our 16 GiB Linux / Wine 11.0 / RTX 4060 **Laptop** GPU (8 GiB), [#1831’s isolated enforcement test](https://github.com/xcl-dev/xcl/pull/1831#issuecomment-7181679304) assigned a 64 MiB job limit but a 128 MiB commit still succeeded. Neither refusal nor unenforced limits provide backpressure. Separately, a contributor [on #542](https://github.com/xcl-dev/xcl/issues/542#issuecomment-7121248709) reported nearly identical ~40 GB commit peaks with 4 vs 15 compiler workers, but ~28 GB with three upload/detile changes together. That makes transient copies worth **measuring**, not proof they dominate on every 16 GiB host. **Proposed first slice** 1. On the `XCL_ACTIVITY` tick, expose capacity held by upload/detile staging: reserved but not allocated, active (including fence-pinned), and idle/reusable, with high-water marks. Count backing allocations once, including capacity retained in pools, not views or just payload length. Compare these with process commit, resident memory and local/non-local GPU memory as distinct series. If staging is small at the load peak, publish that result and pick the measured owner instead. 2. Opt in with e.g. `XCL_HOST_STAGING_BUDGET_MIB` (unset/0: unchanged; positive MiB converted once to bytes). For participating owners, **reserved + active + idle must not exceed the configured bytes**. Reserve the job’s peak simultaneous input/output/scratch before materializing it. Reuse an idle allocation or drop reconstructible idle backing before asking for more. Hold the charge through completion, including GPU fences and aliases. Never discard dirty guest data or memory still in use. Releasing a buffer means it is reusable or freed, not a claim that OS RSS immediately fell. 3. Bound pending descriptors by count as well as payloads by bytes; defer at ingress, not after copying into an unbounded waiting list. Preserve dependency and retirement order. Do not wait holding allocator, queue or submit locks, on a thread needed to retire the work, or while holding a partial reservation needed by another job. Completion, cancellation, failure and device loss must unblock waiters. If one job cannot fit, chunk only when the format permits it; otherwise fail through the existing operation’s error path with owner, required and available bytes. No indefinite retry, partial success, or silently skipped upload. **Fit with existing work.** Keep `title_memory_mb` guest-visible; #1566/#1831 address whole-process commit, #640/#1773 GPU pages and residency. DirectStorage already has `XCL_DSTORAGE_MEMORY_BUDGET_MIB` and ordered retirement: reuse that policy if integrating it later, with both limits checked in one admission decision, not two blocking reservations. Compiler parallelism (#542/#2624) can be tuned independently; opaque DXC/driver allocations are not enforceable staging bytes. This is **not** a maximum on RSS, title CRT allocations, worker processes or driver memory. If required live data alone exceeds physical RAM, a longer wait is not a fix. **What would demonstrate it works?** - Deterministic two-producer fixture: both jobs fit individually but not together. Peak stays within budget, second job makes progress after retirement, and both outputs match the unlimited path byte-for-byte. Force a delayed fence and prove its backing is not recycled early. Exercise idle trim, cancellation, oversize and shutdown with a waiter; none may leak credit or hang. No new gate when unset. - Guarded parent/head comparison with identical cache state, inputs and workload: report staging peak, bytes reclaimed, waits/time, process/scope peak, minimum available RAM and last completed load stage. Repeat with cold and warm caches distinguished. On this 16 GiB Wine machine keep the 9 GiB scope, 512 MiB swap ceiling and 2 GiB system headroom guard; don't approach a kernel OOM to demonstrate one. If the stock vkd3d integration (#175) stops the title earlier, report fixture evidence only. Lower staging usage with unchanged total pressure is useful negative evidence, not proof of gameplay. Maintainer decision requested: does an activity-counter patch for upload/detile staging followed by an opt-in admission patch for the measured owner fit the world-load roadmap? AI assistance: OpenAI Codex reviewed existing reports and drafted this proposal. The linked Wine cap result is a local fixture; the other XCL load measurements are attributed above. No retail data attached.
pickles976 commented 2026-11-26 05:05:31 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by pickles976 on 2026-11-26T04:16:56Z.


Human being here: basically it seems like xcl just allocates memory when the executable asks for it. Instead we should be able to set some limit of how much memory xcl is allowed to use. Requests beyond this point go into a queue, and are realloc'ed when data in memory is no longer needed. I'm not exactly sure what is being loaded during the game's startup, but I am expecting that some of that data is transient, and does not need to live in memory the whole time.

Without xcl enforcing memory limits, the game will always OOM on smaller machines. I am with family for Thanksgiving and running on my gaming laptop with 16GB and this is a hard blocker for running on this machine.

Let me know what you think.

<!-- greyfinch-sync:ivall/xcl:comment:7182456971 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2639#issuecomment-7182456971). Originally posted by [pickles976](https://github.com/pickles976) on 2026-11-26T04:16:56Z. --- Human being here: basically it seems like `xcl` just allocates memory when the executable asks for it. Instead we should be able to set some limit of how much memory `xcl` is allowed to use. Requests beyond this point go into a queue, and are realloc'ed when data in memory is no longer needed. I'm not exactly sure what is being loaded during the game's startup, but I am expecting that some of that data is transient, and does not need to live in memory the whole time. Without `xcl` enforcing memory limits, the game will always OOM on smaller machines. I am with family for Thanksgiving and running on my gaming laptop with 16GB and this is a hard blocker for running on this machine. Let me know what you think.
razormontana commented 2026-11-26 20:12:35 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by razormontana on 2026-11-26T20:12:35Z.


I’d like to take the CPU detiling measurement in #2639, in coordination with the committed-memory work in #2688. On 8b957bec, the owned read fallback allocates a full-size slice or volume buffer, copies only readable committed spans and leaves the gaps zeroed. Detiled output stays alive through the upload fence wait, and an oversized first texture can exceed the 32 MiB guest-byte batch limit. Batch lifetime · CPU backing

I’ll report live owned backing bytes for detile output and the source buffers allocated inside subresources, plus their combined peak, under XCL_ACTIVITY. Borrowed views count as zero. This complements #2862’s GPU staging counters and checks for short-lived peaks within the aggregate Rust heap already sampled for workstream 6. I’ll verify capacities and lifetimes in synthetic serial and parallel cases, including partially committed and oversized inputs, then compare with commit and DXGI usage in a guarded world-load run. The first PR would add measurements only. Earlier Rust heap measurements

AI use

Codex GPT-6.2 traced the allocation path, checked related work and drafted this claim.

<!-- greyfinch-sync:ivall/xcl:comment:7202416478 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2639#issuecomment-7202416478). Originally posted by [razormontana](https://github.com/razormontana) on 2026-11-26T20:12:35Z. --- I’d like to take the CPU detiling measurement in #2639, in coordination with the committed-memory work in #2688. On `8b957bec`, the owned read fallback allocates a full-size slice or volume buffer, copies only readable committed spans and leaves the gaps zeroed. Detiled output stays alive through the upload fence wait, and an oversized first texture can exceed the 32 MiB guest-byte batch limit. [Batch lifetime](https://github.com/xcl-dev/xcl/blob/8b957bec6f82495aec940944c6bf47faa02db590/crates/xcl/src/hle/d3d12x/title_textures.rs#L1074-L1158) · [CPU backing](https://github.com/xcl-dev/xcl/blob/8b957bec6f82495aec940944c6bf47faa02db590/crates/xcl/src/hle/d3d12x/title_textures.rs#L1457-L1483) I’ll report live owned backing bytes for detile output and the source buffers allocated inside `subresources`, plus their combined peak, under `XCL_ACTIVITY`. Borrowed views count as zero. This complements #2862’s GPU staging counters and checks for short-lived peaks within the aggregate Rust heap already sampled for workstream 6. I’ll verify capacities and lifetimes in synthetic serial and parallel cases, including partially committed and oversized inputs, then compare with commit and DXGI usage in a guarded world-load run. The first PR would add measurements only. [Earlier Rust heap measurements](https://github.com/xcl-dev/xcl/issues/2688#issuecomment-7190016474) **AI use** Codex GPT-6.2 traced the allocation path, checked related work and drafted this claim.
kotekompotek commented 2026-12-02 16:26:15 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by kotekompotek on 2026-12-02T16:26:15Z.


Field measurements from a sister translation layer (D3D12-based, copy-architecture shadow memory) fighting the same world-load memory wall on genuinely weak hardware (8 GiB RAM / 2 GiB VRAM), in case the signals transfer:

1. Commit-charge backpressure misfires exactly on weak machines. We triggered reclamation off CommitTotal/CommitLimit watermarks first. On the machine that needs it most this never fires: weak machines carry oversized page files because their RAM is small (8 GiB RAM + 28 GiB page file here → ~36 GiB commit limit), so the workload pages itself to a standstill at 28 % of the limit while the watermark sits silent. What actually predicts thrash is physical pressure — GlobalMemoryStatusEx ullAvailPhys against ullTotalPhys with the same high/low hysteresis shape (0.85/0.80 worked as a starting point). After switching the trigger, system commit went from a runaway 10.2 GiB (0.1 fps, 23 s/frame) to a flat 5.0 GiB plateau with stable frame times in the same workload. The process-cap failures you cite rhyme with this: caps measured against the wrong quantity either refuse legitimately-required pages or never engage.

2. The churn metric that tells you whether reclamation is helping. Track what fraction of reclaimed resources are re-created "soon" after reclaim. In our menu/loading phase the ratio was ~100 % — everything reclaimed was needed again immediately, so reclamation was pure bandwidth cost with zero sustained savings. If your idle-staging reclaim shows a similar ratio during world-load, the working set genuinely exceeds capacity and the lever has to be reducing what gets staged (serializing loaders, as the triage comment proposes) rather than faster reclaim. The ratio is cheap to instrument and separates "reclaim works" from "reclaim churns" in one number.

3. Idle-grace ordering matters. Resources need an idle timeout before they're reclaim-eligible, but the pressure path will dig past it into recently-used ones when the over-amount is large — which under never-relieving pressure is every frame. Ordering strictly LRU and protecting only fence-pinned work made the difference between stable-churn and death-spiral for us.

Notes with implementation detail: xbox-weak-hw-notes (EVICTION-PHYSICAL-PRESSURE.md and neighbors). Happy to share raw measurements if useful.

<!-- greyfinch-sync:ivall/xcl:comment:7351944617 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2639#issuecomment-7351944617). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-12-02T16:26:15Z. --- Field measurements from a sister translation layer (D3D12-based, copy-architecture shadow memory) fighting the same world-load memory wall on genuinely weak hardware (8 GiB RAM / 2 GiB VRAM), in case the signals transfer: **1. Commit-charge backpressure misfires exactly on weak machines.** We triggered reclamation off `CommitTotal/CommitLimit` watermarks first. On the machine that needs it most this never fires: weak machines carry oversized page files *because* their RAM is small (8 GiB RAM + 28 GiB page file here → ~36 GiB commit limit), so the workload pages itself to a standstill at 28 % of the limit while the watermark sits silent. What actually predicts thrash is **physical** pressure — `GlobalMemoryStatusEx` `ullAvailPhys` against `ullTotalPhys` with the same high/low hysteresis shape (0.85/0.80 worked as a starting point). After switching the trigger, system commit went from a runaway 10.2 GiB (0.1 fps, 23 s/frame) to a flat 5.0 GiB plateau with stable frame times in the same workload. The process-cap failures you cite rhyme with this: caps measured against the wrong quantity either refuse legitimately-required pages or never engage. **2. The churn metric that tells you whether reclamation is helping.** Track what fraction of reclaimed resources are re-created "soon" after reclaim. In our menu/loading phase the ratio was ~100 % — everything reclaimed was needed again immediately, so reclamation was pure bandwidth cost with zero sustained savings. If your idle-staging reclaim shows a similar ratio during world-load, the working set genuinely exceeds capacity and the lever has to be reducing what gets staged (serializing loaders, as the triage comment proposes) rather than faster reclaim. The ratio is cheap to instrument and separates "reclaim works" from "reclaim churns" in one number. **3. Idle-grace ordering matters.** Resources need an idle timeout before they're reclaim-eligible, but the pressure path will dig past it into recently-used ones when the over-amount is large — which under never-relieving pressure is every frame. Ordering strictly LRU and protecting only fence-pinned work made the difference between stable-churn and death-spiral for us. Notes with implementation detail: [xbox-weak-hw-notes](https://github.com/kotekompotek/xbox-weak-hw-notes) (EVICTION-PHYSICAL-PRESSURE.md and neighbors). Happy to share raw measurements if useful.
kotekompotek commented 2026-12-02 18:21:42 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by kotekompotek on 2026-12-02T18:21:42Z.


@razormontana Coordination welcome. One measurement trap worth knowing before you instrument the fallback path: on machines where the pagefile inflates the commit limit (our 8 GB test host shows a ~36 GB limit), any watermark keyed to commit charge will never fire while physical RAM thrashes. If your detiling measurements include memory-pressure behavior, capture both GlobalMemoryStatusEx physical availability and commit charge — the divergence between them is itself a useful metric. Our eviction data: pressure watermarks keyed to physical memory cut commit from 10.5 GB runaway to a flat 5 GB in menus, at the cost of high remake churn (83/86 remade soon) when the idle-grace window is too short for the working set. Happy to test your branch on the 8 GB host when you have one — a weak-memory machine is exactly the environment where fallback allocation behavior is decisive.

<!-- greyfinch-sync:ivall/xcl:comment:7354444946 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2639#issuecomment-7354444946). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-12-02T18:21:42Z. --- @razormontana Coordination welcome. One measurement trap worth knowing before you instrument the fallback path: on machines where the pagefile inflates the commit limit (our 8 GB test host shows a ~36 GB limit), any watermark keyed to commit charge will never fire while physical RAM thrashes. If your detiling measurements include memory-pressure behavior, capture both `GlobalMemoryStatusEx` physical availability and commit charge — the divergence between them is itself a useful metric. Our eviction data: pressure watermarks keyed to physical memory cut commit from 10.5 GB runaway to a flat 5 GB in menus, at the cost of high remake churn (83/86 remade soon) when the idle-grace window is too short for the working set. Happy to test your branch on the 8 GB host when you have one — a weak-memory machine is exactly the environment where fallback allocation behavior is decisive.
kotekompotek commented 2026-12-02 21:31:17 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by kotekompotek on 2026-12-02T21:31:17Z.


Follow-up measurements from the weak-host trench (8 GiB RAM / 2 GiB VRAM, D3D12 translation layer), now with a full device-death cascade captured twice:

Driver memory is a third domain, invisible to both watermarks under discussion. At the moment of death the process showed working set 1.5 GiB and commit 7.5 GiB of 40 — healthy by physical and commit accounting. Yet the driver was out of memory: pipeline creation failing E_OUTOFMEMORY, then root-signature creation failing, then DXGI_ERROR_DEVICE_RESET. The only user-mode-visible signal was DXGI QueryVideoMemoryInfo (in use climbing to 91% of budget). Any reclamation design that wants to survive small-VRAM hosts needs that DXGI ratio as a third input — it's cheap (one call/sec) and it's the only counter that leads the failure instead of lagging it.

Eviction lost the race even when it fired correctly. The layer evicts texture copies under budget pressure and we watched it sweep in the final minutes — but stream-in demand outran it because there was no admission control: new textures and pipeline compiles (4-5 s each, driver-side) kept being admitted right up to the wall. Watermark-triggered admission throttling on the producer side may matter as much as reclamation speed on the consumer side.

Full writeup with log excerpts: github.com/kotekompotek/xbox-weak-hw-notes (HYDRA-DEATH-CASCADE.md, BAR-INVERSION-FINDING.md — the second one is about a placement heuristic that backfires when the card is smaller than shared memory, possibly relevant if xcl ever places resources by memory-domain size assumptions).

<!-- greyfinch-sync:ivall/xcl:comment:7359396666 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2639#issuecomment-7359396666). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-12-02T21:31:17Z. --- Follow-up measurements from the weak-host trench (8 GiB RAM / 2 GiB VRAM, D3D12 translation layer), now with a full device-death cascade captured twice: **Driver memory is a third domain, invisible to both watermarks under discussion.** At the moment of death the process showed working set 1.5 GiB and commit 7.5 GiB of 40 — healthy by physical *and* commit accounting. Yet the driver was out of memory: pipeline creation failing `E_OUTOFMEMORY`, then root-signature creation failing, then `DXGI_ERROR_DEVICE_RESET`. The only user-mode-visible signal was DXGI `QueryVideoMemoryInfo` (`in use` climbing to 91% of `budget`). Any reclamation design that wants to survive small-VRAM hosts needs that DXGI ratio as a third input — it's cheap (one call/sec) and it's the only counter that leads the failure instead of lagging it. **Eviction lost the race even when it fired correctly.** The layer evicts texture copies under budget pressure and we watched it sweep in the final minutes — but stream-in demand outran it because there was no *admission* control: new textures and pipeline compiles (4-5 s each, driver-side) kept being admitted right up to the wall. Watermark-triggered admission throttling on the producer side may matter as much as reclamation speed on the consumer side. Full writeup with log excerpts: github.com/kotekompotek/xbox-weak-hw-notes (HYDRA-DEATH-CASCADE.md, BAR-INVERSION-FINDING.md — the second one is about a placement heuristic that backfires when the card is smaller than shared memory, possibly relevant if xcl ever places resources by memory-domain size assumptions).
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl#2629
No description provided.