vkback: cache GTT room state and pace refused_slots recovery with hysteresis #188

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

@⁠deuxque on GitHub · 2026-12-02 06:25 UTC · original
deuxque:pr/gtt-refused-slot-recovery → main · +239 −32 · 4 files · 1 commits · open

Problem

On 8 GB cards (#103 RX 6650 XT 8 GB), GPU-written targets (~4.0 GB) plus umem title
VRAM (~3.0 GB) keep VRAM above its 50% line (~4,087 MiB on an 8,176 MiB budget) for the
entire session. Even after #111 fixed GTT free-arena accounting, three defects in
residency.rs / srclife.rs remained:

  1. Orphaned refused_slots (greenfield/vkback/src/residency.rs:111-120):
    refused_slots was only drained when VRAM transitioned false -> true. On 8 GB cards
    where VRAM stays over its line, slots refused during a transient GTT spike (48k-56k in
    #103 post-#111) stayed cached in slot_cache with null (black) descriptors forever even
    after let_go_idle freed GTT space and new textures spilled cleanly to Place::Gtt.
  2. Uncached over_line() on every GTT spill (greenfield/vkback/src/srclife.rs:101):
    room_for_textures() cached only VRAM room for 100 ms; every texture_place() call
    past the VRAM line fell through to uncached over_line() (2x vkGetPhysicalDeviceMemoryProperties2
    plus arena scans), costing 26 ms of 28 ms (93%) of placed image creation in #103 (d1d6f39).
  3. No resume hysteresis and unbounded burst drain (residency.rs:105-122):
    Reopening at 0 bytes without deadband and draining all of refused_slots inside a
    single 100 ms cached-open window let a large refusal backlog immediately push the heap
    back over its line.

Change

  • Replace VulkanBackend::room_at: (Instant, bool) with a pure, Vulkan-free
    residency::RoomGate (initialized open with checked_at: None) caching
    (vram_open, gtt_open) for 100 ms (invalidated by let_go_idle).
  • Add per-heap -2% resume hysteresis (next_open: closes at over >= 0, reopens once
    over <= -(budget / 50) and < 0, matching the -2% quiet threshold of let_go_from
    and handling budget == 0 safely).
  • Pace refused_slots recovery on fresh probes only (REFUSED_DRAIN_BATCH = 64 per
    100 ms TTL when either VRAM or GTT is open), keeping the cache valid for the TTL so
    retried allocations settle before the next probe and texture_place() does not regress
    to per-call over_line() queries while draining.
  • Check texture_room() in arena.rs::take_retry_slots when !self.refused_slots.is_empty()
    so an existing backlog keeps draining even when no new textures are being created.
  • Preserve room_for_textures() returning VRAM-only room (vram_open) for existing
    callers (lib.rs:3291).
  • No change to the 4 GiB VRAM floor, over_line() reserve math, umem allocation, or
    UMEM_MEMREPORT formatting.

Measurements & Tests

  • Synthetic unit tests (5 new in greenfield/vkback/src/residency.rs, no GPU required):
    • vram_permanently_over_gtt_recovers_drains_refused_slots: VRAM at +5 GiB, GTT drops
      to -3% -> returns Place::Gtt and drains 64 slots (previously 0 drained).
    • hysteresis_blocks_oscillation_between_zero_and_minus_two_pct: verifies -1% stays
      closed, -2% reopens, -1% stays open, 0 closes, and budget == 0 safety.
    • ttl_paced_bounded_drain_no_burst_and_stops_on_pressure: 200 refused slots drain
      64 -> 0 (within TTL) -> 64 -> 0 (when both heaps >= 0) with 3 total probes.
    • gtt_spill_uses_cached_line_within_ttl: 10 consecutive GTT-spill placements within
      100 ms invoke 1 probe (down from 10); invalidate() triggers probe #2.
    • vram_room_semantics_preserved: vram_open == false && gtt_open == true keeps
      VRAM room false while placing in Place::Gtt.
  • cargo test --manifest-path greenfield/Cargo.toml --workspace --no-fail-fast:
    250 passed, 6 ignored, 0 failed.
  • cargo clippy --manifest-path greenfield/Cargo.toml -p vkback --all-targets -- -D warnings:
    0 warnings.
  • cargo test --manifest-path greenfield/Cargo.toml -p vkback --test policy:
    6 passed, 0 failed (lib.rs unchanged at 4,250 non-test lines).
  • Capped tools/build.sh: exit 0 (42 s warm cache).

AI use

Model: Gemini 4 Neon, human-directed scope and design review. All unit, clippy, policy,
and build checks ran on an isolated Linux / RDNA 2 host without modifying the 4 GiB VRAM
floor or over_line() math. On-card full-title testing on an 8 GB GPU (confirming
post-#111 black-texture recovery and texture_place frame-time reduction in #103) remains
pending.

Refs #103 #111

**@⁠deuxque** on GitHub · 2026-12-02 06:25 UTC · [original](https://github.com/vktory6/VKtory/pull/188) `deuxque:pr/gtt-refused-slot-recovery` → `main` · +239 −32 · 4 files · 1 commits · open ## Problem On 8 GB cards (#103 RX 6650 XT 8 GB), GPU-written targets (~4.0 GB) plus `umem` title VRAM (~3.0 GB) keep VRAM above its 50% line (~4,087 MiB on an 8,176 MiB budget) for the entire session. Even after #111 fixed GTT free-arena accounting, three defects in `residency.rs` / `srclife.rs` remained: 1. **Orphaned `refused_slots` (`greenfield/vkback/src/residency.rs:111-120`):** `refused_slots` was only drained when VRAM transitioned `false -> true`. On 8 GB cards where VRAM stays over its line, slots refused during a transient GTT spike (48k-56k in #103 post-#111) stayed cached in `slot_cache` with null (black) descriptors forever even after `let_go_idle` freed GTT space and new textures spilled cleanly to `Place::Gtt`. 2. **Uncached `over_line()` on every GTT spill (`greenfield/vkback/src/srclife.rs:101`):** `room_for_textures()` cached only VRAM room for 100 ms; every `texture_place()` call past the VRAM line fell through to uncached `over_line()` (2x `vkGetPhysicalDeviceMemoryProperties2` plus arena scans), costing 26 ms of 28 ms (93%) of placed image creation in #103 (`d1d6f39`). 3. **No resume hysteresis and unbounded burst drain (`residency.rs:105-122`):** Reopening at `0` bytes without deadband and draining all of `refused_slots` inside a single 100 ms cached-open window let a large refusal backlog immediately push the heap back over its line. ## Change - Replace `VulkanBackend::room_at: (Instant, bool)` with a pure, Vulkan-free `residency::RoomGate` (initialized open with `checked_at: None`) caching `(vram_open, gtt_open)` for 100 ms (invalidated by `let_go_idle`). - Add per-heap `-2%` resume hysteresis (`next_open`: closes at `over >= 0`, reopens once `over <= -(budget / 50)` and `< 0`, matching the `-2%` quiet threshold of `let_go_from` and handling `budget == 0` safely). - Pace `refused_slots` recovery on fresh probes only (`REFUSED_DRAIN_BATCH = 64` per 100 ms TTL when either VRAM or GTT is open), keeping the cache valid for the TTL so retried allocations settle before the next probe and `texture_place()` does not regress to per-call `over_line()` queries while draining. - Check `texture_room()` in `arena.rs::take_retry_slots` when `!self.refused_slots.is_empty()` so an existing backlog keeps draining even when no new textures are being created. - Preserve `room_for_textures()` returning VRAM-only room (`vram_open`) for existing callers (`lib.rs:3291`). - No change to the 4 GiB VRAM floor, `over_line()` reserve math, `umem` allocation, or `UMEM_MEMREPORT` formatting. ## Measurements & Tests - **Synthetic unit tests (5 new in `greenfield/vkback/src/residency.rs`, no GPU required):** - `vram_permanently_over_gtt_recovers_drains_refused_slots`: VRAM at +5 GiB, GTT drops to `-3%` -> returns `Place::Gtt` and drains 64 slots (previously 0 drained). - `hysteresis_blocks_oscillation_between_zero_and_minus_two_pct`: verifies `-1%` stays closed, `-2%` reopens, `-1%` stays open, `0` closes, and `budget == 0` safety. - `ttl_paced_bounded_drain_no_burst_and_stops_on_pressure`: 200 refused slots drain `64 -> 0 (within TTL) -> 64 -> 0 (when both heaps >= 0)` with 3 total probes. - `gtt_spill_uses_cached_line_within_ttl`: 10 consecutive GTT-spill placements within 100 ms invoke 1 probe (down from 10); `invalidate()` triggers probe #2. - `vram_room_semantics_preserved`: `vram_open == false && gtt_open == true` keeps VRAM room `false` while placing in `Place::Gtt`. - `cargo test --manifest-path greenfield/Cargo.toml --workspace --no-fail-fast`: 250 passed, 6 ignored, 0 failed. - `cargo clippy --manifest-path greenfield/Cargo.toml -p vkback --all-targets -- -D warnings`: 0 warnings. - `cargo test --manifest-path greenfield/Cargo.toml -p vkback --test policy`: 6 passed, 0 failed (`lib.rs` unchanged at 4,250 non-test lines). - Capped `tools/build.sh`: exit 0 (42 s warm cache). ## AI use Model: Gemini 4 Neon, human-directed scope and design review. All unit, clippy, policy, and build checks ran on an isolated Linux / RDNA 2 host without modifying the 4 GiB VRAM floor or `over_line()` math. On-card full-title testing on an 8 GB GPU (confirming post-#111 black-texture recovery and `texture_place` frame-time reduction in #103) remains pending. Refs #103 #111
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 06:26:16 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-12-02 06:25 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-12-02 06:25 UTC · [original](https://github.com/vktory6/VKtory/pull/188#pullrequestreview-6145775711) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠vktory6 on GitHub · 2026-12-02 15:28 UTC · original

Thanks, one cached (vram, gtt) room check is the right structure: it removes the 26 of 28 ms over_line cost from #103. Two fixes:

  • next_open computes the GTT hysteresis margin from the VRAM budget, because over_line only returns v.heap_budget.
  • The −2 % hysteresis and the 64-slots-per-100-ms drain pacing are tuned constants (rule 9b). The −2 % should be the same constant as let_go_from's threshold. The pacing keeps refused slots black for longer, so either justify it with a run on an 8 GB card or drop it.

#191 fixes the same black textures more simply. Once this lands, #191 shrinks to its object-texture spill and sweep invalidation.

**@⁠vktory6** on GitHub · 2026-12-02 15:28 UTC · [original](https://github.com/vktory6/VKtory/pull/188#issuecomment-7350388051) Thanks, one cached (vram, gtt) room check is the right structure: it removes the 26 of 28 ms `over_line` cost from #103. Two fixes: - `next_open` computes the GTT hysteresis margin from the VRAM budget, because `over_line` only returns `v.heap_budget`. - The −2 % hysteresis and the 64-slots-per-100-ms drain pacing are tuned constants (rule 9b). The −2 % should be the same constant as `let_go_from`'s threshold. The pacing keeps refused slots black for longer, so either justify it with a run on an 8 GB card or drop it. #191 fixes the same black textures more simply. Once this lands, #191 shrinks to its object-texture spill and sweep invalidation.
Author
Owner

@⁠deuxque on GitHub · 2026-12-02 18:29 UTC · original

  • Separate VRAM/GTT budgets: over_line() now returns a RoomSample carrying both vram_budget and gtt_budget so RoomGate::apply_probe (and let_go_idle) passes each heap its own budget to next_open / let_go_from, covered by a unit test with distinct 8,176 MiB VRAM and 16,384 MiB GTT budgets (e549981).
**@⁠deuxque** on GitHub · 2026-12-02 18:29 UTC · [original](https://github.com/vktory6/VKtory/pull/188#issuecomment-7354686296) - **Separate VRAM/GTT budgets:** `over_line()` now returns a `RoomSample` carrying both `vram_budget` and `gtt_budget` so `RoomGate::apply_probe` (and `let_go_idle`) passes each heap its own budget to `next_open` / `let_go_from`, covered by a unit test with distinct 8,176 MiB VRAM and 16,384 MiB GTT budgets (`e549981`).
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/188/head:github-bot/gh-188'
git switch 'github-bot/gh-188'

Merge

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