Unified Memory Allocation WIP

This commit is contained in:
Dmugetsu 2025-03-07 15:13:57 -06:00
parent 5c87aa346b
commit 703fe8410e
4 changed files with 29 additions and 17 deletions

View File

@ -22,7 +22,7 @@ namespace Libraries::Kernel {
u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize() { u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize() {
LOG_WARNING(Kernel_Vmm, "called"); LOG_WARNING(Kernel_Vmm, "called");
const auto* memory = Core::Memory::Instance(); const auto* memory = Core::Memory::Instance();
return memory->GetTotalDirectSize(); return memory->GetTotalUnifiedMemorySize();
} }
int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u64 len, int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u64 len,
@ -276,7 +276,7 @@ int PS4_SYSV_ABI sceKernelDirectMemoryQuery(u64 offset, int flags, OrbisQueryInf
s32 PS4_SYSV_ABI sceKernelAvailableFlexibleMemorySize(size_t* out_size) { s32 PS4_SYSV_ABI sceKernelAvailableFlexibleMemorySize(size_t* out_size) {
auto* memory = Core::Memory::Instance(); auto* memory = Core::Memory::Instance();
*out_size = memory->GetAvailableFlexibleSize(); *out_size = memory->GetTotalUnifiedMemorySize();
LOG_INFO(Kernel_Vmm, "called size = {:#x}", *out_size); LOG_INFO(Kernel_Vmm, "called size = {:#x}", *out_size);
return ORBIS_OK; return ORBIS_OK;
} }
@ -511,7 +511,7 @@ s32 PS4_SYSV_ABI sceKernelConfiguredFlexibleMemorySize(u64* sizeOut) {
} }
auto* memory = Core::Memory::Instance(); auto* memory = Core::Memory::Instance();
*sizeOut = memory->GetTotalFlexibleSize(); *sizeOut = memory->GetTotalUnifiedMemorySize();
return ORBIS_OK; return ORBIS_OK;
} }

View File

@ -5,12 +5,17 @@
#include "common/bit_field.h" #include "common/bit_field.h"
#include "common/types.h" #include "common/types.h"
#include "core/linker.h"
#include "core/memory.h"
#include "src/common/memory_patcher.h"
constexpr u64 SCE_KERNEL_TOTAL_MEM = 5248_MB * 4; constexpr bool USE_EXPANDED_MEMORY = true;
constexpr u64 SCE_KERNEL_TOTAL_MEM_PRO = 5888_MB * 4;
constexpr u64 SCE_FLEXIBLE_MEMORY_BASE = 64_MB; constexpr u64 SCE_KERNEL_TOTAL_MEM = (USE_EXPANDED_MEMORY ? 5248_MB * 1.2 : 5248_MB);
constexpr u64 SCE_FLEXIBLE_MEMORY_SIZE = 512_MB; constexpr u64 SCE_KERNEL_TOTAL_MEM_PRO = (USE_EXPANDED_MEMORY ? 5888_MB * 1.2 : 5888_MB);
constexpr u64 SCE_FLEXIBLE_MEMORY_BASE = (USE_EXPANDED_MEMORY ? 64_MB * 1.2 : 64_MB);
constexpr u64 SCE_FLEXIBLE_MEMORY_SIZE = (USE_EXPANDED_MEMORY ? 512_MB * 1.2 : 512_MB);
namespace Core::Loader { namespace Core::Loader {
class SymbolsResolver; class SymbolsResolver;

View File

@ -37,14 +37,23 @@ MemoryManager::~MemoryManager() = default;
void MemoryManager::SetupMemoryRegions(u64 flexible_size, bool use_extended_mem1, void MemoryManager::SetupMemoryRegions(u64 flexible_size, bool use_extended_mem1,
bool use_extended_mem2) { bool use_extended_mem2) {
const bool is_neo = ::Libraries::Kernel::sceKernelIsNeoMode(); const bool is_neo = ::Libraries::Kernel::sceKernelIsNeoMode();
auto total_size = is_neo ? SCE_KERNEL_TOTAL_MEM_PRO : SCE_KERNEL_TOTAL_MEM; auto total_size = is_neo ? SCE_KERNEL_TOTAL_MEM_PRO : SCE_KERNEL_TOTAL_MEM;
if (NeedsExtraMemory()) {
total_size = SCE_KERNEL_TOTAL_MEM * 1.2;
}
if (!use_extended_mem1 && is_neo) { if (!use_extended_mem1 && is_neo) {
total_size -= 256_MB; total_size -= 256_MB;
} }
if (!use_extended_mem2 && !is_neo) { if (!use_extended_mem2 && !is_neo) {
total_size -= 128_MB; total_size -= 128_MB;
} }
total_flexible_size = flexible_size - SCE_FLEXIBLE_MEMORY_BASE; total_flexible_size = flexible_size - SCE_FLEXIBLE_MEMORY_BASE;
if (NeedsExtraMemory()) {
total_flexible_size = flexible_size - SCE_FLEXIBLE_MEMORY_BASE * 1.2;
}
total_direct_size = total_size - flexible_size; total_direct_size = total_size - flexible_size;
// Insert an area that covers direct memory physical block. // Insert an area that covers direct memory physical block.

View File

@ -36,6 +36,7 @@ enum class MemoryProt : u32 {
GpuRead = 16, GpuRead = 16,
GpuWrite = 32, GpuWrite = 32,
GpuReadWrite = 48, GpuReadWrite = 48,
UnifiedReadWrite = 50,
}; };
DECLARE_ENUM_FLAG_OPERATORS(MemoryProt) DECLARE_ENUM_FLAG_OPERATORS(MemoryProt)
@ -144,16 +145,12 @@ public:
return impl; return impl;
} }
u64 GetTotalDirectSize() const { u64 GetTotalUnifiedMemorySize() const {
return total_direct_size; return total_direct_size + total_flexible_size;
} }
u64 GetTotalFlexibleSize() const { u64 GetAvailableUnifiedMemorySize() const {
return total_flexible_size; return GetTotalUnifiedMemorySize() - flexible_usage;
}
u64 GetAvailableFlexibleSize() const {
return total_flexible_size - flexible_usage;
} }
VAddr SystemReservedVirtualBase() noexcept { VAddr SystemReservedVirtualBase() noexcept {
@ -168,8 +165,9 @@ public:
} }
bool NeedsExtraMemory() { bool NeedsExtraMemory() {
static const std::unordered_set<std::string> extra_memory_games = { static const std::unordered_set<std::string> extra_memory_games = {
// here should be games with needs of extra memory as EXAMPLE "CUSA28615", // Example game that needs extra memory
"CUSA03173"}; "CUSA03173" // Add other games here if needed
};
return extra_memory_games.find(MemoryPatcher::g_game_serial) != extra_memory_games.end(); return extra_memory_games.find(MemoryPatcher::g_game_serial) != extra_memory_games.end();
} }