xmem, d3d12: cut write-watch rearm, scan-run, and arena slab overhead #475

Merged
DrArroway merged 1 commit from upstream-pr/475 into main 2026-11-29 14:38:15 +00:00
DrArroway commented 2026-11-29 13:21:42 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-11-29T13:21:42Z.


Summary

Reduces placement write-watch scan, rearm, and arena allocation overhead in xmem and d3d12:

  1. Skip unchanged UNTRACKED rearms & keep unheld pages of untracked watches off the scan list:
    • Cache the last rearm reason in d3d12's Watch and skip redundant TuxBoxRearmPhysicalWatch FFI calls when the cell is unchanged (UNTRACKED without WRITTEN) for HELD, SECTION, or UNBACKED. XMem already sets WRITTEN whenever backing/hold state changes (and wakes !handle.tracked handles in watch_held_pages(1)). On #464 default section-backed main (see #472), this skips tens of millions of redundant SECTION rearm calls per run.
    • Track per-handle watchability (Handle.tracked) in XMem and only list targets for tokens that belong to at least one tracked handle (two-pass Pool::rearm and Tracking::detach cleanup).
  2. 16 MiB PrivateArena slabs, per-page arena holds, and held-gap scan guard:
    • Sub-allocate unbacked GPU-only page arenas from 16 MiB (256 * 64 KiB) ArenaSlabs, recycling free slabs (Arc::strong_count == 1, zeroing recycled slots, pruning excess idle slabs) and tracking holds per arena page (pinned_arena_pages / arena_page_has_hold).
    • Refuse bridging GetWriteWatch(RESET) runs across gaps containing import_views or import_arenas pages when held_watch != Some(true), preventing write-watch resets on active RADV userptr pages during scans.
  3. 4 MiB chunked PrivateSpan placeholder reservations:
    • Reserve aligned 4 MiB (64 * 64 KiB) placeholder chunks per PrivateSpan (reserve_private_range + on-demand commit_private_range_protect) bounded by the reservation and existing spans/deferred unmaps, so sparse 64 KiB mappings share one OS allocation and write-watch VMA.
  4. Scan & span diagnostics (TUXBOX_TRACE_XMEM_BACKING=1):
    • Report slabs= and a separate scan stats line (runs=(span= arena= own=), spans=, targets=, 5 s lock/rebuild/gww/dirty counters; zero overhead when unset).

