Skip to content

perf(kyty): memory-tracking reads cost about 19 % of Execute in METAL GEAR SOLID 4 (MappedPrefix, IsBacked, StillValid, FirstClamp) #24

Open

Description

@Raghav314

Summary

In METAL GEAR SOLID 4 (PPSA18194) on the Kyty backend, about 19 % of kytyGpuExecute's time is memory tracking in user code (MappedPrefix, GuestReadLog::StillValid, Shim::IsBacked, IsRegionCpuModified), and another 2–4 % is write-tracking faults, mprotect and the TLB-flush interrupts they cause. Binding and descriptor work is about 14–15 %.

A suggested design is below the measurements.

Measurements

Linux (CachyOS, kernel 7.3), Ryzen 7 7800X3D, RTX 4090 (NVIDIA 620.70.06). AnyKyty at 177ca381a1 plus #19, #23 and #27. Act 1, standing still, two spots, 30 s each, warm shader and pipeline caches. Uncapped: ANYPS5_VBLANK_HZ=360 KYTY_VBLANK_FREQUENCY=360 ANYPS5_FPS_LIMIT=360 APS5_UNPACED_FLIPS=1 KYTY_PRESENT_MODE=Immediate, and the game's own frame limiter patched out (its wait period set to 0) so the frame rate is not held at the game's target.

MGS4 Act 1 FPS (mean) FPS (median) 1% low Worst frame GPU busy
Spot A 199.5 204.0 130 8.31 ms 78 %
Spot B 173.6 176.6 130 7.90 ms 69 %

kytyGpuExecute, 10 s perf record at 3 kHz:

Share of samples Spot A Spot B
Waiting for work (SpscQueue::WaitForElement) 14.8 % 11.6 %
Memory tracking, user code 19.3 % 19.5 %
Kernel 6.8 % 4.1 %
Binding and descriptors (CommitBindings, RebindBuffers, templates, push descriptors) 13.7 % 15.2 %
Other draw work 39.1 % 43.0 %
libc, clock 5.7 % 6.0 %

Memory tracking at spot B: MappedPrefix 7.5 % (about half from ClampRangeSize on buffers that reach past mapped memory, the rest from IsFullyMapped), GuestReadLog::StillValid 5.1 %, Shim::IsBacked 4.5 %, IsRegionCpuModified 1.0 %.

Kernel, resolved against /proc/kallsyms (spot A / spot B): mprotect 2.4 % / 1.0 %, TLB-flush interrupts (sysvec_call_function) 1.6 % / 1.5 %, write-fault handling and signal delivery 0.9 % / 0.3 %.

Page faults (perf stat -e page-faults, 5 s): spot A 6,250/s on kytyGpuExecute and 20,400/s for the process; spot B 2,730/s and 17,300/s.

Suggested design

A general direction, not a finished plan; the details depend on what each existing check guards.

  1. One owner record per guest range. A single table, keyed by fixed-size blocks (for example 64 KiB), says who owns each range and how much of it is mapped: CPU, a pending GPU write, a render target or depth surface, or nothing. The per-draw checks that now ask separate questions (Shim::IsBacked, MappedPrefix, IsRegionCpuModified) read this one record instead, including the mapped length that ClampRangeSize recomputes for the same buffers on every draw. Readers do not take a lock; writers publish changes.
  2. Versions instead of re-checking. Each block has a version that any write to it bumps (CPU write fault, GPU write, unmap). A cached draw, template or resource keeps the versions of the blocks it read. To revalidate, it compares those versions; only on a mismatch does it run the full check that GuestReadLog::StillValid does today. A version moves only when the block's state changes, so repeated writes to an already-dirty block cost nothing.
  3. Fewer fault round trips. A write fault marks the block dirty, bumps its version and leaves the block writable. Dirty blocks are re-protected in one batch when their contents are next consumed (at submission or the next revalidation), and only then read, so a write that lands after the re-protection faults again and is not lost. This also cuts the TLB-flush interrupts each mprotect sends to other cores. It is the smaller part here (2–4 % of kytyGpuExecute).
  4. A verify mode. A switch that runs the old checks next to the new answers and stops on any difference, so each step can be validated in game before the old path is removed.

Steps, each measured like the tables above: owner record behind a switch with verify mode; versions for draw and template revalidation; batched re-protection; then remove the old checks the record replaces. The adaptations would live in the shim or under #if defined(ANYPS5_KYTY), so the imported files stay re-importable.

