XMem: recycle freed physical page numbers on allocation #1935
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1935
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1935"
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?
@ashrafsdrop on GitHub · 2026-11-25 01:12 UTC · original
ashrafsdrop:mem/physical-page-recycling-036→main· +91 −9 · 1 files · 1 commits · openResolves VIC-BT-036 from #1249:
Summary
In \crates/victory-hle/src/modules/xmem.rs, physical page allocation previously grew \physical.next_page\ monotonically by \
umber >> 4).
\ contiguous frames are prioritized from \physical.free\ before expanding \physical.next_page.
Added unit test \physical_pages_recycles_freed_page_numbers\ verifying single and multi-page recycling and matching reuse of page identifiers.
Verification
286fa25859to935eff925f@AgneyaK on GitHub · 2026-11-25 02:19 UTC · original
Tested
01cc8c7merged ontomain940d32f(clean), Windows 11 26300, Rust 1.98.1 MSVC. The new test is flaky in a full run:cargo test -p victory-hle --lib --lockedmain940d32f143 passedmain+ this PRphysical_pages_recycles_freed_page_numbersFAILED, 5 ×144 passedThe failure:
Why: the page table (
physical()) is process-global, and the otherxmemtests (allocate(..)/XMemFreePhysicalPagesaround lines 1349–1435) allocate and free physical pages on other test threads at the same time. Their frees land inphysical.free, and the first-fit search then picks their numbers, or they take this test's freed numbers first. So the exact-number assertions (one == original[1],new_pages == original) only hold when no other test runs in between.Suggestion: move the run search and the free/trim logic into methods on
Physical(e.g.fn take(&mut self, n) -> usizeandfn give_back(&mut self, number)), and test them on a freshPhysical::default(). That makes the test deterministic and keeps the global path as it is. Alternatively, a lock that every test touching physical pages takes. Asserting "a subset of the freed numbers" would still race.The change itself reads right to me: the run search only takes
ncontiguous numbers, and trimming the high-water mark keepsnext_pagelow. I didn't find another table keyed by the page number that a reuse would confuse; views keep their ownSliceandArc<Section>.Not tested: the title.
AI use: Claude Code (Claude Opus 5.5) ran these checks and wrote this; the results are from the runs described.
@Marvisak on GitHub · 2026-11-25 08:19 UTC · original · edited 2026-11-26 07:20 UTC
Automated triage for the maintainers.
Merge candidate. Rebased with the same content as before. In
crates/victory-hle/src/modules/xmem.rs:XMemAllocatePhysicalPagesgets its numbers fromPhysical::take, which reuses a freed contiguous run (inFRAMESsteps) before advancingnext_page.XMemFreePhysicalPagesgives back only numbers that were allocated.give_backtrims trailing numbers back down tonext_page.The test uses a local
Physical, so it doesn't race the other xmem tests.CI: passing.
Generated by Claude Code
@ashrafsdrop on GitHub · 2026-11-25 10:40 UTC · original
Thanks @AgneyaK and @Marvisak for the spot-on review and diagnosis of the test concurrency race.
Updated in commit \85565c3:
**Encapsulated Allocation and Recycling on \Physical**:
\ contiguous frames before falling back to \self.next_page.
umber\ in \self.free\ and trims trailing high-water pages contiguous with \self.next_page.
Deterministic Isolated Unit Test:
Rebased on Main:
940d32f) picking up the GPU-less CI test skip.@catminou4 on GitHub · 2026-11-25 02:10 UTC · original · reviewed
Static review only: victory-hle is Windows-only — nothing compiles or runs on macOS; source review of the diff.
XMem: recycle freed physical page numbers on allocation: PFN recycling in the memory manager — memory-pressure fix.
@fuzeofficlal on GitHub · 2026-11-26 12:39 UTC · original · approved these changes
Reviewed and verified at head
935eff92againstorigin/main(63bcca43) on Windows 11 (debug &--release):Physical::takeandPhysical::give_back(crates/victory-hle/src/modules/xmem.rs:409-455) cleanly encapsulate contiguousFRAMES-stepped (16) PFN run recycling and trailing high-water reclamation back to the base0x10_0000(never underflowing or returning page0).XMemFreePhysicalPages(xmem.rs:610-612) callsgive_backonly whenphysical.pages.remove(&number).is_some(), keepingfreeandpagesstrictly disjoint and safely ignoring double-frees, page0, and unknown/unaligned numbers. Mapped views (views/shown) are keyed bySlice::key(Arc<Section>+ slice index) rather than page numbers, so recycled PFNs cannot collide with still-mapped older sections, and all physical-page state remains serialized underPHYSICAL.physical_pages_recycles_freed_page_numbers(xmem.rs:1373-1395) operates on a localPhysical, avoiding cross-test flakiness.Physical::takescansself.freeinO(|free|)when searching for a contiguous run under fragmentation; fine for typical streaming workloads.git merge-treeagainstorigin/main(63bcca43);cargo xtask policy(191 files ok);cargo clippy -p victory-hle --all-targets --locked -- -D warningsclean with default features and--all-features.cargo test -p victory-hle --locked: 3/3 consecutive parallel dev runs passed (153 unit + 2 integrationeach) and--releasepassed (153 unit + 2 integration).XMemAllocatePhysicalPages/XMemFreePhysicalPagesin--releasewith 8 threads x 80 iterations of concurrent multi-page allocation + partial free + full free plus isolated double-free/bogus-page checks: zero duplicate live PFNs, all PFNs aligned toFRAMESand>= 0x10_0000, andnext_pageretracted cleanly back to0x10_0000.LGTM.
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.