[pr-performance][memory] DARNER_PAGE_DEAD_S: page-buffer tiles under freed title memory give their memory back (mode 3, off by default) #319

Open
Cyber-Croissant wants to merge 1 commit from Cyber-Croissant/Darner:page-dead-tiles into main
Contributor

Contributor role (optional)

  • Fluxer ID: 1576300404596027392 (CyberCroissant#5122)

What it changes

  • The problem on main: a diagnostics counter added here (tiles of windows that lie wholly under title memory the game has freed, and that still hold pool memory). At the end of 12 min drives with page buffers in mode 3 it read 1,123 to 1,298 MB of such tiles dead for 60 s and more, out of 3.2 to 3.4 GB of tiles with memory (five drives without the switch, rows 3, 6, 9, 10 and 14 below).

In mode 3 a window's tile takes memory from the pool at its first write and keeps it until the window goes. Windows outlive the title's allocations under them, so tiles stay backed by memory nobody reads.

With DARNER_PAGE_DEAD_S=<seconds> a tile that lies wholly under title memory freed for that long, and that was written nothing but zeros since, is unmapped at its window's next take, in the order of the queue; its pool tile goes back once the submissions in the air have finished (the path unmap already uses). It then reads zeros, as a tile that never had memory, and gets memory again at the next write. A look once in 30 frames puts the windows that hold such tiles on the list the next send looks at, since a window nobody writes is not looked at otherwise.

Off by default: with the switch unset nothing is unmapped, the look returns at once, and a normal build does not note dead tiles at all. A build with the diagnostics feature notes them (a time stamp per tile) to count them and writes one log line with the page-buffer report; every drive below ran on such a build.

This was opened as a work in progress; the repeats below are done and it is now ready for review. Results from more testers and more reviewers would still help a lot: everything below comes from one PC, one route and one card. Other cards (8 GB, AMD, Intel), 16 GB of RAM, long sessions and other places in the game are not covered.

A second change, emptying the emptiest pool heap so that it goes back to the system (DARNER_PAGE_DRAIN), builds on this one: #332. Order: this one first. #332 sits on this branch and stays a draft (WIP) until this one is merged; then its WIP comes off and it can be reviewed and merged in turn. Most drives below ran with both, since the private-memory gain comes from the two together; they are marked.

How it was tested

  • Tested revision: e5abccd9 on main f3840d73 for the tests, the gates and the build. The drives ran on two other trees, said in the table: an earlier base (57dea7f2) and f3840d73 with this change and the drain together (the drain switched off unless marked). No drive has run on e5abccd9 itself yet.

  • Commands and results:

    • cargo test -p darner-gpu --features diagnostics --lib pagebuf::: 6 passed, 5 ignored (the ignored ones need a card).
    • tiles_under_freed_title_memory_give_their_memory_back_in_mode_three (new, ignored by default, run by name with DARNER_ADAPTER, DARNER_PAGE_BUFFERS=3, DARNER_PAGE_DEAD_S=1): passed on the RTX 5070 the drives ran on, and on the PC's integrated AMD adapter. It goes through the real path of a submission: the tiles wholly under freed title memory give their memory back at the next send and read zeros; a tile written anything but zeros since the free stays, a tile freed in part stays, nothing leaves before its time, and a tile that left gets memory again when a refresh finds bytes there.
    • a_window_written_straight_into_its_tiles_round_trip_in_mode_three (existing): passed with the switch unset and with DARNER_PAGE_DEAD_S=1, on both adapters.
    • About the adapter: the card tests' helper refuses any adapter whose name holds "5070" (it prints "not run" and the test counts as passed), its comment says "never on the RTX 5070 the game's benchmarks run on". No switch lifts that. For the runs on the RTX 5070 I lifted the check in a local copy of e5abccd9 (not in this PR), with the game closed. Before that the tests had only run on the integrated adapter, which shares the PC's memory and so says little about a discrete card.
    • cargo check -p darner (no diagnostics feature): 0 warnings.
    • cargo build --profile diag -p darner --features diagnostics: built.
  • Changes a default: no

  • A/B result: the switch is off by default, so this is how it was checked rather than a default's A/B. Autodrive of 12 min on a recorded input tape, the same save, one drive per row, in the order they ran. Numbers are read at the end of the drive (tiles, heaps), over its last tenth (private, commit) or over the window 30 to 720 s after the world's first frame (frame figures). "D60" is DARNER_PAGE_DEAD_S=60, "D10" is 10, "PACK" is DARNER_PAGE_PACK=1, "DRAIN" is the second change.

    # Tree Switches Tiles with memory, MB Pool heaps, MB Private, GB Peak private, GB Commit, GB Mean fps p99, ms Frame at 6,500 draws, ms Flicker events/min Tiles given back UpdateTileMappings calls
    1 old base PACK D10 1,872 2,752 24.79 24.93 45.76 27.0 74.0 40.3 8.1 174,647 not read
    2 old base PACK D60 2,315 3,072 24.86 25.00 45.54 28.5 65.9 39.7 10.8 49,921 not read
    3 old base PACK 3,375 3,648 25.57 25.74 46.32 27.7 70.8 40.0 8.8 0 26,466
    4 old base PACK D60 DRAIN 2,105 2,176 23.85 24.80 44.88 27.5 70.0 40.1 7.7 52,894 56,946
    5 old base PACK D60 2,141 3,136 25.31 25.46 46.07 27.7 70.4 40.3 9.1 52,218 not read
    6 old base none 3,427 3,648 25.45 25.54 46.19 27.8 70.3 39.4 12.5 0 not read
    7 old base PACK D60 DRAIN 2,221 2,240 24.45 24.86 45.26 28.0 70.7 40.1 5.7 50,708 not read
    8 old base PACK D60 DRAIN 2,126 2,240 24.75 25.82 45.55 28.0 70.7 40.1 4.7 53,958 not read
    9 old base none 3,371 3,840 25.69 25.91 46.48 27.6 70.0 40.4 9.8 0 not read
    10 f3840d73 + both none 3,211 3,584 24.08 24.22 45.20 27.5 72.2 40.4 7.4 0 26,695
    11 f3840d73 + both PACK D60 DRAIN 2,285 2,304 22.84 23.32 44.67 26.5 73.6 41.5 9.5 48,990 54,395
    12 f3840d73 + both PACK D60 2,307 3,200 24.12 24.24 45.65 26.9 72.1 40.8 7.6 50,690 51,356
    13 f3840d73 + both PACK D60 DRAIN 2,496 2,560 22.94 23.53 44.95 26.9 74.9 42.1 12.4 52,899 57,742
    14 f3840d73 + both none 3,430 3,840 24.36 24.49 46.85 27.5 71.2 41.0 11.1 0 25,169
    15 f3840d73 + both PACK DRAIN 3,483 3,520 24.10 24.33 46.18 26.5 74.0 41.2 11.1 0 27,291
    16 f3840d73, main as it is none 3,298 3,584 24.12 24.19 46.23 27.4 70.1 40.8 7.5 0 26,234
    17 f3840d73 + both PACK D60 DRAIN 2,033 2,048 22.57 23.83 44.68 27.8 69.2 39.9 9.1 50,736 53,494
    18 f3840d73 + both PACK 3,457 3,712 24.29 24.49 46.57 26.7 74.4 41.7 21.6 0 26,378
    19 f3840d73 + both PACK D60 DRAIN 2,172 2,304 23.01 23.95 45.27 27.8 69.1 39.6 7.5 55,249 57,184
    20 f3840d73 + both none 3,342 3,968 24.42 24.54 46.80 27.0 73.7 41.8 7.4 0 26,296
    21 f3840d73 + both D60 DRAIN 2,086 2,112 22.76 23.90 45.07 28.1 70.7 39.5 7.5 52,820 54,922
    22 f3840d73 + both none 3,320 3,584 24.38 24.53 46.50 28.3 71.3 40.5 7.3 0 24,911

    Rows 16 to 22 were added later the same day: repeats, and the cases that were missing. Row 16 is main as it is, with none of this code. One drive whose autodrive did not start (the character stayed out of the car) was discarded and run again as row 22. Drives of other trees that ran in between are not listed.

    Read from the table, for this change alone (rows 2, 5, 12 against the rows without it):

    • Tiles with memory at the end: 2,141 to 2,315 MB against 3,211 to 3,430.
    • Pool heaps at the end: 3,072 to 3,200 MB against 3,584 to 3,840. The tiles given back are spread over heaps that stay, which is what the drain is for.
    • Private memory over the last tenth: 24.86 and 25.31 GB against 25.45 to 25.69 on the old base; 24.12 against 24.08, 24.36, 24.42 and 24.38 on the new one. On current main the one drive with this change alone is inside the spread of the four drives without it. I do not claim a private-memory gain for this change alone; with the drain of #332 it is 1.1 to 1.9 GB (rows 11, 13, 17, 19, 21 against 10, 14, 20, 22).
    • Frame figures: no cost found. On current main the four drives without any switch (rows 10, 14, 20, 22) have a mean of 27.0 to 28.3 fps, a p99 of 71.2 to 73.7 ms and 40.4 to 41.8 ms at 6,500 draws; row 12 (this change with PACK) has 26.9 fps, 72.1 ms and 40.8 ms. On the old base rows 2 and 5 are within the rows without the switch.
    • UpdateTileMappings calls about double (51,356 against 25,169 and 26,695 over a drive).
    • With both switches: the four drives with PACK D60 DRAIN (rows 11, 13, 17, 19) have 26.5 to 27.8 fps, a p99 of 69.1 to 74.9 ms and 39.6 to 42.1 ms at 6,500 draws, and row 21 (D60 DRAIN without PACK) 28.1 fps, 70.7 ms and 39.5 ms. An earlier version of this text gave a frame-time cost for the two switches together (p99 +1.4 and +3.7 ms, from rows 11 and 13 against 10 and 14). With the repeats that difference is inside the spread between drives of one arm, and I withdraw it. Four benches with the camera standing still (240 s each; none, PACK D60 DRAIN, PACK D60 DRAIN, none) gave a mean frame of 34.8, 32.5, 32.7 and 34.1 ms and a p99 of 49.8, 49.3, 47.8 and 50.1 ms; the two with the switches drew fewer draws a frame (6,649 and 6,850 against 7,817 and 7,372), so no speed gain is claimed either.
    • PACK is not needed: row 21 (D60 DRAIN, no PACK, one drive) ends at 2,112 MB of heaps and 22.76 GB private, as the rows with PACK do. PACK alone (row 18) changes neither (3,712 MB, 24.29 GB).
    • Seen by eye, by the person at the screen (one look per drive, at the end of the route, the car stopped): the shadow of one tree flickered in rows 18 (PACK alone) and 19 (PACK D60 DRAIN); it did not in rows 20 and 22 (no switch) nor in row 21 (D60 DRAIN without PACK). The flicker counter has a burst in row 18 only (79 and 82 events a minute, 3 and 2 minutes before the end; 0 to 34 a minute in the last six minutes of the other drives) and nothing in row 19, so it does not see this reliably. Both drives with it have DARNER_PAGE_PACK=1. One drive per case is not enough to name a cause, and the light and the weather of the game are not the same from drive to drive. The earlier rows were not looked at for it.
    • With 10 s (row 1) 174,647 tiles were given back against about 50,000 at 60 s: tiles are often written again soon after being freed. In row 12 the counter of dead tiles written again reads 283,457 after under 1 s, 161,545 after 1 to 10 s, 95,317 after 10 to 60 s and 363 after 60 s and more.
    • No error line in any of these logs besides one Streamline line that every drive has.
  • Where the process's memory is, from the layer's own process memory: line (DARNER_PROCESS_MEMORY=1, one a minute; the last one of each drive on f3840d73, MB; column numbers are the rows above):

    Last reading of the drive, MB none (10) none (14) PACK D60 (12) PACK DRAIN (15) PACK D60 DRAIN (11) PACK D60 DRAIN (13)
    Private, by the system 24,557 25,044 24,706 24,703 23,530 23,526
    of it in memory (working set) 18,707 18,228 19,420 19,297 16,811 16,343
    Private at console addresses (the title's own) 3,428 3,428 3,428 3,428 3,428 3,428
    Private at host addresses 20,835 21,260 20,996 20,962 19,794 19,886
    of it write-combined (the card's memory the driver maps) 10,731 10,857 11,253 10,839 10,839 10,788
    Private bytes the line names 14,521 14,647 15,043 14,629 14,629 14,578
    Private bytes it does not name 10,035 10,396 9,662 10,073 8,900 8,947
    Mapped at host addresses 13,240 13,501 11,433 11,658 13,269 13,751
    of it the copies' mirror files 6,927 7,188 7,187 7,407 6,955 7,553
    Mapped at console addresses 8,006 8,132 8,053 8,211 8,019 8,298
    Committed, found by address 45,511 46,323 43,912 44,261 44,513 45,365

    Read from it, nothing more: with both switches the private bytes at host addresses are 19.8 and 19.9 GB against 20.8 and 21.3, the bytes the line does not name 8.9 GB against 10.0 and 10.4, and the working set 16.3 and 16.8 GB against 18.2 and 18.7. With one switch alone the private total is inside the two drives without any (24.7 against 24.6 and 25.0). The title's own private bytes and the write-combined part do not move. The mapped bytes at host addresses are 1.6 to 2.1 GB lower in the two drives with one switch alone: one mapped region of 2,048 MB is in the last reading of the four other drives (it appears at minute 2, 6, 9 or 12 of the drive, with and without the switches) and never in those two. I have not identified it. It is mapped, not private, and the commit charge the system reports for the process (the "Commit" column of the first table) is not lower in those two drives. In an address census on the earlier base (a local diagnostic, not in this PR) the pool's heaps showed as private, not write-combined regions of 64 MiB committed whole.

  • Gates run on that revision (the three in AGENTS.md; there is no CI): on e5abccd9: cargo clippy --workspace --all-targets --locked -- -D warnings passed; the same with --all-features passed; cargo xtask policy: 555 files ok. cargo test --workspace --locked failed, as it does on main here (#389): it stopped at darner-gpu with 2 failed tests of 1,773 (gpu_owned::tests::concurrent_faults_on_same_block_serialize_single_readback, watch::tests::ask_once_by_res_splits_reservations_without_refusals), neither in the files this touches. cargo test -p darner-gpu --lib --locked six times: 2 runs failed, with tests of watch and host::watch_pipe that fail on main too (main f3840d73: 10 runs of 20; #332's head, which holds this commit: 9 of 20, and 1,757 passed, 0 failed with --test-threads=1). The rest of the workspace but darner-shader, on #332's head: 1,015 passed, 0 failed. darner-shader, on that head: 556 passed, 1 failed (emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders, which fails on main too), with oracle64::legacy_mul_forms_are_exact skipped: on main it had not ended after 14 min of CPU time.

  • Gameplay, when relevant: RTX 5070 12 GB, Series S profile, DLSS Quality, no frame generation, no ray tracing. Diagnostics build (--profile diag --features diagnostics), DARNER_PAGE_BUFFERS at its play default (3).

  • Shader wave sizes tested, when relevant: not relevant.

  • Hardware dependence: untested elsewhere. Needs tiled resources tier 2 and mode 3; does nothing in the other modes.

  • Coverage gaps:

    • One PC, one card, one route, 12 min; one drive per row, so run-to-run spread is only what the repeated rows show.
    • No drive on e5abccd9 itself; the drives' trees also held the drain code, switched off.
    • Nothing under a RAM limit (16 GB) or a small card.
    • Without DARNER_PAGE_PACK=1: one drive (row 21), with both switches; this change alone without PACK is not measured.
    • The private-memory effect of this change alone is not established (see above).
    • The card tests on the RTX 5070 need the helper's check lifted by hand (see above); a reviewer with another card does not.
    • The tests are mine; nobody else has read them.
    • With PR #221 (which touches the same functions): a trial merge had two text conflicts in the tests, both "two tests added at the same place"; the merged tree passed both sets of tests (on the integrated adapter only so far) and has not been driven yet. If #221 lands first, the mode-3 checks here should follow its windows_direct().

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #221 (windows tile by tile by adapter; same file and functions, different subject, see coverage gaps). #321 (a title free reaches the paged copies even with nothing in place) is about the path this change depends on: the give-back acts on tiles that shadow::paged_freed marks, and on main that function is reached only when something is in place (inplace::holds_any()). In the drives above the frees did reach it (about 1.2 GB of tiles dead for 60 s and more at the end of a drive without the switch; 48,990 to 53,958 tiles given back with D60); I have not checked whether every free did. With #321 more frees may reach it; not measured. It also touches shadow.rs; no trial merge done. #310 and #300 touch shadow.rs for landed ranges, a different subject. #274 is about the host's retirement queues, not the tile pool. Closed: #56, #59, #62 (pools and windows; none gives tiles back). Issues: #111 (memory outside the ledger grows on Proton; this may or may not help there, not tested), #290, #60, #19.
  • Replaces or overlaps: none found (searched open and closed pull requests and issues for DARNER_PAGE_PACK, DARNER_PAGE_BUFFERS, "page buffers", "tiles", "pool heaps", and the file lists of the open pull requests for pagebuf.rs).
## Contributor role (optional) - Fluxer ID: 1576300404596027392 (CyberCroissant#5122) ## What it changes - The problem on main: a diagnostics counter added here (tiles of windows that lie wholly under title memory the game has freed, and that still hold pool memory). At the end of 12 min drives with page buffers in mode 3 it read 1,123 to 1,298 MB of such tiles dead for 60 s and more, out of 3.2 to 3.4 GB of tiles with memory (five drives without the switch, rows 3, 6, 9, 10 and 14 below). In mode 3 a window's tile takes memory from the pool at its first write and keeps it until the window goes. Windows outlive the title's allocations under them, so tiles stay backed by memory nobody reads. With `DARNER_PAGE_DEAD_S=<seconds>` a tile that lies wholly under title memory freed for that long, and that was written nothing but zeros since, is unmapped at its window's next take, in the order of the queue; its pool tile goes back once the submissions in the air have finished (the path `unmap` already uses). It then reads zeros, as a tile that never had memory, and gets memory again at the next write. A look once in 30 frames puts the windows that hold such tiles on the list the next send looks at, since a window nobody writes is not looked at otherwise. Off by default: with the switch unset nothing is unmapped, the look returns at once, and a normal build does not note dead tiles at all. A build with the `diagnostics` feature notes them (a time stamp per tile) to count them and writes one log line with the page-buffer report; every drive below ran on such a build. This was opened as a work in progress; the repeats below are done and it is now ready for review. **Results from more testers and more reviewers would still help a lot**: everything below comes from one PC, one route and one card. Other cards (8 GB, AMD, Intel), 16 GB of RAM, long sessions and other places in the game are not covered. A second change, emptying the emptiest pool heap so that it goes back to the system (`DARNER_PAGE_DRAIN`), builds on this one: #332. **Order: this one first.** #332 sits on this branch and stays a draft (WIP) until this one is merged; then its WIP comes off and it can be reviewed and merged in turn. Most drives below ran with both, since the private-memory gain comes from the two together; they are marked. ## How it was tested - Tested revision: `e5abccd9` on main `f3840d73` for the tests, the gates and the build. The drives ran on two other trees, said in the table: an earlier base (`57dea7f2`) and `f3840d73` with this change and the drain together (the drain switched off unless marked). No drive has run on `e5abccd9` itself yet. - Commands and results: - `cargo test -p darner-gpu --features diagnostics --lib pagebuf::`: 6 passed, 5 ignored (the ignored ones need a card). - `tiles_under_freed_title_memory_give_their_memory_back_in_mode_three` (new, ignored by default, run by name with `DARNER_ADAPTER`, `DARNER_PAGE_BUFFERS=3`, `DARNER_PAGE_DEAD_S=1`): passed on the RTX 5070 the drives ran on, and on the PC's integrated AMD adapter. It goes through the real path of a submission: the tiles wholly under freed title memory give their memory back at the next send and read zeros; a tile written anything but zeros since the free stays, a tile freed in part stays, nothing leaves before its time, and a tile that left gets memory again when a refresh finds bytes there. - `a_window_written_straight_into_its_tiles_round_trip_in_mode_three` (existing): passed with the switch unset and with `DARNER_PAGE_DEAD_S=1`, on both adapters. - About the adapter: the card tests' helper refuses any adapter whose name holds "5070" (it prints "not run" and the test counts as passed), its comment says "never on the RTX 5070 the game's benchmarks run on". No switch lifts that. For the runs on the RTX 5070 I lifted the check in a local copy of `e5abccd9` (not in this PR), with the game closed. Before that the tests had only run on the integrated adapter, which shares the PC's memory and so says little about a discrete card. - `cargo check -p darner` (no `diagnostics` feature): 0 warnings. - `cargo build --profile diag -p darner --features diagnostics`: built. - Changes a default: no - A/B result: the switch is off by default, so this is how it was checked rather than a default's A/B. Autodrive of 12 min on a recorded input tape, the same save, one drive per row, in the order they ran. Numbers are read at the end of the drive (tiles, heaps), over its last tenth (private, commit) or over the window 30 to 720 s after the world's first frame (frame figures). "D60" is `DARNER_PAGE_DEAD_S=60`, "D10" is 10, "PACK" is `DARNER_PAGE_PACK=1`, "DRAIN" is the second change. | # | Tree | Switches | Tiles with memory, MB | Pool heaps, MB | Private, GB | Peak private, GB | Commit, GB | Mean fps | p99, ms | Frame at 6,500 draws, ms | Flicker events/min | Tiles given back | UpdateTileMappings calls | |---|---|---|---|---|---|---|---|---|---|---|---|---|---| | 1 | old base | PACK D10 | 1,872 | 2,752 | 24.79 | 24.93 | 45.76 | 27.0 | 74.0 | 40.3 | 8.1 | 174,647 | not read | | 2 | old base | PACK D60 | 2,315 | 3,072 | 24.86 | 25.00 | 45.54 | 28.5 | 65.9 | 39.7 | 10.8 | 49,921 | not read | | 3 | old base | PACK | 3,375 | 3,648 | 25.57 | 25.74 | 46.32 | 27.7 | 70.8 | 40.0 | 8.8 | 0 | 26,466 | | 4 | old base | PACK D60 DRAIN | 2,105 | 2,176 | 23.85 | 24.80 | 44.88 | 27.5 | 70.0 | 40.1 | 7.7 | 52,894 | 56,946 | | 5 | old base | PACK D60 | 2,141 | 3,136 | 25.31 | 25.46 | 46.07 | 27.7 | 70.4 | 40.3 | 9.1 | 52,218 | not read | | 6 | old base | none | 3,427 | 3,648 | 25.45 | 25.54 | 46.19 | 27.8 | 70.3 | 39.4 | 12.5 | 0 | not read | | 7 | old base | PACK D60 DRAIN | 2,221 | 2,240 | 24.45 | 24.86 | 45.26 | 28.0 | 70.7 | 40.1 | 5.7 | 50,708 | not read | | 8 | old base | PACK D60 DRAIN | 2,126 | 2,240 | 24.75 | 25.82 | 45.55 | 28.0 | 70.7 | 40.1 | 4.7 | 53,958 | not read | | 9 | old base | none | 3,371 | 3,840 | 25.69 | 25.91 | 46.48 | 27.6 | 70.0 | 40.4 | 9.8 | 0 | not read | | 10 | f3840d73 + both | none | 3,211 | 3,584 | 24.08 | 24.22 | 45.20 | 27.5 | 72.2 | 40.4 | 7.4 | 0 | 26,695 | | 11 | f3840d73 + both | PACK D60 DRAIN | 2,285 | 2,304 | 22.84 | 23.32 | 44.67 | 26.5 | 73.6 | 41.5 | 9.5 | 48,990 | 54,395 | | 12 | f3840d73 + both | PACK D60 | 2,307 | 3,200 | 24.12 | 24.24 | 45.65 | 26.9 | 72.1 | 40.8 | 7.6 | 50,690 | 51,356 | | 13 | f3840d73 + both | PACK D60 DRAIN | 2,496 | 2,560 | 22.94 | 23.53 | 44.95 | 26.9 | 74.9 | 42.1 | 12.4 | 52,899 | 57,742 | | 14 | f3840d73 + both | none | 3,430 | 3,840 | 24.36 | 24.49 | 46.85 | 27.5 | 71.2 | 41.0 | 11.1 | 0 | 25,169 | | 15 | f3840d73 + both | PACK DRAIN | 3,483 | 3,520 | 24.10 | 24.33 | 46.18 | 26.5 | 74.0 | 41.2 | 11.1 | 0 | 27,291 | | 16 | f3840d73, main as it is | none | 3,298 | 3,584 | 24.12 | 24.19 | 46.23 | 27.4 | 70.1 | 40.8 | 7.5 | 0 | 26,234 | | 17 | f3840d73 + both | PACK D60 DRAIN | 2,033 | 2,048 | 22.57 | 23.83 | 44.68 | 27.8 | 69.2 | 39.9 | 9.1 | 50,736 | 53,494 | | 18 | f3840d73 + both | PACK | 3,457 | 3,712 | 24.29 | 24.49 | 46.57 | 26.7 | 74.4 | 41.7 | 21.6 | 0 | 26,378 | | 19 | f3840d73 + both | PACK D60 DRAIN | 2,172 | 2,304 | 23.01 | 23.95 | 45.27 | 27.8 | 69.1 | 39.6 | 7.5 | 55,249 | 57,184 | | 20 | f3840d73 + both | none | 3,342 | 3,968 | 24.42 | 24.54 | 46.80 | 27.0 | 73.7 | 41.8 | 7.4 | 0 | 26,296 | | 21 | f3840d73 + both | D60 DRAIN | 2,086 | 2,112 | 22.76 | 23.90 | 45.07 | 28.1 | 70.7 | 39.5 | 7.5 | 52,820 | 54,922 | | 22 | f3840d73 + both | none | 3,320 | 3,584 | 24.38 | 24.53 | 46.50 | 28.3 | 71.3 | 40.5 | 7.3 | 0 | 24,911 | Rows 16 to 22 were added later the same day: repeats, and the cases that were missing. Row 16 is main as it is, with none of this code. One drive whose autodrive did not start (the character stayed out of the car) was discarded and run again as row 22. Drives of other trees that ran in between are not listed. Read from the table, for this change alone (rows 2, 5, 12 against the rows without it): - Tiles with memory at the end: 2,141 to 2,315 MB against 3,211 to 3,430. - Pool heaps at the end: 3,072 to 3,200 MB against 3,584 to 3,840. The tiles given back are spread over heaps that stay, which is what the drain is for. - Private memory over the last tenth: 24.86 and 25.31 GB against 25.45 to 25.69 on the old base; 24.12 against 24.08, 24.36, 24.42 and 24.38 on the new one. **On current main the one drive with this change alone is inside the spread of the four drives without it.** I do not claim a private-memory gain for this change alone; with the drain of #332 it is 1.1 to 1.9 GB (rows 11, 13, 17, 19, 21 against 10, 14, 20, 22). - Frame figures: no cost found. On current main the four drives without any switch (rows 10, 14, 20, 22) have a mean of 27.0 to 28.3 fps, a p99 of 71.2 to 73.7 ms and 40.4 to 41.8 ms at 6,500 draws; row 12 (this change with PACK) has 26.9 fps, 72.1 ms and 40.8 ms. On the old base rows 2 and 5 are within the rows without the switch. - `UpdateTileMappings` calls about double (51,356 against 25,169 and 26,695 over a drive). - With both switches: the four drives with PACK D60 DRAIN (rows 11, 13, 17, 19) have 26.5 to 27.8 fps, a p99 of 69.1 to 74.9 ms and 39.6 to 42.1 ms at 6,500 draws, and row 21 (D60 DRAIN without PACK) 28.1 fps, 70.7 ms and 39.5 ms. **An earlier version of this text gave a frame-time cost for the two switches together (p99 +1.4 and +3.7 ms, from rows 11 and 13 against 10 and 14). With the repeats that difference is inside the spread between drives of one arm, and I withdraw it.** Four benches with the camera standing still (240 s each; none, PACK D60 DRAIN, PACK D60 DRAIN, none) gave a mean frame of 34.8, 32.5, 32.7 and 34.1 ms and a p99 of 49.8, 49.3, 47.8 and 50.1 ms; the two with the switches drew fewer draws a frame (6,649 and 6,850 against 7,817 and 7,372), so no speed gain is claimed either. - PACK is not needed: row 21 (D60 DRAIN, no PACK, one drive) ends at 2,112 MB of heaps and 22.76 GB private, as the rows with PACK do. PACK alone (row 18) changes neither (3,712 MB, 24.29 GB). - Seen by eye, by the person at the screen (one look per drive, at the end of the route, the car stopped): the shadow of one tree flickered in rows 18 (PACK alone) and 19 (PACK D60 DRAIN); it did not in rows 20 and 22 (no switch) nor in row 21 (D60 DRAIN without PACK). The flicker counter has a burst in row 18 only (79 and 82 events a minute, 3 and 2 minutes before the end; 0 to 34 a minute in the last six minutes of the other drives) and nothing in row 19, so it does not see this reliably. Both drives with it have `DARNER_PAGE_PACK=1`. One drive per case is not enough to name a cause, and the light and the weather of the game are not the same from drive to drive. The earlier rows were not looked at for it. - With 10 s (row 1) 174,647 tiles were given back against about 50,000 at 60 s: tiles are often written again soon after being freed. In row 12 the counter of dead tiles written again reads 283,457 after under 1 s, 161,545 after 1 to 10 s, 95,317 after 10 to 60 s and 363 after 60 s and more. - No error line in any of these logs besides one Streamline line that every drive has. - Where the process's memory is, from the layer's own `process memory:` line (`DARNER_PROCESS_MEMORY=1`, one a minute; the last one of each drive on `f3840d73`, MB; column numbers are the rows above): | Last reading of the drive, MB | none (10) | none (14) | PACK D60 (12) | PACK DRAIN (15) | PACK D60 DRAIN (11) | PACK D60 DRAIN (13) | |---|---|---|---|---|---|---| | Private, by the system | 24,557 | 25,044 | 24,706 | 24,703 | 23,530 | 23,526 | | of it in memory (working set) | 18,707 | 18,228 | 19,420 | 19,297 | 16,811 | 16,343 | | Private at console addresses (the title's own) | 3,428 | 3,428 | 3,428 | 3,428 | 3,428 | 3,428 | | Private at host addresses | 20,835 | 21,260 | 20,996 | 20,962 | 19,794 | 19,886 | | of it write-combined (the card's memory the driver maps) | 10,731 | 10,857 | 11,253 | 10,839 | 10,839 | 10,788 | | Private bytes the line names | 14,521 | 14,647 | 15,043 | 14,629 | 14,629 | 14,578 | | Private bytes it does not name | 10,035 | 10,396 | 9,662 | 10,073 | 8,900 | 8,947 | | Mapped at host addresses | 13,240 | 13,501 | 11,433 | 11,658 | 13,269 | 13,751 | | of it the copies' mirror files | 6,927 | 7,188 | 7,187 | 7,407 | 6,955 | 7,553 | | Mapped at console addresses | 8,006 | 8,132 | 8,053 | 8,211 | 8,019 | 8,298 | | Committed, found by address | 45,511 | 46,323 | 43,912 | 44,261 | 44,513 | 45,365 | Read from it, nothing more: with both switches the private bytes at host addresses are 19.8 and 19.9 GB against 20.8 and 21.3, the bytes the line does not name 8.9 GB against 10.0 and 10.4, and the working set 16.3 and 16.8 GB against 18.2 and 18.7. With one switch alone the private total is inside the two drives without any (24.7 against 24.6 and 25.0). The title's own private bytes and the write-combined part do not move. The mapped bytes at host addresses are 1.6 to 2.1 GB lower in the two drives with one switch alone: one mapped region of 2,048 MB is in the last reading of the four other drives (it appears at minute 2, 6, 9 or 12 of the drive, with and without the switches) and never in those two. I have not identified it. It is mapped, not private, and the commit charge the system reports for the process (the "Commit" column of the first table) is not lower in those two drives. In an address census on the earlier base (a local diagnostic, not in this PR) the pool's heaps showed as private, not write-combined regions of 64 MiB committed whole. - Gates run on that revision (the three in AGENTS.md; there is no CI): on `e5abccd9`: `cargo clippy --workspace --all-targets --locked -- -D warnings` passed; the same with `--all-features` passed; `cargo xtask policy`: 555 files ok. `cargo test --workspace --locked` **failed, as it does on main here** (#389): it stopped at `darner-gpu` with 2 failed tests of 1,773 (`gpu_owned::tests::concurrent_faults_on_same_block_serialize_single_readback`, `watch::tests::ask_once_by_res_splits_reservations_without_refusals`), neither in the files this touches. `cargo test -p darner-gpu --lib --locked` six times: 2 runs failed, with tests of `watch` and `host::watch_pipe` that fail on main too (main `f3840d73`: 10 runs of 20; #332's head, which holds this commit: 9 of 20, and 1,757 passed, 0 failed with `--test-threads=1`). The rest of the workspace but `darner-shader`, on #332's head: 1,015 passed, 0 failed. `darner-shader`, on that head: 556 passed, 1 failed (`emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders`, which fails on main too), with `oracle64::legacy_mul_forms_are_exact` skipped: on main it had not ended after 14 min of CPU time. - Gameplay, when relevant: RTX 5070 12 GB, Series S profile, DLSS Quality, no frame generation, no ray tracing. Diagnostics build (`--profile diag --features diagnostics`), `DARNER_PAGE_BUFFERS` at its play default (3). - Shader wave sizes tested, when relevant: not relevant. - Hardware dependence: untested elsewhere. Needs tiled resources tier 2 and mode 3; does nothing in the other modes. - Coverage gaps: - One PC, one card, one route, 12 min; one drive per row, so run-to-run spread is only what the repeated rows show. - No drive on `e5abccd9` itself; the drives' trees also held the drain code, switched off. - Nothing under a RAM limit (16 GB) or a small card. - Without `DARNER_PAGE_PACK=1`: one drive (row 21), with both switches; this change alone without PACK is not measured. - The private-memory effect of this change alone is not established (see above). - The card tests on the RTX 5070 need the helper's check lifted by hand (see above); a reviewer with another card does not. - The tests are mine; nobody else has read them. - With PR #221 (which touches the same functions): a trial merge had two text conflicts in the tests, both "two tests added at the same place"; the merged tree passed both sets of tests (on the integrated adapter only so far) and has not been driven yet. If #221 lands first, the mode-3 checks here should follow its `windows_direct()`. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #221 (windows tile by tile by adapter; same file and functions, different subject, see coverage gaps). #321 (a title free reaches the paged copies even with nothing in place) is about the path this change depends on: the give-back acts on tiles that `shadow::paged_freed` marks, and on main that function is reached only when something is in place (`inplace::holds_any()`). In the drives above the frees did reach it (about 1.2 GB of tiles dead for 60 s and more at the end of a drive without the switch; 48,990 to 53,958 tiles given back with D60); I have not checked whether every free did. With #321 more frees may reach it; not measured. It also touches `shadow.rs`; no trial merge done. #310 and #300 touch `shadow.rs` for landed ranges, a different subject. #274 is about the host's retirement queues, not the tile pool. Closed: #56, #59, #62 (pools and windows; none gives tiles back). Issues: #111 (memory outside the ledger grows on Proton; this may or may not help there, not tested), #290, #60, #19. - Replaces or overlaps: none found (searched open and closed pull requests and issues for `DARNER_PAGE_PACK`, `DARNER_PAGE_BUFFERS`, "page buffers", "tiles", "pool heaps", and the file lists of the open pull requests for `pagebuf.rs`).
A tile of a window written straight in that lies wholly under title memory
freed for the given number of seconds, and written nothing but zeros since,
is unmapped at the window's next take and its memory goes back to the pool
once the submissions in the air have finished. It reads zeros, as a tile
that never had memory, and gets memory again at the next write. A look
once in 30 frames puts the windows that hold such tiles on the list the
next send looks at. Diagnostics builds count the dead tiles by age.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Cyber-Croissant changed title from WIP: [pr-performance][memory] DARNER_PAGE_DEAD_S: page-buffer tiles under freed title memory give their memory back (mode 3, off by default) to [pr-performance][memory] DARNER_PAGE_DEAD_S: page-buffer tiles under freed title memory give their memory back (mode 3, off by default) 2026-12-04 18:57:17 +00:00
Contributor

Code review only (read the diff at e5abccd9), nothing built or run.

  • The give-back path looks right. It runs under the write gate (try_write, so nothing leaves while a write straight in is under way), skips tiles with a pending mapping, hot tiles and this take's direct tiles, and returns memory through the existing unmap/retire path. I checked whether a tile freed and then written by a shader could keep its dead mark and lose the shader's bytes. It can't: a declared shader write ends the direct way for good (Shadow::end_direct), and take_dead acts only on direct windows.
  • As your table says, this one alone doesn't move private memory on current main. Its use is as the base for #332, so testers with RAM problems should run both switches together.
  • Related, not required: with nothing in place, only the runtime's physical-page unmaps and remaps reach paged_freed today (title_memory_changed, ungated). The title's own VirtualFree goes through the holds_any()-gated path, which #321 opens. With #321, tiles over memory the title frees that way may qualify too.
  • The doubled UpdateTileMappings count showed no frame cost on your PC. A second tester with a weaker CPU would help settle that.

Reviewed with Claude Code (AI-assisted); findings checked by a human before posting.

Code review only (read the diff at `e5abccd9`), nothing built or run. - The give-back path looks right. It runs under the write gate (`try_write`, so nothing leaves while a write straight in is under way), skips tiles with a pending mapping, hot tiles and this take's `direct` tiles, and returns memory through the existing `unmap`/`retire` path. I checked whether a tile freed and then written by a shader could keep its dead mark and lose the shader's bytes. It can't: a declared shader write ends the direct way for good (`Shadow::end_direct`), and `take_dead` acts only on direct windows. - As your table says, this one alone doesn't move private memory on current main. Its use is as the base for #332, so testers with RAM problems should run both switches together. - Related, not required: with nothing in place, only the runtime's physical-page unmaps and remaps reach `paged_freed` today (`title_memory_changed`, ungated). The title's own `VirtualFree` goes through the `holds_any()`-gated path, which #321 opens. With #321, tiles over memory the title frees that way may qualify too. - The doubled `UpdateTileMappings` count showed no frame cost on your PC. A second tester with a weaker CPU would help settle that. Reviewed with Claude Code (AI-assisted); findings checked by a human before posting.
Author
Contributor

@iBooM72 thank you for the review, and for checking the shader-write case.

  • Both switches together: agreed. The private-memory gain is in the rows with the drain of #332 (11, 13, 17, 19, 21); this one alone is its base.
  • Frees that reach paged_freed: thank you for naming the two paths, I read the code the same way. With nothing in place, the runtime's unmaps and remaps reach it (title_memory_changed), the title's own VirtualFree does not (holds_any()), until #321. So the dead tiles counted in the drives (about 1.2 GB at the end of a drive without the switch) came from the first path. With #321: not measured here.
  • UpdateTileMappings: agreed, a tester with a weaker CPU is what is missing. I only have this PC.
@iBooM72 thank you for the review, and for checking the shader-write case. - Both switches together: agreed. The private-memory gain is in the rows with the drain of #332 (11, 13, 17, 19, 21); this one alone is its base. - Frees that reach `paged_freed`: thank you for naming the two paths, I read the code the same way. With nothing in place, the runtime's unmaps and remaps reach it (`title_memory_changed`), the title's own `VirtualFree` does not (`holds_any()`), until #321. So the dead tiles counted in the drives (about 1.2 GB at the end of a drive without the switch) came from the first path. With #321: not measured here. - `UpdateTileMappings`: agreed, a tester with a weaker CPU is what is missing. I only have this PC.
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 'page-dead-tiles:Cyber-Croissant-page-dead-tiles'
git switch 'Cyber-Croissant-page-dead-tiles'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'Cyber-Croissant-page-dead-tiles'
git switch 'Cyber-Croissant-page-dead-tiles'
git rebase 'main'
git switch 'main'
git merge --ff-only 'Cyber-Croissant-page-dead-tiles'
git switch 'Cyber-Croissant-page-dead-tiles'
git rebase 'main'
git switch 'main'
git merge --no-ff 'Cyber-Croissant-page-dead-tiles'
git switch 'main'
git merge --squash 'Cyber-Croissant-page-dead-tiles'
git switch 'main'
git merge --ff-only 'Cyber-Croissant-page-dead-tiles'
git switch 'main'
git merge 'Cyber-Croissant-page-dead-tiles'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!319
No description provided.