XMem: physical page numbers freed are given out again before they pass the title's 21 bits (#233) #316

Open
github-bot wants to merge 1 commit from github-bot/gh-316 into main AGit
Owner

@⁠illuminatedfellow on GitHub · 2026-11-26 16:13 UTC · original
illuminatedfellow:xmem/reuse-page-numbers → main · +74 −4 · 1 files · 1 commits · open

Closes #233.

XMemAllocatePhysicalPages gave page numbers from next_page, which only ever grew. The title keeps a number as 21-bit number >> 4 (FRAMES), so after about 124 GiB of allocations over a run its truncated numbers were unknown to us (XMemMapPhysicalPages returned null) or aliased live low pages.

  • Pages::take(n): numbers are still given in order while they fit (no change in normal runs). Past the limit, the lowest run of n numbers not in use (free_run) is given, with a one-time log line.
  • An allocation that finds no such run fails cleanly (count 0, the section released as on any other failure) instead of handing out a number the title cannot keep.
  • n * FRAMES and the end of the range are checked, so an absurd n cannot wrap.

Test: page_numbers_freed_are_given_again_past_the_title_s_21_bits covers the in-order path up to the limit, reuse of the lowest free run, gaps too small, a full range and the 21-bit packing. The numbering logic was also run in a standalone crate on Linux (Rust 1.97); the module's own tests run on Windows CI. Not run in the game: the limit is only reached after ~124 GiB of allocate/free churn.

Note: main's CI is currently red for reasons unrelated to this PR (see #280).

**@⁠illuminatedfellow** on GitHub · 2026-11-26 16:13 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/316) `illuminatedfellow:xmem/reuse-page-numbers` → `main` · +74 −4 · 1 files · 1 commits · open Closes #233. `XMemAllocatePhysicalPages` gave page numbers from `next_page`, which only ever grew. The title keeps a number as 21-bit `number >> 4` (`FRAMES`), so after about 124 GiB of allocations over a run its truncated numbers were unknown to us (`XMemMapPhysicalPages` returned null) or aliased live low pages. - `Pages::take(n)`: numbers are still given in order while they fit (no change in normal runs). Past the limit, the lowest run of `n` numbers not in use (`free_run`) is given, with a one-time log line. - An allocation that finds no such run fails cleanly (`count` 0, the section released as on any other failure) instead of handing out a number the title cannot keep. - `n * FRAMES` and the end of the range are checked, so an absurd `n` cannot wrap. Test: `page_numbers_freed_are_given_again_past_the_title_s_21_bits` covers the in-order path up to the limit, reuse of the lowest free run, gaps too small, a full range and the 21-bit packing. The numbering logic was also run in a standalone crate on Linux (Rust 1.97); the module's own tests run on Windows CI. Not run in the game: the limit is only reached after ~124 GiB of allocate/free churn. Note: `main`'s CI is currently red for reasons unrelated to this PR (see #280).
Page numbers only ever grew, and the title keeps them as 21-bit
`number >> 4`: past ~124 GiB of allocations over a run, a number came
back truncated, unknown to us or aliasing a live page. Numbers are still
given in order while they fit; then the lowest run of freed ones is used,
and an allocation with no such run fails (count 0) instead of handing out
a number the title cannot keep.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 16:16:48 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/316/head:github-bot/gh-316'
git switch 'github-bot/gh-316'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-316'
git switch 'github-bot/gh-316'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-316'
git switch 'github-bot/gh-316'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-316'
git switch 'main'
git merge --squash 'github-bot/gh-316'
git switch 'main'
git merge --ff-only 'github-bot/gh-316'
git switch 'main'
git merge 'github-bot/gh-316'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.