Skip to content

perf(memory): write tracked direct memory through backing views - #1309

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
TibixDev:pr/tracked-backing-writes
Oct 9, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
TibixDev:pr/tracked-backing-writes

Conversation

@TibixDev

@TibixDev TibixDev commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What

Write tracked Linux direct memory through a retained backing view. Keep access checks, write versions, and GPU ordering. Use the same path for completion labels.

The writer validates the full range before it changes any bytes. Unsupported mappings use the existing copy path.

Related: #1152 reduces GPU import count; this change reduces CPU write faults. Both change PhysicalBacking and need integration. #637 changes Windows tracking.

Tested

Fedora 44, Release build:

  • Shared writes, write tracking, and guest memory tests.
  • Shared writes with write watching disabled.
  • RX 6600 completion-label storage and ordering tests with Vulkan validation. The recorder fixture now enables command-buffer reset.
  • Contribution checks.

Isolated comparison: upstream e9846679 versus the same revision plus this PR. Six pinned processes per variant in ABBA order. A 1 MiB write took 285.954 → 68.110 µs (76% less time); process medians ranged from 274.610–365.925 µs before and 64.895–79.676 µs after. Write faults fell from 589,824 to zero over 2,304 measured writes. Smaller writes and labels had overlapping timing ranges. This is a component result, not title frame time. Windows was not tested.

Checklist

  • Current main; related PRs and integration needs are described above.
  • One topic.
  • No new code comments.
  • Unsupported paths still throw; UI stubs are documented.
  • No notes, logs, or images in the repository.
  • No new third-party code.
  • General behavior.
  • Depends on: none.
  • AI-assisted: yes.

@TibixDev

TibixDev commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on e9846679. The test-list conflict is resolved; the production change is unchanged.

Measured upstream e9846679 against that revision plus this PR (349781da). Fedora 44, GCC 16 Release, Ryzen 5 5600, pinned to CPU 3. Six processes per variant, ABBA × 3; each has one warmup and nine batches of 256 writes. No game or build ran during timing.

Write size Upstream median (µs) PR median (µs) Upstream process range PR process range
4,096 bytes 50.023 41.315 40.184–57.437 37.069–54.181
65,536 bytes 65.957 46.791 54.190–76.309 37.947–56.446
1,048,576 bytes 285.954 68.110 274.610–365.925 64.895–79.676

The 1 MiB case uses 76% less time. Faults per 2,304 writes fell from 2,304 / 36,864 / 589,824 to zero for the three sizes. Both builds check the output bytes.

For 4/8/16-byte completion stores, medians were 49.860/49.247/40.664 → 40.406/39.346/42.053 µs. All ranges overlap, so this does not establish a small-store speedup; the 16-byte median regressed. The label fixture invokes the same access-check and store sequence as each revision's completion callback. Faults fell from 2,304 to zero in each case.

Shared-write, write-tracking, and graphics tests pass. Shared writes also pass with watching disabled. Completion storage and ordering pass with core and sync validation on RX 6600 RADV and llvmpipe. Contribution checks pass. No title frame time or Windows result is claimed. AI-assisted.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 8, 2026
@popcoder565

Copy link
Copy Markdown
Contributor

Tested on Windows, since the description says it wasn't: Windows 10 (19045), RTX 3060 Laptop (driver 616.92), MinGW-w64 GCC 15.2.0, Release. I tested main 7a178e2 merged with 349781d.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

PhysicalBacking::HostWriteData (DirectMemory.cpp) returns nullptr when the mmap of the write view fails, and StoreOwnBytes then writes with memcpy instead. Failures stay explicit here (#182); please throw when that mmap fails, and keep false only for ranges that aren't direct-memory backed.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 8, 2026
TibixDev and others added 2 commits October 10, 2026 00:53
Retain host backing views for emulator writes and completion labels. Validate full spans, preserve write versions and GPU ordering, and keep the fallback for other mappings. Test remaps, aliases, access checks, partial failures, tracking, view lifetime, and completion ordering.

Written with AI assistance.
@adriadam10
adriadam10 force-pushed the pr/tracked-backing-writes branch from 349781d to 0e32f36 Compare October 9, 2026 23:00
@adriadam10

Copy link
Copy Markdown
Collaborator

Rebased onto current main (conflicts in the agcTest list in libSceAgcDriver/CMakeLists.txt and in main of tests/Recorder.cpp) and added one commit:

  • PhysicalBacking::HostWriteData (DirectMemory.cpp) now throws std::system_error when the mmap of the write view fails, as requested in the review. It still returns nullptr only for ranges that aren't backed by direct memory.

Rebuilt the AgcDriver, libc and libkernel targets; agc_shared_write passes, and the new test no longer builds without the non-test changes. Windows results from @popcoder565 above still apply (production code for Windows is unchanged).

Note: #1152 also changes PhysicalBacking in DirectMemory.cpp and conflicts with this PR; whichever lands second needs a rebase.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#1046 core/libs/prx/libSceAgcDriver/CMakeLists.txt L673
#1152 core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp L226-227, L255, L261-262, L282
#1640 core/libs/prx/libSceAgcDriver/CMakeLists.txt L673
#1959 core/libs/prx/libSceAgcDriver/CMakeLists.txt L673
#2470 core/libs/prx/libSceAgcDriver/CMakeLists.txt L673
#2501 core/libs/prx/libSceAgcDriver/CMakeLists.txt L673

SleglJan pushed a commit to SleglJan/AnyPS5 that referenced this pull request Oct 10, 2026
…rites

perf(memory): write tracked direct memory through backing views
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants