xmem: give freed physical page numbers again #124

Manually merged
github merged 1 commit from github-bot/gh-124 into main 2026-11-26 18:09:26 +00:00 AGit
Owner

@⁠Olima34 on GitHub · 2026-11-26 17:33 UTC · original
Olima34:fix/xmem-page-number-free-list → main · +91 −23 · 2 files · 1 commits · merged 2026-11-26 18:09 UTC

The page-number free list from #15 (your point 2 there), small and tested, like #108.

Why. XMemAllocatePhysicalPages handed out page numbers that only grew, and XMemFreePhysicalPages gave none back. The title keeps them in 25 bits (number_kept, #111). So after about 128 GiB allocated since start-up, a live number came back as another page's.

What.

  • Freed numbers go to a free list and are given again lowest first, before new ones (Physical::number). This keeps numbers as low as the pages alive at once allow.
  • A number whose page a view still shows is pinned (Physical::pinned, keyed by its slice). It becomes free only once the last view showing that page is unmapped (unmap, checked after the Windows re-maps). So a mapped number never reaches two pages.
  • Scatter batching (map_fresh_scatter) no longer requires consecutive numbers: freed numbers come back in any order. It already checks that the pages are consecutive slices of one pool, which is what the batch needs.

Test. freed_page_numbers_are_given_again_once_unmapped, on its own Physical, since other tests allocate concurrently:

  • freed numbers come back lowest first;
  • a freed number that is still mapped is not given again;
  • once unmapped, it is.
    It fails without the free list.

victory-hle tests (macOS x86_64, 246), Windows clippy and cargo xtask policy pass. Not checked in game.

**@⁠Olima34** on GitHub · 2026-11-26 17:33 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/124) `Olima34:fix/xmem-page-number-free-list` → `main` · +91 −23 · 2 files · 1 commits · merged 2026-11-26 18:09 UTC The page-number free list from #15 (your point 2 there), small and tested, like #108. **Why.** `XMemAllocatePhysicalPages` handed out page numbers that only grew, and `XMemFreePhysicalPages` gave none back. The title keeps them in 25 bits (`number_kept`, #111). So after about 128 GiB allocated since start-up, a live number came back as another page's. **What.** - Freed numbers go to a free list and are given again lowest first, before new ones (`Physical::number`). This keeps numbers as low as the pages alive at once allow. - A number whose page a view still shows is pinned (`Physical::pinned`, keyed by its slice). It becomes free only once the last view showing that page is unmapped (`unmap`, checked after the Windows re-maps). So a mapped number never reaches two pages. - Scatter batching (`map_fresh_scatter`) no longer requires consecutive numbers: freed numbers come back in any order. It already checks that the pages are consecutive slices of one pool, which is what the batch needs. **Test.** `freed_page_numbers_are_given_again_once_unmapped`, on its own `Physical`, since other tests allocate concurrently: - freed numbers come back lowest first; - a freed number that is still mapped is not given again; - once unmapped, it is. It fails without the free list. victory-hle tests (macOS x86_64, 246), Windows clippy and `cargo xtask policy` pass. Not checked in game.
XMemAllocatePhysicalPages handed out numbers that only grew, and
XMemFreePhysicalPages gave none back. Grand Theft Auto VI keeps them in
25 bits, so past about 128 GiB allocated since start-up a live number
was rebuilt as another page's (issue #15).

Freed numbers now go to a free list, taken lowest first before new
ones. A number whose page a view still shows waits until the last such
view is unmapped, so a mapped number never reaches two pages.

Scatter batching no longer asks for consecutive numbers: it already
checks that the pages are consecutive slices of one pool.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 17:37:37 +00:00
github manually merged commit b2ce7e7a87 into main 2026-11-26 18:09:26 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 18:09 UTC · original

Merged, thanks. This is the page-number free list from #15.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 18:09 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/124#issuecomment-7200128515) Merged, thanks. This is the page-number free list from #15.
This discussion has been locked. Commenting is limited to contributors.
No description provided.