xmem: give freed physical page numbers again #124

Merged
Olima34 merged 1 commit from upstream-pr/124 into main 2026-11-26 18:09:23 +00:00
Olima34 commented 2026-11-26 17:33:11 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-26T17:33:11Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6632037151 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/124). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-26T17:33:11Z. --- 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.
LakshanSivakumar commented 2026-11-26 18:09:57 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T18:09:57Z.


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7200128515 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/124#issuecomment-7200128515). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T18:09:57Z. --- Merged, thanks. This is the page-number free list from #15.
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
LakshanSivakumar/Native-Victory-macOS!124
No description provided.