XMem: coalesce split placeholders before retrying a mapping #1060
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!1060
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@gmankab on GitHub · 2026-11-25 17:52 UTC · original
gmankab:fix/coalesce-physical-placeholders→main· +41 −14 · 1 files · 1 commits · openThis 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
@Solarthis on GitHub · 2026-11-25 20:35 UTC · original
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
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.