Method and limitations

  • AnyPS5's trace capture (APS5_TRACE_DIR, aps5-summary.jsonl, tools/trace_digest.py) is stubbed out in the Kyty backend (KytyShim/src/EntryHost.cpp, AgcDriverTraceRecording returns false), so these numbers come from MangoHud and perf instead.
  • FPS, 1% low and worst frame come from a MangoHud log at 100 ms intervals, so the 1% low and worst frame are approximate.
  • Shares are self time per function, grouped by name; the groups are approximate.
  • One session, two spots; the spots differ in scene, so the two columns show the range, not a controlled A/B.
  • The game executable was patched only in its frame limiter.

Activity

  1. changed the title [-]perf(kyty): memory tracking takes up to 40 % of kytyGpuExecute in MGS4[/-] [+]perf(kyty): memory tracking takes about 20 % of kytyGpuExecute in MGS4[/+] on Nov 17, 2026
  2. Raghav314 commented on Nov 17, 2026

    @Raghav314
    Author

    Corrected the description. The first version put kytyGpuExecute's kernel time (up to 24 %) down to write-tracking faults. Resolving the kernel samples showed it was almost all write() calls from the per-draw clamp message in ClampRangeSize. #27 fixes that: at spot B it goes from 124 to 174 fps. The numbers above are measured again with #27: memory tracking is about 20 % of kytyGpuExecute, not up to 40 %.

  3. simnJS commented on Nov 17, 2026

    @simnJS
    Owner

    Thanks, these numbers line up with what we measure on Subnautica. Two pieces of this are already in progress on our side, so here they are to avoid overlap:

    • Fault round trips (your point 3): feat/kyty-eager-readback stops protecting, faulting and reading back, on every frame, the ranges a compute pass writes and the CPU then reads. Instead it reads them back ahead of the CPU, before the label. The ceiling measured on Subnautica is +15.7 % fps. It's under review and not merged yet.
    • Versions instead of re-checking, on the Resolve side: a prototype that reuses a draw's resource materialization when the pages it read have the same version.

    Your read-path part, the owner record per block with MappedPrefix, IsBacked, StillValid and IsRegionCpuModified answered from it plus a verify mode, is not covered by either, and it's the biggest share in your profile. If you want it, it's yours; we'll keep to faults/readback and Resolve. Behind a switch with the verify mode, as you describe, is exactly what we'd want.

  4. Raghav314 commented on Nov 17, 2026

    @Raghav314
    Author

    Thanks for laying that out. I'd rather you take the read-path part as well. It touches the same page state as your readback and Resolve work, so having one owner keep the owner record, the versions and the protection in step seems simpler than splitting them between us. One thing worth deciding up front: the page versions in your Resolve prototype could be the same versions the owner record keeps, so there is one version table rather than two. I'm happy to test any of it on MGS4 and title A with the same measurements as above.

    (edited by maintainer)

  5. simnJS commented on Nov 17, 2026

    @simnJS
    Owner

    Fair enough, we'll take the read-path part too, with a single page-version table shared with the Resolve work, as you suggest. It'll start after the current batch lands; we'll ping you for MGS4 and title A runs when there's something to test.

  6. simnJS commented on Nov 18, 2026

    @simnJS
    Owner

    We measured the ceiling before building the registry. A throwaway prototype answers every check from memoized results with no validation at all (IsBacked, MappedPrefix, IsFullyMapped, ClampRangeSize, FindBackingPointer, IsRegionCpuModified). It gains nothing in our games:

    Game Before Ceiling
    Subnautica (uncapped) 111.6 fps 111.1 fps
    Stray, heavy scene (~4,250 draws/frame) 55.5 fps 55.6 fps
    Stray, light scene 71.9 fps 72.0 fps

    Memory tracking is about 7% of kytyGpuExecute here, against 19.5% in your MGS4 profile, and Execute is not the stage that limits these games.

    What looks specific to MGS4 is the slow path of ClampRangeSize on buffers that run past the mapped range: MappedPrefix is walked twice, and FirstClamp takes a lock and a std::set on every call. None of our games takes that path, so we're not building the full registry for now.

    If MGS4 is still slow there, a targeted fix of that path (cache the clamp result per buffer range until an unmap) should get most of it. Happy to share the ceiling prototype if you want to check it on MGS4 first.

  7. Raghav314 commented on Nov 18, 2026

    @Raghav314
    Author

    Thanks for measuring the ceiling first. I think the difference is which stage limits the game, and title A is limited by the one your games aren't.

    Title A, story mode, fixed spot, RTX 4090, simnJS/AnyKyty with native RT plus two local fixes, heap off:

    Thread Load
    kytyGpuExecute 97%
    kytyGpuRecord 100%
    kytyGpuResolve 100%
    game main thread 100%
    GPU 80–86% busy

    So Execute is a bottleneck here: 67.9 fps, p50 14.7 ms, with the GPU waiting on it. A 10 s profile of kytyGpuExecute (inclusive shares) shows:

    Function Share of Execute
    BufferCache::ObtainBuffer 7.7%
    … of which ReadMemoryAsync → UpdatePageWatchers → mprotect 6.1%
    GuestReadLog::StillValid 5.1% (4.0% self)

    That's about 13% of the limiting thread. Neither part is on the ClampRangeSize slow path: Title A doesn't take it. Your ceiling list also doesn't include StillValid or the watcher re-protection. That is where title A spends its time:

    • re-arming write protection on pages a draw reads;
    • re-validating read logs entry by entry.

    This is why I think the version model is needed rather than a per-path fix:

    • StillValid would become one version compare per block instead of a walk over the logged reads.
    • Protection would only change when a page's version moves, instead of on every ReadMemoryAsync.

    In title A the protection side is what costs. So the shared page-version table is the part that matters; the memoized read checks alone wouldn't show it.

    The test that would settle it is your ceiling prototype run on title A and MGS4, ideally with StillValid and the watcher updates answered from memo too. If you can share it, I'll run both games at the same spots and post before/ceiling numbers in the same format as yours.

    (edited by maintainer)

  8. simnJS commented on Nov 18, 2026

    @simnJS
    Owner

    Fair point, and thanks for the profile: if Execute is the wall in title A, our two games can't settle it, and StillValid and the watcher re-protection weren't in our ceiling.

    We're extending the ceiling prototype to cover both: StillValid answered from a memo, and UpdatePageWatchers skipping the re-protection. Each part gets its own switch, plus one switch for everything. We'll publish it as a branch on top of the current AnyKyty, with the switches and how to read the results, so you can run title A and MGS4 at the same spots. I'll post the link here, probably in a few hours.

  9. simnJS commented on Nov 18, 2026

    @simnJS
    Owner

    Thanks for the profile, it was very useful. Here is a ceiling build that covers GuestReadLog::StillValid and the mprotect calls of the memory tracker, so you can measure on title A and MGS4 what they would give at most.

    Branch proto/memory-tracking-ceiling: one commit on top of AnyKyty 52f1faa881. Build it like AnyKyty on Linux (-DANYPS5_GPU_BACKEND=kyty, targets kyty_gpu libs relinker). The commit message lists every switch and every log line.

    This is a measurement build, not for playing. The levers answer from stale data on purpose: frames can be wrong, the scene can change, and a game can hang. Stray hangs while loading if write protection is skipped from the start; KYTY_CEIL_START_S (below) avoids it.

    Switches (environment variables):

    • KYTY_REG_CEIL=all-ab turns everything on and off every 10 s in the same session; this is the one to run first. all keeps it on. on/ab are the first prototype (unvalidated memo of the address queries: IsBacked, MappedPrefix, IsFullyMapped, ClampRangeSize, FindBackingPointer, IsRegionCpuModified; StillValid skipped). stats only counts.
    • KYTY_STILLVALID_CEIL=memo|skip: memo checks a read log once per period and then answers from a per-thread memo, with no byte comparison, no MayFaultOnGpuRead and no descriptor refresh; skip always answers valid. (The first prototype already skipped StillValid in on/ab; it now has its own switch.)
    • KYTY_REARM_CEIL=protected|skip: the write protection the tracker puts back after an upload (SynchronizeBuffer → ForEachUploadRange → UpdatePageWatchersForRegion → mprotect). protected skips the call when the pages already have that protection; skip never puts it back, so later CPU writes go unseen (the protections are applied again when a period turns off).
    • KYTY_CEIL_AB=1 alternates any of these every 10 s; KYTY_CEIL_START_S=60 keeps everything off for the first 60 s after the first draw, so the game loads normally.

    Reading it: the [reg] period lines on stderr give, every 10 s, on=0|1, fps, draws_per_frame, and the CPU µs per draw and busy share of the Resolve, Execute and Record threads. Compare on=1 with the neighbouring on=0 periods, at the same draws_per_frame. The [reg] counts lines give, per thread, every mprotect of the page manager by kind with its cycles: rearm (write protection put back after an upload), wunwatch (removed after a CPU write), rwatch/runwatch (no-access protection put on GPU-written pages, and removed after a readback), otherprot. On kytyGpuExecute, cycles ÷ draws of the period is the time Execute spends in mprotect per draw, without skipping anything.

    One thing we found: in the code, ReadMemoryAsync → ReleaseReadback → UpdatePageWatchers → mprotect is the removal of a read watcher (a page the GPU wrote and the CPU then read), not the write re-protection. Read watchers cannot be skipped: when we tried, Stray stopped at once ("unknown op", the command processor read commands the GPU had written) and so did Subnautica. So this build only counts them (rwatch/runwatch). If they are what Execute pays on title A, the counters will show it, and the answer is a different design (fewer protection changes for GPU-written pages), not a ceiling.

    Our numbers (Ryzen 9 7950X3D, RTX 4080 SUPER, Linux, uncapped, all-ab with KYTY_CEIL_START_S=50, 11 periods of 10 s):

    • protected never fires on our games (0 % of re-protections skipped): the watcher counts already avoid redundant calls.
    • Stray (≈ 4,230 draws per frame): Execute 2.78 µs per draw with or without the ceiling, Execute busy 83 %. Skipping write protection changes the scene (4,770 draws per frame in every "on" period), so the fps do not compare (70.4 off, 65.5 on). The page manager's mprotect calls cost Execute 0.07 µs per draw.
    • Subnautica (≈ 900 draws per frame): 165.5 → 173.3 fps on average, +1 to +3.5 % between neighbouring periods, inside the drift of the scene; Execute 3.60 → 3.56 µs per draw, busy 54 %, so not the bottleneck. mprotect costs Execute 0.47 µs per draw (13 % of its time): 0.35 for read watchers, 0.075 for write re-protection.
    • Each mprotect costs 2 to 14 µs here (60+ threads in the process).

    On our games Execute is not the stage that sets the frame time, so even a ceiling gives little. Your case is different (Execute at 97 %), which is why your numbers on title A and MGS4 matter more than ours. If you can, please post the [reg] period lines of one all-ab run and the [reg] counts lines of kytyGpuExecute.

  10. Raghav314 commented on Nov 18, 2026

    @Raghav314
    Author

    Thanks, I'll run all-ab on MGS4 first, then title A. I can't find proto/memory-tracking-ceiling though: https://github.com/simnJS/AnyPS5/tree/proto/memory-tracking-ceiling returns 404 and it isn't in git ls-remote (only its base, 52f1faa, is reachable). Could you push it?

  11. simnJS commented on Nov 18, 2026

    @simnJS
    Owner

    @Raghav314 pushed back: proto/memory-tracking-ceiling is at b2c87bb again (same commit, on its original base 52f1faa). It merges cleanly into the current AnyKyty.

  12. Raghav314 commented on Nov 19, 2026

    @Raghav314
    Author

    MGS4 and GTA V (uncapped, RTX 4090, Linux) on proto/memory-tracking-ceiling. MGS4 ran b2c87bb on 52f1faa as is; GTA V ran it cherry-picked onto the current AnyKyty (32b1173, applies cleanly), because on 52f1faa GTA V runs at 35 fps at this spot instead of ~115, with the GPU at 50 %, and the levers were flat there (on 34.4/34.7, off 35.2/33.6).

    GTA V (Performance RT, KYTY_REG_CEIL=ab, standing still)

    ab gives about +6 % in GTA V, and every on period beats its neighbours. Draws per second at 2,890-3,110 draws per frame:

    on off neighbours change vs their mean
    372.5 k (123.1 fps) 364.2 k (117.0), 332.7 k (115.1) +6.9 %
    356.7 k (119.9 fps) 332.7 k (115.1), 342.8 k (114.4) +5.6 %

    Over all three in-game on periods (the first, 368.4 k, follows a loading period) and three off periods: 365.9 k vs 346.6 k draws/s (+5.6 %), 123.2 vs 115.5 fps (+6.7 %). Memo hits as in MGS4: clamp 48-50 %, cpumod 62 %, backed 7 %, findback 3 %, fullmap and mayfault 0 %; the address queries per draw drop from 16.4 to 10.9, mostly the StillValid → MayFaultOnGpuRead calls. So this is again mostly the StillValid ceiling.

    mprotect on kytyGpuExecute in GTA V: ≈ 0.20-0.26 µs per draw (≈ 7-9 % of the 2.9 µs of wall time per draw), without skipping anything:

    kind calls / 10 s µs per draw
    runwatch 177-290 k 0.065-0.107
    otherprot 11.8-13.6 k 0.08-0.12
    rwatch 19-21 k 0.028-0.035
    wunwatch 2.3-3.5 k 0.005-0.007
    rearm 3.5-5.9 k 0.004-0.007

    Unlike MGS4, GTA V pays on Execute for read watchers (removal after a readback) and otherprot (textures, image heap, strict watch), the case you describe as needing fewer protection changes for GPU-written pages rather than a ceiling. Rearm is small.

    MGS4 (Act 1)

    all-ab hangs MGS4 the moment it turns on, twice. With KYTY_CEIL_START_S=60 (still loading) and with =180 (in game, standing still): the log stops at the first on=1 period and the GPU hangs about 2 s later (Xid 109, CTX SWITCH TIMEOUT). Every on=0 period before that is clean, so there is no on period to compare. With KYTY_REG_CEIL=ab (no write-protection skip) it runs, so the hang is the rearm skip.

    ab in game: within the scene's drift, and the memo mostly misses. Draws per second, the throughput of the saturated Execute thread, on vs the neighbouring off periods at the same draws per frame:

    on period neighbours (off) change
    484.8 k draws/s (205.6 fps, 2,358 dpf) 476.5 k (2,377), 478.3 k (2,331) +1.5 %
    472.0 k (200.9 fps, 2,349 dpf) 478.3 k (2,331), 472.5 k (2,367) −0.7 %

    The later periods moved with the scene (1,830-2,490 dpf), so they don't pair. Hits per call in the on periods: StillValid skipped 100 %, clamp 60-67 %, cpumod 11 %, backed 4 %, findback 2 %, fullmap, prefix and mayfault 0 %. Skipping StillValid also takes MayFaultOnGpuRead from ~23 M to ~4.5 M calls per 10 s. So in MGS4 ab is mostly a StillValid ceiling: worth about 0-1.5 % here. The per-thread address memo barely hits, so it says little about what an owner-record design could save on the other ~14 queries per draw.

    mprotect on kytyGpuExecute is not the cost in MGS4. 14 in-game on=0 periods, 2,450-2,980 draws per frame, 152-195 fps:

    kind on kytyGpuExecute calls / 10 s µs per draw
    rearm 0 0
    wunwatch 8,600-29,300 0.022-0.028
    rwatch / runwatch 0 0
    otherprot 0-58 ≤ 0.0002

    About 4.7 µs per wunwatch call. At about 2.1 µs of wall time per draw, that's about 1 %.

    The re-protection happens on the game's threads instead: rearm 144-157 k calls and 3.2-3.4 G cycles per 10 s (≈ 0.8 s of CPU), and wunwatch 153-168 k calls (≈ 0.7 s), ≈ 5 µs each. That doesn't set the frame time here.

    What Execute does call is the address queries, about 15.5 per draw: mayfault 4.7, cpumod 2.8, backed 1.6, fullmap 1.6, clamp 1.6, findback 1.6, stillvalid 1.0, prefix 0.6. The counts lines carry no cycles for these in off periods, so their cost needs the ab periods.

    One note on reading the period lines: *_busy and *_us_per_draw come from thread CPU time, and Resolve, Execute and Record spin while they wait on their queues, so all three read 94-99 % busy and their µs per draw are just busy × wall time per draw (Execute 2.073 = 0.979 × 2.117 at 472 k draws/s). They follow fps and can't show which stage limits. Our perf profiles are what put MGS4 on Execute. The same probably applies to the Stray figures (2.78 µs, 83 %).

  13. simnJS commented on Nov 19, 2026

    @simnJS
    Owner

    @Raghav314 thanks for the measurements. We tried the safe part of ab: branch perf/addr-validity (f3f1146, on AnyKyty 17b0abc). Each thread keeps the answers of MayFaultOnGpuRead until the set of GPU-written pages changes (one global generation), and nothing is skipped. KYTY_GPU_OWNER_MEMO=0 turns it off.

    What we measured on our RT bench title (Fidelity 4K, RTX 4080 SUPER, Linux):

    • the memo answers 3.30 of the 3.99 MayFaultOnGpuRead calls per draw (83 %);
    • no measurable gain: Execute 3.97 µs per draw without it, 4.13 with it (user time 3.01 vs 3.06 µs, within noise). Execute is only 39 % busy here, so it does not set the frame rate;
    • without the memo, 99 % of these calls already took the short path (a region with no GPU-written page). Only 0.025 per draw walked the page bits.

    So the +6 % of ab probably doesn't come from these calls. It comes from what ab skips without checking: the byte comparison in StillValid, and the mapping queries (ClampRangeSize, IsBacked, FindBackingPointer, IsFullyMapped). Those mapping queries could use the same scheme, with a generation bumped on map, unmap and protect. Skipping the StillValid comparison safely would need a write guard on the journal pages, which is a protection change.

    Since your Execute is saturated, an A/B of this branch on your side (KYTY_GPU_OWNER_MEMO=0 vs the default, same scene) would tell us whether it helps there. We won't merge it without a measured gain.

  14. simnJS commented on Nov 19, 2026

    @simnJS
    Owner

    Update, with a clearer picture of where the memory-tracking cost comes from and what the console does.

    On our RT bench title (Fidelity 4K, busy city), write faults cost ~19 s of game-thread CPU per 10 s. 89 % of them land in one structure: the game's pool of command-buffer segments (PM4 packets plus dynamic constants copied in by memcpy), which the game rewrites every few frames.

    What we established about the console driver's behaviour:

    • sceAgcDriverSubmitDcb/Acb/Multi* hand the GPU (address, size) pairs and do nothing else with the buffer memory: no copy, no cache flush, no barrier, no per-page tracking.
    • The command processor reads the buffer when it executes it, not at submit. Games keep writing into already-submitted buffers (patches, REWIND), and nothing in the driver orders that.
    • The only synchronization is the game's own labels (RELEASE_MEM, whose cache write-back is chosen by the game).

    So per-page write tracking of that pool is work the console never does. In progress: take that memory as-is when the GPU uses it, with the addresses a WAIT_REG_MEM polls still read live. Expected around −4 to −6 ms per frame on the critical path in that scene, to be A/B-measured before it lands. This should help MGS4's case too, if its tracked writes are the same kind; worth re-measuring once it's in.

  15. simnJS commented on Nov 20, 2026

    @simnJS
    Owner

    Status at AnyKyty de0fa04, against the design above.

    What landed, on the write-fault side:

    • KYTY_WRITE_FAULT_BLOCKS (88eb2573eb, narrowed by da2947c57d, with b3f9a4a0d5 keeping GPU-written pages out of an opened block): a guest write fault in command-buffer memory opens the whole 64 KiB block with one protection change, and a block opens only where the command processor read a command buffer or libSceAgc wrote packets. On our RT bench title: 724,000-840,000 guest write faults per 10 s down to 231,000-234,000, 53.5 to 56.0 fps, buffer uploads 11.8-12.1 down to 9.7-9.9 GiB per 10 s. [kyty-write-blocks] counts the faults by owner.
    • fewer faults on reads: indirect register tables are read without a fault when the GPU never wrote their bytes (d2b599b8b3), the shader resource table walk reads GPU-owned pages without one (31c6c4aedc), and faulted reads are replayed on the backing view (e36fbe6707, 6cb0cb2a4a, 0832a8bc2e). Hot-page write watching exists but stays off by default (f394e912fb).
      These act on the guest threads. Your MGS4 numbers put the re-protection there too and the fault handling at 0.9 % and 0.3 % of Execute, so we do not expect them to move the 19 %.

    What did not change: the read path that is that 19 % (MappedPrefix, Shim::IsBacked, GuestReadLog::StillValid). Your ab ceiling on MGS4 was 0 to 1.5 %, the owner-record redesign is not built, and perf/addr-validity (a memo of MayFaultOnGpuRead) is not merged because it showed no gain.

    Still open for MGS4: the slow path of ClampRangeSize we named above. MappedPrefix is walked twice, and FirstClamp takes a mutex and a std::set on every clamped call. #130 removes the second walk (draft, in-game trace pending); FirstClamp is untouched. Reading command-buffer memory as-is when the GPU uses it, from the previous update, is not on the head yet.

    @Raghav314, a re-measurement would settle what is left: spot B, a 10 s perf record of kytyGpuExecute, on the current head, once as is and once with #130's branch. The "memory tracking, user code" and kernel shares of both, in the same format as your tables.

  16. added
    perf
    on Nov 22, 2026
  17. changed the title [-]perf(kyty): memory tracking takes about 20 % of kytyGpuExecute in MGS4[/-] [+]perf(kyty): memory-tracking reads cost about 19 % of Execute in METAL GEAR SOLID 4 (MappedPrefix, IsBacked, StillValid, FirstClamp)[/+] on Nov 22, 2026
  18. added
    area: gpu-memory
    area: execute
    medium
    needs: measurement
    on Nov 22, 2026
  19. simnJS commented on Nov 22, 2026

    @simnJS
    Owner

    Status at AnyKyty a4b4360d66:

    The open question is still the one above: how much of the 19 % is left on the current head. Spot B, a 10 s perf record of kytyGpuExecute, with the "memory tracking, user code" and kernel shares in the same format as the first tables, would settle it. A change to FirstClamp is a good medium task once those numbers are in; measure it with an in-run KYTY_AB A/B (how).

  20. mrfelek commented on Nov 23, 2026

    @mrfelek
    Contributor

    @simnJS a title where the ClampRangeSize slow path is most of the frame: Star Wars Galactic Racer (PPSA28416, Unreal Engine). I'd like to take the targeted fix you suggested above ("cache the clamp result per buffer range until an unmap"); here is the measurement and a prototype.

    Setup: Linux, Ryzen 9 5950X, RTX 3080 Ti (NVIDIA 615.71.09), AnyKyty 945dc287bc, KYTY_GPU_SPIN_US=0, warm caches. The game is driven by APS5_PAD_INPUT_FILE into an Arcade race on Jakku, and every number is from the race.

    Execute is the wall. A busy-wait added before every operation on the execute thread:

    Added per op fps Frame Execute CPU
    0 ~5.8 ~172 ms 85 %
    +100 µs 2.9 ~345 ms 93 %
    +250 µs 1.4 ~714 ms 93 %

    The frame grows by as much as Execute's busy time (slope about 1.0), at roughly 1,800–2,000 operations per frame, so about 80 µs per operation. The GPU is about 40 % busy.

    Where it goes. perf record -g of kytyGpuExecute for 30 s: 74 % of its samples are in MappedPrefix, called from ClampRangeSize in RenderExecutor::FindBuffers (DispatchIndirect 40 %, PrepareGraphicsBindings 23 %, DispatchDirect 11 %).

    A temporary counter in ClampRangeSize and PageTable::Store, per 10 s:

    • ~48,000 calls; 18,900 answered by IsBacked.
    • ~29,000 of them for a 2–4 GiB range (2^31 bytes), every one only partly mapped, so MappedPrefix walks the mapped part (~570 MB, ~35,000 pages of 16 KiB) each time: ~1.0 billion page-table loads per 10 s.
    • 89 % of the calls repeat a (address, size) pair seen just before.
    • The page table changes 20 to 30 times per 10 s.

    Prototype. A per-thread 256-entry memo in ClampRangeSize, keyed by (address, size) and valid while g_probe_epoch and g_backing_epoch are unchanged. OnViewChange bumps the first before it stores the pages and the second after, and OnProtectionChange bumps the first, so a result is stored only when neither moved while MappedPrefix ran. A hit also skips FirstClamp. It sits behind a temporary switch, KYTY_CLAMP_MEMO, measured with KYTY_AB=20:KYTY_CLAMP_MEMO KYTY_AB_SETTLE=5 KYTY_AB_START=250s in the race, tools/kyty_ab_report.py:

      A: KYTY_CLAMP_MEMO=1
      B: KYTY_CLAMP_MEMO=0
      A: 8 phase(s); 13.02 img/s (sd 0.79)
      B: 8 phase(s); 6.89 img/s (sd 0.09)
      B - A: -6.12 img/s (-47.0 %)
      drift-cancelled B - A over 7 B phase(s): -6.23 img/s (standard error 0.15)
    

    So +89 % fps in that race with the memo, with the picture unchanged.

    Plan for the PR, branched off the current AnyKyty:

    • the memo in ClampRangeSize as above, and the same lookup in ClampRangeSizeOrZero and IsFullyMapped if you agree, since they call MappedPrefix on the same ranges;
    • a shim test: a clamped range, then an unmap and a map inside it, with the answer checked against MappedPrefix after each;
    • an in-run A/B on this title and a non-regression run on one more game, then the switch removed, as START_HERE asks.

    Does that fit what you have in mind, or would you rather have the result kept per buffer in the buffer cache?

    AI-assisted.

  21. mrfelek commented on Nov 23, 2026

    @mrfelek
    Contributor

    @simnJS the fix from my comment above is ready, but I can't open a pull request for it: simnJS/AnyPS5 is no longer in the fork network of boykopovar/AnyPS5, so GitHub refuses a pull request from mrfelek/AnyPS5 ("head invalid"). How would you like to receive it? Meanwhile, the branch is here:

    • Branch: mrfelek/AnyPS5 perf/kyty-clamp-memo, two commits on AnyKyty 7de61e3451. c558edf4e6 is the change behind the temporary switch KYTY_CLAMP_MEMO, and 56a8b0fdab removes the switch after the A/B.
    • Fetch: git fetch https://github.com/mrfelek/AnyPS5.git perf/kyty-clamp-memo
    • The final change: ClampRangeSize keeps, per thread, a 256-entry table of (address, size) → mapped length, used only while g_probe_epoch and g_backing_epoch are unchanged. It adds 20 lines in MemoryBacking.cpp and a check in kyty_shim_memory (commit, reset and recommit inside a clamped range, on two threads).

    A/B on the branch (KYTY_AB=20:KYTY_CLAMP_MEMO, warm caches, tools/kyty_ab_report.py, A = remembered, B = walked):

    Scene A B drift-cancelled B − A
    PPSA28416 Jakku race, on 7de61e3451 7.23 img/s 5.46 img/s −1.98 img/s (−27 %), standard error 0.16
    PPSA21564 pirate island, on 7de61e3451 (non-regression) 18.60 img/s 18.21 img/s −0.12 img/s, inside the noise
    PPSA28416 Sentinel I map menu, prototype on 945dc287bc, 8 + 8 phases 5.62 img/s 4.20 img/s −1.39 img/s (−25 %), standard error 0.06

    On 7de61e3451 the walked arm of the race is slower than on 945dc287bc (5.5 vs 6.9 img/s), so something else on the head costs this scene too, and the gain shows less there than the +89 % above.

    Shim suite with the validation layer, serially, on 7de61e3451 and on the change: 109 of 110 on both, layer inserted 25 times and never missing, 0 VUID-. The same two don't pass on both: kyty_shim_memory_sparse_reads_switch times out and kyty_shim_rt_corpus is skipped. check_conventions.py and check_kyty_settings.py pass.

    PPSA21564, PPSA03912, PPSA02015, PPSA03671 and Ghost of Yōtei never log clamped buffer range here, and neither did PPSA22408 in three minutes of menus, so they don't take this path.

    The full pull-request description, in the template's format, is ready to paste wherever you prefer.

    AI-assisted.

  22. simnJS commented on Nov 26, 2026

    @simnJS
    Owner

    @mrfelek sorry for the wait, and thank you: without the memo that race runs 27 % to 47 % slower, so 20 lines is a very good trade, and the non-regression run on the other title is clean. Yes, the memo in ClampRangeSize is what we had in mind. Keep it per thread as you did, not in the buffer cache, and with the switch removed as in 56a8b0fdab.

    About the pull request: GitHub refuses it because your fork belongs to upstream AnyPS5's network, and this repository isn't in it any more. Fork simnJS/AnyPS5 itself (pick another name, for example AnyKyty, since you already have mrfelek/AnyPS5), push perf/kyty-clamp-memo there and open the PR against AnyKyty with the description you have ready. If that doesn't work for you, tell us and we'll carry the branch as a PR with your authorship, as was done for #292.

    The walked arm being slower on 7de61e3451 than on 945dc287bc (5.5 against 6.9 img/s on the same race) is worth its own issue, if you can profile both on the same scene.

  23. mrfelek commented on Nov 26, 2026

    @mrfelek
    Contributor

    @simnJS thanks. We'd rather not keep a second fork, so please carry it as a PR with my authorship, as you did for #292. The branch is mrfelek/AnyPS5:perf/kyty-clamp-memo, head 56a8b0fdab (switch removed), on 7de61e3451. The description and numbers are in my comment above: race 7.23 against 5.46 img/s, ASTRO BOT 18.6 against 18.2 fps as the non-regression run. If it no longer applies cleanly on the current AnyKyty head, say so and I'll rebase the branch.

    I'll open a separate issue for the walked arm being slower on 7de61e3451 than on 945dc287bc once I have both profiled on the same scene.

    AI-assisted.

  24. mrfelek commented on Nov 26, 2026

    @mrfelek
    Contributor

    @simnJS change of plan, so you don't have to carry it: I made the fork after all (mrfelek/AnyKyty) and opened the PR there: #333. Same head 56a8b0fdab as above; it merges cleanly on the current AnyKyty head 90a48455d2.

    AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: executearea: gpu-memorymediumneeds: measurementperf

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions