kernelx: XMemVirtualAlloc reads its 4th argument as a flags word #3173
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3173"
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 ivall/xcl. Originally posted by KOLESNiii on 2026-11-28T15:54:16Z.
Status: a guess that needs evidence before it can be merged. Reading XMemVirtualAlloc's 4th argument as a flags word is reasoned from how titles call the API and from the PC's D3D12; it is not taken from any console documentation, and no title has confirmed it yet. Draft until then.
Evidence that would confirm it:
XCL_TRACE_MEM=1logs every call's decoded flags with its result; titles' words and what they then do with the memory settle the meaning of each bit. No bit is acted on yet (see below).If you run a title that gets there, please post those lines here (not the whole log, which names your paths).
XMemVirtualAlloc's 4th argument looks like a flags word, not an allocator's XALLOC_ATTRIBUTES. This PR decodes it as flags, for a trace and for a log of the address limits it can ask for. It changes no allocation:main's routing is kept as it is (the XAllocAttrs decode: MEM_GRAPHICS from a graphics memory type in bits 29–32, 0x8000_0000 for a page-size field of 2; the test title's check that a graphics memory type lands in UMA depends on it), andtypeandprotectotherwise go toVirtualAllocas given. Placing memory below an address limit is left to a second PR.Why the flags are not acted on: an earlier revision (
1664d4bb) added MEM_GRAPHICS on bit 0x2. The retail game sets it on its big committed large-page heaps (about 4.6 GB), which then went to the sparse VRAM pool instead of the coherent window: 640, 705 and 707 frames againstmain's 1297, 1259 and 1316, at about +9.5 GB peak commit (see the comments). A later revision (c5aff7ad) removedmain's attribute routing instead, which broke the test title's UMA check. Whether a console title's graphics bit should make memory GPU-visible needs a design for where such heaps go; it is not done here.What the retail game asks for: in the regression run below it makes one address-limited request, flags 0x7 (CPU, graphics, below 4 GiB) for 0xb900000 bytes, and gets 0x44c610000, above the limit (
mem: XMemVirtualAlloc asks for an address below 0x100000000 (flags 0x7): 0x44c610000 + 0xb900000 is above it: not placed yet). It runs regardless; whether it depends on that memory being low is not known.What is in it
crates/xcl/src/hle/kernelx.rsVirtualAllocFlags:limit()gives the first address the memory must stay below.trace_virtual_alloc_flags: logs every call, decoded, underXCL_TRACE_MEM; logs one line per run, unconditionally, for the first request with an address limit, with whether the returned address fits.XMemVirtualAlloc: the allocation as onmain, then the trace.README.md:XCL_TRACE_MEMalso logs eachXMemVirtualAlloccall's decoded flags.Tested
cargo test --workspace --no-fail-fast -- --test-threads=4on599bf81a(built onmain10d27297; it merges into the currentmain7db2f391without conflict): 2155 passed, 0 failed, 48 ignored, 25SKIPPEDlines (21 no wave64, 3 #1426, 1 no heap windows). The e2e test title tests pass, including its graphics-memory-in-UMA check.kernelx::tests, ok in that run:virtual_alloc_flags_decode;virtual_alloc_graphics_flag_keeps_the_type: a committed heap with word 0x283 is not in the GPU-visible pool (fails on1664d4bb);virtual_alloc_preserves_legacy_graphics_routing: a word with memory type bit 29 lands in UMA, as onmain(the test title's check of the same thing failed onc5aff7ad).Regression run
Both 60-second runs started from copies of the same DXIL cache, with
XCL_PREPARE=0andXCL_PRESS_AT=25:A.The
mainrun is on a newermainthan the PR's base (10d27297).Not tested
maindoes).XCL_PREPARE=0.AI use
1664d4bbregression to the graphics bit.main's routing in599bf81a, addedvirtual_alloc_preserves_legacy_graphics_routing, and ran the suite on this head.🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-28T16:27:53Z.
Regression run on this head fails the merge gate (RTX 2070 SUPER, the retail game, 60 s,
XCL_PRESS_AT=25:A,XCL_PREPARE=0, release builds, same starting DXIL cache):main309c3ec51664d4bbThe gate is at least 80 % of
main's frames and at most 125 % of its peak commit. One run only, but the size of both changes makes noise unlikely.Likely cause, from the diff (not yet confirmed by a trace):
mainmakes anXMemVirtualAllocGPU-visible (MEM_GRAPHICS) when the 4th argument decodes as an allocator attribute with a graphics memory type, and adds0x8000_0000for its 2 MiB page size. This head makes it GPU-visible only on bit0x2of a flags word and drops the large-page bit. So the retail game's allocations land in a different pool with different pages. The run logged one address-limited request (flags0x7,0xb900000bytes at0x4f2e00000: above 4 GiB, not placed).I have stopped work on this PR until the author decides how to go on.
Rerun (same settings, interleaved main / this head / main / this head in one queue job; CPU load 2–3 % and no build processes at the start and end of every run, so not background load):
main309c3ec5(a)1664d4bb(a)main309c3ec5(b)1664d4bb(b)The regression reproduces: about 55 % of
main's frames, below 60 fps even at the end, and about +9.5 GB peak commit on both runs.— Claude Code (Claude Opus 5.5), on behalf of the PR author
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-28T17:03:19Z.
Regression confirmed: on two more interleaved runs on an idle machine this head showed about 55 % of
main's frames (705 and 707 against 1259 and 1316) and about +9.5 GB peak commit (numbers in the comment above). Not merge-ready as it stands.The author is now investigating exactly why it is slower: which of the title's
XMemVirtualAlloccalls decode differently under the flags-word reading than undermain's allocator-attribute reading, and whether the cost comes from the pool they land in (GPU-visible or not), from losing the large-page bit, or from the 4 GiB-limited request placed above its limit. The findings and a fix will be posted here; the PR stays a draft until then.— Claude Code (Claude Opus 5.5), on behalf of the PR author
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-28T17:39:59Z.
Cause found and fixed in
c5aff7ad. Undermain's decode every word the retail game passes has memory type 0, so onmainXMemVirtualAllocis a plainVirtualAllocfor it. The earlier head added MEM_GRAPHICS on the flags' bit 0x2, which the game sets on its big committed large-page heaps (about 4.6 GB). They went to the sparse VRAM pool instead of the coherent window; video memory went over budget (10.8 GB against 6.8), and a 6 GB physical-page allocation found no room in unified memory and went to plain write-watched memory, where each look scanned 5.8 GB instead of 1.7. The 4 GiB-limited request and the large-page bit were ruled out.c5aff7addecodes the flags for the trace and the address-limit log only and passestype/protecttoVirtualAllocas given. A new test checks a committed heap with word 0x283 stays out of the GPU-visible pool; it fails on1664d4bb. The suite and a new regression pair againstmainare queued; the results will go into the description.— Claude Code (Claude Opus 5.5), on behalf of the PR author
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-30T17:32:53Z.
Additional call-site evidence supports keeping these arguments separate: Microsoft’s Xbox GDK FSR3 sample builds the third
XMemVirtualAllocargument fromMEM_RESERVE | pageSizeFlag(usingMEM_2MB_PAGESorMEM_64K_PAGES) and passesXMEM_GRAPHICS | XMEM_MAPPABLEseparately as the fourth argument.This sample supports treating the page-size/type and flags arguments as distinct contracts. It does not establish the numeric
XALLOC_ATTRIBUTES.PageSizemapping forXMemAllocDefault, so the evidence gap on #3092 remains.AI-assisted.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:40:51Z.
Triage (#1607) – head
599bf81#3353 is stacked on this PR (it carries this commit
599bf81aplus its own address-limit counter), so it is not a duplicate.The title says the 4th argument is read as a flags word, but
XMemVirtualAllocstill routes onXAllocAttrs::decode(flags);VirtualAllocFlagsis only used for the trace, as the description says.virtual_alloc_graphics_flag_keeps_the_typealso passes onmain(routing unchanged), so it is a regression guard rather than a test of a fix. The comment ontrace_virtual_alloc_flagsrefers to a "PR 2" that does not exist yet.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-12-02T14:59:07Z.
Thanks @thehollowedone for the call-site evidence, and @Foniass for the triage. The comment on
trace_virtual_alloc_flagsno longer mentions a "PR 2" (it now says nothing places requests under the limit yet). New head11c0e219(rebased ontomaindf0cfef6). Agreed thatvirtual_alloc_graphics_flag_keeps_the_typeis a regression guard, since routing does not change here.— Claude Code (Claude Opus 5.5), on behalf of the PR author
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T15:00:03Z.
Follow-up review (head
11c0e219, since599bf81, diff read, not a merge-check; checks red):XAllocAttrs::decode: partly fixed; the commit subject now sayskernelx: trace XMemVirtualAlloc flags without changing routing, which matches the code, but the PR title still says "reads its 4th argument as a flags word".virtual_alloc_graphics_flag_keeps_the_typepasses onmain: unchanged; it is a regression guard, as before.New: none. #3353 is stacked on the old commit
599bf81aand will need the same rebase.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.