hle: skip redundant VirtualAlloc commit and VirtualFree placeholder split in xmem::map #1100

Open
DoktorTK wants to merge 2 commits from upstream-pr/1103 into main
DoktorTK commented 2026-11-25 19:31:19 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by DoktorTK on 2026-11-25T19:31:19Z.


Avoids two redundant Windows kernel syscalls per remapped page during CopyPageMappingsBatchX -> xmem::map_alias:

  1. Skip redundant VirtualAlloc(..., MEM_COMMIT) (11ae5b5): Tracks committed section pages (Arc::as_ptr(&slice.section), slice.index + k) inside Physical so xmem::map only commits a backing section page on its first mapping, and cleans up keys when XMemFreePhysicalPages frees pages.
  2. Skip redundant VirtualFree(..., MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER) (c95adbb): Tracks exact unsplit placeholders (at, size) returned by UnmapViewOfFile2(..., MEM_PRESERVE_PLACEHOLDER) in unmap so xmem::map skips splitting a placeholder that already matches base..base + len.

Verified with cargo test --release -p victory-hle (all 99 tests pass).

<!-- greyfinch-sync:fxceless/victory-fork:issue:6612124740 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1103). Originally posted by [DoktorTK](https://github.com/DoktorTK) on 2026-11-25T19:31:19Z. --- Avoids two redundant Windows kernel syscalls per remapped page during `CopyPageMappingsBatchX -> xmem::map_alias`: 1. **Skip redundant `VirtualAlloc(..., MEM_COMMIT)` (`11ae5b5`):** Tracks committed section pages `(Arc::as_ptr(&slice.section), slice.index + k)` inside `Physical` so `xmem::map` only commits a backing section page on its first mapping, and cleans up keys when `XMemFreePhysicalPages` frees pages. 2. **Skip redundant `VirtualFree(..., MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER)` (`c95adbb`):** Tracks exact unsplit placeholders `(at, size)` returned by `UnmapViewOfFile2(..., MEM_PRESERVE_PLACEHOLDER)` in `unmap` so `xmem::map` skips splitting a placeholder that already matches `base..base + len`. Verified with `cargo test --release -p victory-hle` (all 99 tests pass).
NotADonky43 commented 2026-11-25 21:05:56 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by NotADonky43 on 2026-11-25T21:05:01Z.


Related native-Windows test result: on a separate implementation, I remapped 256 destination views between two already-committed source ranges, checking the resulting bytes. On Windows with an RTX 5070 Ti, the D3D12 validation fixture also read the expected texture bytes after remapping. This covered remaps to different backing pages, not identical mappings.

Across four interleaved trials per mode (3,072 backing changes each), a path that removed both the redundant commit and the split for an exact returned placeholder reduced median wall time from 15.43 to 12.23 ms per trial. That number is for both calls combined; it does not isolate the commit cost, validate this PR's bookkeeping, or establish a game FPS gain. Newly mapped or unknown backing still took the commit path in the tested implementation.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7174588519 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1103#issuecomment-7174588519). Originally posted by [NotADonky43](https://github.com/NotADonky43) on 2026-11-25T21:05:01Z. --- Related native-Windows test result: on a separate implementation, I remapped 256 destination views between two already-committed source ranges, checking the resulting bytes. On Windows with an RTX 5070 Ti, the D3D12 validation fixture also read the expected texture bytes after remapping. This covered remaps to different backing pages, not identical mappings. Across four interleaved trials per mode (3,072 backing changes each), a path that removed both the redundant commit and the split for an exact returned placeholder reduced median wall time from 15.43 to 12.23 ms per trial. That number is for *both* calls combined; it does not isolate the commit cost, validate this PR's bookkeeping, or establish a game FPS gain. Newly mapped or unknown backing still took the commit path in the tested implementation.
upstream-sync changed title from [PR #1103] Skip redundant VirtualAlloc MEM_COMMIT on already-committed section p… to [PR #1103] hle: skip redundant VirtualAlloc commit and VirtualFree placeholder split in xmem::map 2026-11-25 22:07:10 +00:00
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1103:upstream-pr/1103'
git switch 'upstream-pr/1103'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/1103'
git switch 'upstream-pr/1103'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1103'
git switch 'upstream-pr/1103'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1103'
git switch 'main'
git merge --squash 'upstream-pr/1103'
git switch 'main'
git merge --ff-only 'upstream-pr/1103'
git switch 'main'
git merge 'upstream-pr/1103'
git push origin 'main'
Sign in to join this conversation.
No reviewers
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
fxceless/victory-fork!1100
No description provided.