WIP: [pr-performance][memory] DARNER_PAGE_DRAIN: the emptiest pool heap of page buffers is emptied and goes back (mode 3, off by default) #332

Draft
Cyber-Croissant wants to merge 2 commits from Cyber-Croissant/Darner:page-drain into main
Contributor

Contributor role (optional)

  • Fluxer ID: 1576300404596027392 (CyberCroissant#5122)

What it changes

  • The problem on main: the page-buffer report's own numbers. In mode 3 a heap of the pool goes back only when its last tile happens to be freed, so heaps stay for a few tiles each. At the end of 12 min drives the pool's heaps held 221 to 469 MB more than the tiles in use without any switch (rows 6, 9, 10, 14 below), and 757 to 995 MB more once #319 gives dead tiles back (rows 2, 5, 12): the tiles it frees are spread over heaps that stay.

With DARNER_PAGE_DRAIN=1 the heap of the pool in the PC's memory with the fewest tiles in use is chosen when the other heaps have room for its tiles and 16 MB more. Its free tiles are given to nobody. The windows written straight in move their tiles of it to other heaps at their next take, in the order of the queue: the bytes are copied by the CPU under the window's write gate, the tiles are mapped at their new place ahead of the take's send, and the old tiles go back once the submissions in the air have finished. The heap goes back when its last tile is free. One heap at a time, 10 s of rest after each, and a heap not empty after 60 looks (one look in 30 frames) is left as it is.

Off by default: with the switch unset no heap is chosen and nothing moves. The counters are behind the diagnostics feature.

This is a draft on top of #319 (the give-back of tiles under freed title memory); the diff shows both commits until #319 lands, and only the second is this change. Order: #319 first. This one stays a draft (WIP) until #319 is merged; then I take the WIP off and it can be reviewed and merged in turn. The WIP in the title stands for that dependency only: the measurements below are done. Results from more testers and more reviewers would still help a lot: everything below comes from one PC, one route and one card.

How it was tested

  • Tested revision: 8354d13e (on e5abccd9 of #319, 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 the same code as 8354d13e but for one comment line and the README. No drive has run on 8354d13e itself yet.

  • Commands and results:

    • cargo test -p darner-gpu --features diagnostics --lib pagebuf::: 7 passed, 5 ignored (the ignored ones need a card). The new one is the_emptiest_heap_is_emptied_when_the_others_have_room (the choice of the heap).
    • the_emptiest_heap_of_the_pool_is_emptied_and_goes_back_in_mode_three (new, ignored by default, run by name with DARNER_ADAPTER, DARNER_PAGE_BUFFERS=3, DARNER_PAGE_DRAIN=1): passed on the RTX 5070 the drives ran on, and on the PC's integrated AMD adapter. Through the real path of a submission: two windows written straight in fill a heap and start a second; the first window goes, the heap it leaves almost empty is chosen, the other window's tiles in it move at its next send with nothing written, shaders read them at their new place, and the heap goes back once the submissions have run.
    • #319's card test and the existing mode-3 round trip: passed with DARNER_PAGE_DRAIN=1 set too, 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 8354d13e (not in this PR), with the game closed.
    • cargo check -p darner (no diagnostics feature): 0 warnings.
  • 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). "DRAIN" is DARNER_PAGE_DRAIN=1, "D60" is DARNER_PAGE_DEAD_S=60 of #319, "D10" is 10, "PACK" is DARNER_PAGE_PACK=1. The same table is in #319.

    # 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:

    • With PACK, D60 and DRAIN (rows 4, 7, 8 on the old base; 11, 13, 17, 19 on the new) the pool's heaps end at 2,048 to 2,560 MB, within 15 to 132 MB of the tiles in use, against 3,584 to 3,968 MB without any switch. 50 to 57 heaps of 64 MB went back in a drive on the old base, 51 to 57 on the new, where none was given up.
    • Private memory over the last tenth, same rows: 23.85, 24.45, 24.75 GB against 25.45 and 25.69 on the old base; 22.84, 22.94, 22.57 and 23.01 against 24.08, 24.36, 24.42 and 24.38 on the new one (1.1 to 1.9 GB lower, no overlap).
    • DRAIN without D60 (row 15, one drive): 47 heaps went back and the heaps end 37 MB over the tiles, but there are few free tiles to gain: heaps 3,520 MB, private 24.10 GB, inside the drives without any switch. Each switch alone shows no private-memory gain here; the two together do, in the eight drives of eight that had both (rows 4, 7, 8, 11, 13, 17, 19, 21).
    • Without PACK (row 21: D60 DRAIN, one drive): heaps 2,112 MB, 26 MB over the tiles, 56 heaps gone back, private 22.76 GB, the same as with PACK. PACK alone (row 18) changes neither heaps nor private memory (3,712 MB, 24.29 GB).
    • Frame time: 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; the four with PACK D60 DRAIN (11, 13, 17, 19) 26.5 to 27.8 fps, 69.1 to 74.9 ms and 39.6 to 42.1 ms; row 21 (no PACK) 28.1 fps, 70.7 ms and 39.5 ms. An earlier version of this text gave a cost (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): mean frame 34.8, 32.5, 32.7, 34.1 ms; p99 49.8, 49.3, 47.8, 50.1 ms; pool heaps at the end 1,536, 1,472, 1,344, 1,664 MB; private 19.18, 18.97, 18.90, 19.76 GB; 6 and 5 heaps gone back. 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; standing still there is little to give back.
    • UpdateTileMappings calls: 53,494 to 57,742 a drive with D60 and DRAIN (rows 11, 13, 17, 19, 21) against 24,911 to 26,695 without any switch; 27,291 with DRAIN and no D60.
    • Tiles moved by the drain: 17,992 to 21,755 a drive with D60 (rows 11, 13, 17, 19, 21), 16,397 without (row 15). Each is a 64 KiB copy by the CPU.
    • 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.
    • 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 8354d13e: 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,774 (host::refresh_tests::chunked_nothing_new_with_matches_individual, watch::tests::ask_once_by_res_splits_reservations_without_refusals), neither in the files this touches. cargo test -p darner-gpu --lib --locked 20 times: 9 runs failed, against 10 of 20 on main f3840d73; the tests that fail are those of watch and host that fail on main, and one more of the same kind (write-watched memory), descriptor::tests::records_copied_as_bytes_are_made_at_the_next_sync, in 2 runs of 26 here and none of 26 on main: I cannot say whether that one is chance. With --test-threads=1: 1,757 passed, 0 failed. The rest of the workspace but darner-shader: 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 or for heaps on the card.

  • 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.
    • Frame time: four drives per arm on current main, and the spread inside an arm (1.3 fps of mean, 2.5 and 5.8 ms of p99) is larger than any difference between the arms.
    • No drive on 8354d13e itself.
    • Nothing under a RAM limit (16 GB) or a small card, which is where the memory would matter most.
    • Without DARNER_PAGE_PACK=1: one drive (row 21).
    • The peak of private memory is lower on the new base (23.32 and 23.53 GB against 24.22 and 24.49) and was not on the old one (24.80 to 25.82 against 25.54 and 25.91).
    • The copy of a tile's bytes runs under the window's write gate taken without waiting; if a write straight in is under way nothing moves that time. I have tested this by the card test only, not under contention.
    • 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.

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 #319 (the drain moves the tiles that #319's give-back leaves spread over heaps; alone it shows no gain, and its code sits on #319's)

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #319 (prerequisite). #221 (windows tile by tile by adapter; same file and functions, different subject). #321 (a title free reaches the paged copies even with nothing in place): see #319. It changes how many tiles #319 can give back, so how much this change has to gather; not measured. #274 ("Drain retirement queues") is about the host's retirement queues, not the tile pool, despite the word. #310 and #300 touch shadow.rs for landed ranges. Closed: #56, #59, #62 (pools and windows; none empties a pool heap). Issues: #111, #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", "drain", 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: the page-buffer report's own numbers. In mode 3 a heap of the pool goes back only when its last tile happens to be freed, so heaps stay for a few tiles each. At the end of 12 min drives the pool's heaps held 221 to 469 MB more than the tiles in use without any switch (rows 6, 9, 10, 14 below), and 757 to 995 MB more once #319 gives dead tiles back (rows 2, 5, 12): the tiles it frees are spread over heaps that stay. With `DARNER_PAGE_DRAIN=1` the heap of the pool in the PC's memory with the fewest tiles in use is chosen when the other heaps have room for its tiles and 16 MB more. Its free tiles are given to nobody. The windows written straight in move their tiles of it to other heaps at their next take, in the order of the queue: the bytes are copied by the CPU under the window's write gate, the tiles are mapped at their new place ahead of the take's send, and the old tiles go back once the submissions in the air have finished. The heap goes back when its last tile is free. One heap at a time, 10 s of rest after each, and a heap not empty after 60 looks (one look in 30 frames) is left as it is. Off by default: with the switch unset no heap is chosen and nothing moves. The counters are behind the `diagnostics` feature. This is a draft on top of #319 (the give-back of tiles under freed title memory); the diff shows both commits until #319 lands, and only the second is this change. **Order: #319 first.** This one stays a draft (WIP) until #319 is merged; then I take the WIP off and it can be reviewed and merged in turn. The WIP in the title stands for that dependency only: the measurements below are done. **Results from more testers and more reviewers would still help a lot**: everything below comes from one PC, one route and one card. ## How it was tested - Tested revision: `8354d13e` (on `e5abccd9` of #319, 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 the same code as `8354d13e` but for one comment line and the README. No drive has run on `8354d13e` itself yet. - Commands and results: - `cargo test -p darner-gpu --features diagnostics --lib pagebuf::`: 7 passed, 5 ignored (the ignored ones need a card). The new one is `the_emptiest_heap_is_emptied_when_the_others_have_room` (the choice of the heap). - `the_emptiest_heap_of_the_pool_is_emptied_and_goes_back_in_mode_three` (new, ignored by default, run by name with `DARNER_ADAPTER`, `DARNER_PAGE_BUFFERS=3`, `DARNER_PAGE_DRAIN=1`): passed on the RTX 5070 the drives ran on, and on the PC's integrated AMD adapter. Through the real path of a submission: two windows written straight in fill a heap and start a second; the first window goes, the heap it leaves almost empty is chosen, the other window's tiles in it move at its next send with nothing written, shaders read them at their new place, and the heap goes back once the submissions have run. - #319's card test and the existing mode-3 round trip: passed with `DARNER_PAGE_DRAIN=1` set too, 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 `8354d13e` (not in this PR), with the game closed. - `cargo check -p darner` (no `diagnostics` feature): 0 warnings. - 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). "DRAIN" is `DARNER_PAGE_DRAIN=1`, "D60" is `DARNER_PAGE_DEAD_S=60` of #319, "D10" is 10, "PACK" is `DARNER_PAGE_PACK=1`. The same table is in #319. | # | 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: - With PACK, D60 and DRAIN (rows 4, 7, 8 on the old base; 11, 13, 17, 19 on the new) the pool's heaps end at 2,048 to 2,560 MB, within 15 to 132 MB of the tiles in use, against 3,584 to 3,968 MB without any switch. 50 to 57 heaps of 64 MB went back in a drive on the old base, 51 to 57 on the new, where none was given up. - Private memory over the last tenth, same rows: 23.85, 24.45, 24.75 GB against 25.45 and 25.69 on the old base; 22.84, 22.94, 22.57 and 23.01 against 24.08, 24.36, 24.42 and 24.38 on the new one (1.1 to 1.9 GB lower, no overlap). - DRAIN without D60 (row 15, one drive): 47 heaps went back and the heaps end 37 MB over the tiles, but there are few free tiles to gain: heaps 3,520 MB, private 24.10 GB, inside the drives without any switch. **Each switch alone shows no private-memory gain here; the two together do, in the eight drives of eight that had both (rows 4, 7, 8, 11, 13, 17, 19, 21).** - Without PACK (row 21: D60 DRAIN, one drive): heaps 2,112 MB, 26 MB over the tiles, 56 heaps gone back, private 22.76 GB, the same as with PACK. PACK alone (row 18) changes neither heaps nor private memory (3,712 MB, 24.29 GB). - **Frame time: 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; the four with PACK D60 DRAIN (11, 13, 17, 19) 26.5 to 27.8 fps, 69.1 to 74.9 ms and 39.6 to 42.1 ms; row 21 (no PACK) 28.1 fps, 70.7 ms and 39.5 ms. **An earlier version of this text gave a cost (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): mean frame 34.8, 32.5, 32.7, 34.1 ms; p99 49.8, 49.3, 47.8, 50.1 ms; pool heaps at the end 1,536, 1,472, 1,344, 1,664 MB; private 19.18, 18.97, 18.90, 19.76 GB; 6 and 5 heaps gone back. 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; standing still there is little to give back. - `UpdateTileMappings` calls: 53,494 to 57,742 a drive with D60 and DRAIN (rows 11, 13, 17, 19, 21) against 24,911 to 26,695 without any switch; 27,291 with DRAIN and no D60. - Tiles moved by the drain: 17,992 to 21,755 a drive with D60 (rows 11, 13, 17, 19, 21), 16,397 without (row 15). Each is a 64 KiB copy by the CPU. - 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. - 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 `8354d13e`: `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,774 (`host::refresh_tests::chunked_nothing_new_with_matches_individual`, `watch::tests::ask_once_by_res_splits_reservations_without_refusals`), neither in the files this touches. `cargo test -p darner-gpu --lib --locked` 20 times: 9 runs failed, against 10 of 20 on main `f3840d73`; the tests that fail are those of `watch` and `host` that fail on main, and one more of the same kind (write-watched memory), `descriptor::tests::records_copied_as_bytes_are_made_at_the_next_sync`, in 2 runs of 26 here and none of 26 on main: I cannot say whether that one is chance. With `--test-threads=1`: 1,757 passed, 0 failed. The rest of the workspace but `darner-shader`: 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 or for heaps on the card. - 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. - Frame time: four drives per arm on current main, and the spread inside an arm (1.3 fps of mean, 2.5 and 5.8 ms of p99) is larger than any difference between the arms. - No drive on `8354d13e` itself. - Nothing under a RAM limit (16 GB) or a small card, which is where the memory would matter most. - Without `DARNER_PAGE_PACK=1`: one drive (row 21). - The peak of private memory is lower on the new base (23.32 and 23.53 GB against 24.22 and 24.49) and was not on the old one (24.80 to 25.82 against 25.54 and 25.91). - The copy of a tile's bytes runs under the window's write gate taken without waiting; if a write straight in is under way nothing moves that time. I have tested this by the card test only, not under contention. - 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. ## 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 #319 (the drain moves the tiles that #319's give-back leaves spread over heaps; alone it shows no gain, and its code sits on #319's) ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #319 (prerequisite). #221 (windows tile by tile by adapter; same file and functions, different subject). #321 (a title free reaches the paged copies even with nothing in place): see #319. It changes how many tiles #319 can give back, so how much this change has to gather; not measured. #274 ("Drain retirement queues") is about the host's retirement queues, not the tile pool, despite the word. #310 and #300 touch `shadow.rs` for landed ranges. Closed: #56, #59, #62 (pools and windows; none empties a pool heap). Issues: #111, #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", "drain", 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]>
The heap of the pool in the PC's memory with the fewest tiles in use is
chosen when the other heaps have room for its tiles and a spare. Its free
tiles are given to nobody; the windows written straight in move their
tiles of it to other heaps at their next take, the bytes copied by the
CPU, and the old tiles go back once the submissions in the air have
finished. The heap goes back when its last tile is free. One heap at a
time, a rest after each, and a heap not empty after 60 looks is left as
it is.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Contributor

Code review only (read 8354d13e, this PR's own commit on top of #319's e5abccd9), nothing built or run. It merges cleanly onto main today (git merge-tree). The "not mergeable" flag is the draft state.

  • A heap that can't empty may be picked again and again. take_drain moves only tiles of direct windows (not on the card, not hot). So a heap that also holds a tile that can't move (non-direct takes may use the same CPU-visible heaps) would never empty, and is given up after 60 looks. After the 10 s rest, drain_choice has no memory of it and likely picks the same heap again (most free tiles). Each round keeps the pool's largest free space unused for about a minute (take_from skips draining heaps), which can push new tiles into new heaps. The "given up" counter would show it. Remembering given-up heaps for a few minutes, or skipping heaps with tiles that can't move, would avoid it.
  • The rest looks right. The copy runs under the write gate, on windows with no shader writes, with the old tile kept until retire. Lock order is gate/state → pool, and the pool lock never takes a window's state.
  • The 1.1–1.9 GB private-memory gain is what matters for the RAM reports. More testers on other PCs, with both switches, would be the best way to move this forward.

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

Code review only (read `8354d13e`, this PR's own commit on top of #319's `e5abccd9`), nothing built or run. It merges cleanly onto main today (`git merge-tree`). The "not mergeable" flag is the draft state. - **A heap that can't empty may be picked again and again.** `take_drain` moves only tiles of direct windows (not on the card, not hot). So a heap that also holds a tile that can't move (non-direct takes may use the same CPU-visible heaps) would never empty, and is given up after 60 looks. After the 10 s rest, `drain_choice` has no memory of it and likely picks the same heap again (most free tiles). Each round keeps the pool's largest free space unused for about a minute (`take_from` skips draining heaps), which can push new tiles into new heaps. The "given up" counter would show it. Remembering given-up heaps for a few minutes, or skipping heaps with tiles that can't move, would avoid it. - The rest looks right. The copy runs under the write gate, on windows with no shader writes, with the old tile kept until `retire`. Lock order is gate/state → pool, and the pool lock never takes a window's state. - The 1.1–1.9 GB private-memory gain is what matters for the RAM reports. More testers on other PCs, with both switches, would be the best way to move this forward. Reviewed with Claude Code (AI-assisted); findings checked by a human before posting.
This pull request is marked as a work in progress.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'page-drain:Cyber-Croissant-page-drain'
git switch 'Cyber-Croissant-page-drain'

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-drain'
git switch 'Cyber-Croissant-page-drain'
git rebase 'main'
git switch 'main'
git merge --ff-only 'Cyber-Croissant-page-drain'
git switch 'Cyber-Croissant-page-drain'
git rebase 'main'
git switch 'main'
git merge --no-ff 'Cyber-Croissant-page-drain'
git switch 'main'
git merge --squash 'Cyber-Croissant-page-drain'
git switch 'main'
git merge --ff-only 'Cyber-Croissant-page-drain'
git switch 'main'
git merge 'Cyber-Croissant-page-drain'
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!332
No description provided.