xmem: chunk contiguous private spans and hand off private backing on held-span secondary aliases #600
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/600"
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 brcly/TuxBox. Originally posted by DrArroway on 2026-11-30T21:19:20Z.
Follow-up to #501 (
TUXBOX_XMEM_PRIVATE_VIEWS=1).Problem
Pool::map_private_contiguouscommitted a contiguous private range as a singlePrivateSpanregardless of size, rather than splitting atPRIVATE_SPAN_CHUNK(64 pages = 4 MiB). When a title maps a large contiguous pool (in ProjectScarlett, a 99,776-page / 6.09 GiB pool at0xf00200000..0x1085e00000), a single GPU import hold anywhere inside that pool locks the entire span (page_imp=false, span_imp=true) and blocks secondary-alias write promotion on unrelated pages withERROR_BUSY(170).PrivateArenabackings: Even with 4 MiB chunks, a sibling page held inside the same 4 MiBPrivateSpanstill prevents detaching the canonicalPrivateViewslot (promote_token_to_sectionfails withERROR_BUSY), andBink2Scarlett.dllalso triggers secondary-alias write faults on tokens whose canonical backing is a live (sometimes import-held)PrivateArenasitting inside a held 4 MiB span.eager_promote_dual_cpu_aliasestried to promote toSharedSectioneven when the destination slot lay inside a held/deferredPrivateSpan, andclear_page_mappingleft recycledaliases == 0tokens onPageBacking::SharedSectionunder private-views mode instead of returning them toPageBacking::Unbacked.Changes
runtime/xmem/src/physical_pages/private_views.rsmap_private_contiguousatPRIVATE_SPAN_CHUNK(64 pages / 4 MiB) boundaries with upfront validation and atomic rollback viaChunkUndo, while keeping theOk(false)fallback for plain non-placeholderVirtualAllocreservations.unmap_private_view_rangewith a zero-allocation single-span fast path (unmap_single_private_span_range) plus upfront-validated multi-span contiguous unmapping.Pool::handoff_private_backing, called fromsecondary_alias_vehonErr(ERROR_BUSY)beforemirror_readonly_secondary_alias:PageBacking::PrivateView(old_va): freezesold_vatoPAGE_READONLY, copies the 64 KiB page tofault_page(PAGE_READWRITE), demotesold_vaand any stalereadonly_secondary_aliasestoPAGE_NOACCESS, transferspage.backing = PageBacking::PrivateView(fault_page), and callsself.touch(token).PageBacking::PrivateArena { arena, offset }(both unheld and import-held): copies the 64 KiB page tofault_page(PAGE_READWRITE), switchespage.backing = PageBacking::PrivateView(fault_page)(existingHoldRecord.arenaskeeps the heldArc<PrivateArena>alive), callsself.touch(token), and whenwas_held, returns the held VAs sosecondary_alias_vehdropsPOOLand callsnotify_backing_invalidated.eager_promote_dual_cpu_aliaseswhen the destination VA lies in a held/deferredPrivateSpan.SharedSectiontokens withaliases == 0back toPageBacking::Unbackedinclear_page_mappingwhen private-views mode is active.runtime/xmem/src/physical_pages.rsXMemMapPhysicalPageserrors showingat,count,unmap,err,shared_tokens,max_aliases, andspan_held.runtime/xmem/src/tests/private_views.rsPrivateViewhandoff inside a sibling-held 4 MiB span, and held-PrivateArenahandoff with invalidation notification.Verification
Evidence: TuxBox check of
6e1f2a1eb0, no uncommitted changes, GPU 1002:73bf: 17 passed, 0 failed, 0 not runEvidence: TuxBox check of
6e1f2a1eb0, no uncommitted changes, GPU 1002:164e: 17 passed, 0 failed, 0 not runtuxbox-xmemWindows unit tests under GE-Proton Wine on AMD Radeon RX 6900 XT (1002:73bf) (physical_ --test-threads=1):40 passed; 0 failed; 1 ignored(scan_cost), including all 4 newprivate_viewstests.TUXBOX_XMEM_PRIVATE_VIEWS=1checks on both GPUs — AMD Radeon RX 6900 XT (1002:73bf) and AMD Raphael Radeon 610M iGPU (1002:164e):tuxbox.py verify --only xmem:12/12PASS on AMD Radeon RX 6900 XT (1002:73bf),12/12PASS on AMD Raphael Radeon 610M iGPU (1002:164e).d3d12-buffer-import.exe(buffer-import,buffer-remap,buffer-unmap-alive,buffer-unmap-released):4/4PASS on AMD Radeon RX 6900 XT (1002:73bf),4/4PASS on AMD Raphael Radeon 610M iGPU (1002:164e).RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --target x86_64-pc-windows-msvc -p tuxbox-xmem --document-private-items,cargo clippy --locked --target x86_64-pc-windows-msvc -p tuxbox-xmem --all-targets -- -D warnings,cargo fmt --all -- --check, andtests.test_repository_hygiene(7/7): all passed.Live ProjectScarlett runs (AMD Radeon RX 6900 XT (1002:73bf), GE-Proton11-14,
TUXBOX_XMEM_PRIVATE_VIEWS=1,TUXBOX_CHECK_ONCE_PER_FRAME=1,VKD3D_CONFIG=no_upload_hvv)All 3 confirmation runs also carried open PR #389 in
d3d12_xs.dllto get past unrelated RADV GPUVM faults once inside the 3D world:490.8s, Frame 1644, 83 3D mission frames): 4 live held-PrivateArenasecondary-alias handoffs saved (0x33d2b0000,0x779640000,0x779660000,0x36ddd0000),0err=170,0XMemMapPhysicalPagesfailures,0GPUVM faults.407.7s, Frame 1269, 49 3D mission frames):0err=170,0XMemMapPhysicalPagesfailures,0GPUVM faults.213.7s, Frame 967, 16 3D mission frames): 3 live held-PrivateArenasecondary-alias handoffs saved (0x327600000,0x327670000,0x8f3120000),0err=170,0XMemMapPhysicalPagesfailures,0GPUVM faults.All 3 runs ended on the pre-existing
0x80000003breakpoint atgame_scarlett_master.exe + 0x4DA6315(seen identically on earlier runs with shared-section backing).