XMem: coalesce split placeholders before retrying a mapping #1058
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1060"
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 fxceless/victory-fork. Originally posted by gmankab on 2026-11-25T17:52:42Z.
This fixes a physical-page mapping case relevant to the measured streaming remap bottleneck. After two adjacent one-page views are unmapped, Windows leaves two placeholders. The runtime may then request one view of consecutive physical pages across both slots. The replacement requires a single placeholder with the same address and size.
A small Wine probe reproduced the failure with the split placeholders. After explicitly coalescing them, the same two-page mapping succeeded and both bytes read back correctly. The patch retries a failed multi-page replacement only after coalescing the exact range. The runtime regression exercises
XMemMapPhysicalPageswith two distinct byte values.All 12
xmemtests passed. The patch covers correctness of this remap sequence. The impact on in-game streaming times is still unmeasured.Microsoft's placeholder requirements for MapViewOfFile3
Tested-on: Fedora Linux 45 x86_64, Wine in the Victory Flatpak, DRM devices hidden
Assisted-by: gpt-6.2 sol xhigh
Imported from fxceless/victory-fork. Originally posted by DoubleD17 on 2026-11-25T20:25:37Z.
Review: COMMENTED
Independent native Windows x64 check of the placeholder-remap sequence in
875aad664052b852ce54731b1dbe64cd50ca2381(build 26300, AMD Ryzen 7 5800X). In a standalone fixture I mapped and committed two 64 KiB views of a pagefile-backed section, then unmapped both withMEM_PRESERVE_PLACEHOLDER. A third adjacent view stayed mapped. Retry path at this SHAThe initial split request across the two existing placeholders failed with Win32 error 87. The first 128 KiB
MapViewOfFile3replacement failed with error 487. Coalescing exactly those two placeholders and retrying then mapped at the requested address. Readback gave the expected marker bytes1and42from the two slots, and the neighboring view still read its original marker90.This adds coverage on native Windows for the API sequence. The standalone fixture exercised the Windows calls and did not execute the PR's HLE or measure streaming performance.
AI-assisted.
Imported from fxceless/victory-fork. Originally posted by Solarthis on 2026-11-25T20:35:06Z.
The mechanism this retry exists for, on the record, and the three things it does not fix.
A one-page remap into an N-page view asks the kernel for two things it refuses:
VirtualFree(base, PAGE, MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER)wherebaseis inside the view (the unmap acts on the whole view, and the sub-range is not itself a placeholder), thenMapViewOfFile3(…, MEM_REPLACE_PLACEHOLDER, base, PAGE, …)where the placeholder is N pages (a placeholder is replaced only at exactly its own size). Both calls fail and nothing stays mapped: a hole. A placeholder isPAGE_NOACCESS, so the CPU faults and a host-pointer import reads zeros (black); where the failure is silent the read falls through into the neighbouring page's offset (red/garbage). First one-page remap into any batched view, 3 launches of 3.Coalescing at the exact range fixes the kernel side, and #1063 needs it. What is left over is per view rather than per page:
inplace::views_gonedrops the whole view record on one page's remap;cover()falls toNone/Holes, and #606's re-upload then covers all N pages.AllocationBasemoves to the run base — #1063's own test asserts it — so anything keyed on it (census, import windows) widens to the run.The 11–13% coalesce refusals tikD1337 reports on #1063 are that same rule seen at the ends: a coalesce takes whole placeholders only, so a leftover piece of a larger view at either end refuses it. Splitting both ends first is the right fix.
Our runtime (a separate implementation of the same API surface) keeps a page state victory has not got — pending, recorded with no view. It coalesces and isolates the exact byte range before every map, and a one-page remap inside a first-use view demotes the view instead: one unmap, the survivors pending, a view again on use. View length then costs a remap nothing and the break cannot happen. Covered by a test that replays the title's own order, mid-run remap included, after which a fill lands in the run; xmem 259/259.
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.