[PR #3932] [MERGED] Kernel.Vmm: Handle sparse physical memory usage + other fixes #3810

Closed
opened 2026-02-27 22:05:03 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/shadps4-emu/shadPS4/pull/3932
Author: @StevenMiller123
Created: 1/17/2026
Status: Merged
Merged: 1/21/2026
Merged by: @georgemoralis

Base: mainHead: sparse-phys-mem


📝 Commits (10+)

📊 Changes

7 files changed (+692 additions, -523 deletions)

View changed files

📝 src/core/address_space.cpp (+180 -125)
📝 src/core/address_space.h (+10 -12)
📝 src/core/devtools/widget/memory_map.cpp (+4 -3)
📝 src/core/devtools/widget/memory_map.h (+2 -2)
📝 src/core/libraries/kernel/memory.cpp (+1 -0)
📝 src/core/memory.cpp (+449 -300)
📝 src/core/memory.h (+46 -81)

📄 Description

This PR rewrites chunks of address space and memory code to properly handle sparse physical memory usage for pool and flexible memory.

Notable changes:

  • AddressSpace unmaps no-longer need a physical address, or the various VMA offset parameters we used to use. All relevant information needed to properly unmap memory is stored within AddressSpace now.
  • Mapped/Pooled virtual memory areas will now merge when the areas are similar enough. Previously, restrictions with Windows AddressSpace unmaps prevented this. This change should improve memory performance in games that spam small memory mappings.
  • Memory code now takes advantage of our SharedFirstMutex, allowing multi-threaded memory map accesses (like virtual queries). This should theoretically help memory performance, though I don't think the change will be too noticeable.
  • Virtual memory areas now store a map of all physical memory they encompass. This is needed to fix the regressions from #3909, and to properly enable merging flexible and pooled memory.

This PR affects a lot of code, so this probably needs a lot of testing before any merging can happen. I would especially like to see performance tests from games that spam memory calls, as I've made various changes that can both hurt and improve performance here.

I've tested a couple of notable edge cases in my games, and this code seems to function at least.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/shadps4-emu/shadPS4/pull/3932 **Author:** [@StevenMiller123](https://github.com/StevenMiller123) **Created:** 1/17/2026 **Status:** ✅ Merged **Merged:** 1/21/2026 **Merged by:** [@georgemoralis](https://github.com/georgemoralis) **Base:** `main` ← **Head:** `sparse-phys-mem` --- ### 📝 Commits (10+) - [`760ac1d`](https://github.com/shadps4-emu/shadPS4/commit/760ac1dadb0b58e4ae95fe0b671b677c5b8b4c15) Initial work - [`f4a7e10`](https://github.com/shadps4-emu/shadPS4/commit/f4a7e10f9ecd1b3be40db68083a2d4ec8e4c5818) Bug fixing - [`e45268c`](https://github.com/shadps4-emu/shadPS4/commit/e45268cf6263c4f6d75291bae8bdc9d88e525bb1) Fix more bugs - [`fadae1c`](https://github.com/shadps4-emu/shadPS4/commit/fadae1cfb8d186c3f24be52bbbb69a20688881bc) More bug fixing - [`6dddf4f`](https://github.com/shadps4-emu/shadPS4/commit/6dddf4fb14abde865bf5166640a6b8524c31772d) Even more bug fixing - [`b031b9c`](https://github.com/shadps4-emu/shadPS4/commit/b031b9c3a66d8c50eadc29bacae6706965f68605) More bugfixing - [`697ff90`](https://github.com/shadps4-emu/shadPS4/commit/697ff90b44e8bf2fb18e93d4ffc128267b378957) Update memory.cpp - [`b7c5868`](https://github.com/shadps4-emu/shadPS4/commit/b7c58686bc7d2fb458415bfc969f03c2eb6ff47c) Rewrite start - [`c647e0f`](https://github.com/shadps4-emu/shadPS4/commit/c647e0fe13762ce9d7c38ad10ef4e816662956ec) Fix for oversized unmaps - [`4d9613a`](https://github.com/shadps4-emu/shadPS4/commit/4d9613a3ec15bfcd15b49740b5dbf231f2cf4f7a) Oops ### 📊 Changes **7 files changed** (+692 additions, -523 deletions) <details> <summary>View changed files</summary> 📝 `src/core/address_space.cpp` (+180 -125) 📝 `src/core/address_space.h` (+10 -12) 📝 `src/core/devtools/widget/memory_map.cpp` (+4 -3) 📝 `src/core/devtools/widget/memory_map.h` (+2 -2) 📝 `src/core/libraries/kernel/memory.cpp` (+1 -0) 📝 `src/core/memory.cpp` (+449 -300) 📝 `src/core/memory.h` (+46 -81) </details> ### 📄 Description This PR rewrites chunks of address space and memory code to properly handle sparse physical memory usage for pool and flexible memory. Notable changes: - AddressSpace unmaps no-longer need a physical address, or the various VMA offset parameters we used to use. All relevant information needed to properly unmap memory is stored within AddressSpace now. - Mapped/Pooled virtual memory areas will now merge when the areas are similar enough. Previously, restrictions with Windows AddressSpace unmaps prevented this. This change should improve memory performance in games that spam small memory mappings. - Memory code now takes advantage of our SharedFirstMutex, allowing multi-threaded memory map accesses (like virtual queries). This should theoretically help memory performance, though I don't think the change will be too noticeable. - Virtual memory areas now store a map of all physical memory they encompass. This is needed to fix the regressions from #3909, and to properly enable merging flexible and pooled memory. This PR affects a lot of code, so this probably needs a lot of testing before any merging can happen. I would especially like to see performance tests from games that spam memory calls, as I've made various changes that can both hurt and improve performance here. I've tested a couple of notable edge cases in my games, and this code seems to function at least. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 22:05:03 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
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
starred/shadPS4#3810
No description provided.