Tested

  • Unit & hygiene checks (GE-Proton11-14 Wine):
    • tests.test_repository_hygiene: 7/7 pass.
    • tuxbox-xmem: 29/29 pass (including 4 new tests covering untracked unheld pages, held-gap scan guard, arena slabs, and chunked PrivateSpan scans, plus #464 section-backing tests).
    • tuxbox-d3d12 device::placement: 92/92 pass (including unchanged_untracked_textures_skip_redundant_rearms).
  • AMD RX 6900 XT (1002:73bf, RADV, Mesa 26.3.1, GE-Proton11-14) — tuxbox.py check:
    • All 11 steps pass: 123/123 Lanes & fixtures, 22/22 D3D12 regression controls, shader translator on GPU, all CPU/CI suites.
  • AMD Raphael Radeon 610M (1002:164e, RADV, Mesa 26.3.1, GE-Proton11-14) — tuxbox.py check:
    • All 11 steps pass: 122/122 Lanes & fixtures, 22/22 D3D12 regression controls, shader translator on GPU, all CPU/CI suites.
  • Live ProjectScarlett (3840x2160, offline, RX 6900 XT, RADV, Mesa 26.3.1, GE-Proton11-14):
    • TUXBOX_XMEM_PRIVATE_VIEWS=1 (with #462): PrivateSpan VMAs dropped from ~97,290 to 4,449 (22x fewer), GetWriteWatch runs/scan dropped from 4,258 to 369 (11.5x fewer), placement scan dropped from 12.7 ms to 9.79 ms/scan, live_arenas dropped from 3,137 (1,170 MiB) to 36 slabs (576 MiB), unaccounted (rearm/etc.) dropped from 19.0% to 12.6% of wall time, zero GPU faults or ERROR_BUSY.
    • Default #464 section-backed main (6e2c5dab combined with the parallel placement digest PR): ran 17+ minutes (74 3D world windows) with zero crashes or GPU faults, skipping 27.2M redundant SECTION rearms (placement scan 0.9% of wall time).
  • AMD and NVIDIA: AMD tested (1002:73bf and 1002:164e); NVIDIA still needs to run checks.

Checks

No evidence JSON changed.

<!-- greyfinch-sync:brcly/TuxBox:issue:5551119278 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/475). Originally posted by [DrArroway](https://github.com/DrArroway) on 2026-11-29T13:21:42Z. --- ## Summary Reduces placement write-watch scan, rearm, and arena allocation overhead in `xmem` and `d3d12`: 1. **Skip unchanged `UNTRACKED` rearms & keep unheld pages of untracked watches off the scan list:** - Cache the last rearm reason in `d3d12`'s `Watch` and skip redundant `TuxBoxRearmPhysicalWatch` FFI calls when the cell is unchanged (`UNTRACKED` without `WRITTEN`) for `HELD`, `SECTION`, or `UNBACKED`. XMem already sets `WRITTEN` whenever backing/hold state changes (and wakes `!handle.tracked` handles in `watch_held_pages(1)`). On `#464` default section-backed `main` (see #472), this skips tens of millions of redundant `SECTION` rearm calls per run. - Track per-handle watchability (`Handle.tracked`) in XMem and only list targets for tokens that belong to at least one tracked handle (two-pass `Pool::rearm` and `Tracking::detach` cleanup). 2. **16 MiB `PrivateArena` slabs, per-page arena holds, and held-gap scan guard:** - Sub-allocate unbacked GPU-only page arenas from 16 MiB (`256 * 64 KiB`) `ArenaSlab`s, recycling free slabs (`Arc::strong_count == 1`, zeroing recycled slots, pruning excess idle slabs) and tracking holds per arena page (`pinned_arena_pages` / `arena_page_has_hold`). - Refuse bridging `GetWriteWatch(RESET)` runs across gaps containing `import_views` or `import_arenas` pages when `held_watch != Some(true)`, preventing write-watch resets on active RADV userptr pages during scans. 3. **4 MiB chunked `PrivateSpan` placeholder reservations:** - Reserve aligned `4 MiB` (`64 * 64 KiB`) placeholder chunks per `PrivateSpan` (`reserve_private_range` + on-demand `commit_private_range_protect`) bounded by the reservation and existing spans/deferred unmaps, so sparse 64 KiB mappings share one OS allocation and write-watch VMA. 4. **Scan & span diagnostics (`TUXBOX_TRACE_XMEM_BACKING=1`):** - Report `slabs=` and a separate `scan stats` line (`runs=(span= arena= own=)`, `spans=`, `targets=`, 5 s `lock`/`rebuild`/`gww`/`dirty` counters; zero overhead when unset). ## Tested - **Unit & hygiene checks (`GE-Proton11-14` Wine):** - `tests.test_repository_hygiene`: `7/7` pass. - `tuxbox-xmem`: `29/29` pass (including 4 new tests covering untracked unheld pages, held-gap scan guard, arena slabs, and chunked `PrivateSpan` scans, plus `#464` section-backing tests). - `tuxbox-d3d12 device::placement`: `92/92` pass (including `unchanged_untracked_textures_skip_redundant_rearms`). - **AMD RX 6900 XT (`1002:73bf`, RADV, Mesa 26.3.1, GE-Proton11-14) — `tuxbox.py check`:** - All 11 steps pass: `123/123` Lanes & fixtures, `22/22` D3D12 regression controls, shader translator on GPU, all CPU/CI suites. - **AMD Raphael Radeon 610M (`1002:164e`, RADV, Mesa 26.3.1, GE-Proton11-14) — `tuxbox.py check`:** - All 11 steps pass: `122/122` Lanes & fixtures, `22/22` D3D12 regression controls, shader translator on GPU, all CPU/CI suites. - **Live ProjectScarlett (3840x2160, offline, RX 6900 XT, RADV, Mesa 26.3.1, GE-Proton11-14):** - `TUXBOX_XMEM_PRIVATE_VIEWS=1` (with `#462`): `PrivateSpan` VMAs dropped from `~97,290` to `4,449` (22x fewer), `GetWriteWatch` runs/scan dropped from `4,258` to `369` (11.5x fewer), `placement scan` dropped from `12.7 ms` to `9.79 ms/scan`, `live_arenas` dropped from `3,137` (`1,170 MiB`) to `36` slabs (`576 MiB`), `unaccounted` (rearm/etc.) dropped from `19.0%` to `12.6%` of wall time, zero GPU faults or `ERROR_BUSY`. - Default `#464` section-backed `main` (`6e2c5dab` combined with the parallel placement digest PR): ran 17+ minutes (`74` 3D world windows) with zero crashes or GPU faults, skipping `27.2M` redundant `SECTION` rearms (`placement scan` `0.9%` of wall time). - **AMD and NVIDIA:** AMD tested (`1002:73bf` and `1002:164e`); NVIDIA still needs to run checks. ## Checks No evidence JSON changed.
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
brcly/TuxBox!475
No description provided.