From dc5cdb3bb49712908cf7f129696505d901b7a6da Mon Sep 17 00:00:00 2001 From: Eladash Date: Sat, 4 Apr 2020 22:49:04 +0300 Subject: [PATCH] sys_ppu_thread: reduce global memory stats after thread creation --- rpcs3/Emu/Cell/PPUModule.cpp | 2 +- rpcs3/Emu/Cell/PPUThread.cpp | 6 ++++++ rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/rpcs3/Emu/Cell/PPUModule.cpp b/rpcs3/Emu/Cell/PPUModule.cpp index 07ad2a3276..ffdbe12e9a 100644 --- a/rpcs3/Emu/Cell/PPUModule.cpp +++ b/rpcs3/Emu/Cell/PPUModule.cpp @@ -1577,7 +1577,7 @@ void ppu_load_exec(const ppu_exec_object& elf) mem_size += 0xC000000; } - g_fxo->init(mem_size); + g_fxo->init(mem_size)->used += primary_stacksize; ppu->cmd_push({ppu_cmd::initialize, 0}); diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index fe47e25764..4c21533fcb 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -12,6 +12,7 @@ #include "SPURecompiler.h" #include "lv2/sys_sync.h" #include "lv2/sys_prx.h" +#include "lv2/sys_memory.h" #include "Emu/GDB.h" #ifdef LLVM_AVAILABLE @@ -747,6 +748,11 @@ ppu_thread::~ppu_thread() { // Deallocate Stack Area vm::dealloc_verbose_nothrow(stack_addr, vm::stack); + + if (const auto dct = g_fxo->get()) + { + dct->used -= stack_size; + } } ppu_thread::ppu_thread(const ppu_thread_params& param, std::string_view name, u32 prio, int detached) diff --git a/rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp b/rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp index d16863cb41..750d6dc64f 100644 --- a/rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp @@ -8,6 +8,7 @@ #include "sys_event.h" #include "sys_process.h" #include "sys_mmapper.h" +#include "sys_memory.h" LOG_CHANNEL(sys_ppu_thread); @@ -367,10 +368,19 @@ error_code _sys_ppu_thread_create(vm::ptr thread_id, vm::ptr(std::max(_stacksz, 4096), 4096); + const auto dct = g_fxo->get(); + + // Try to obtain "physical memory" from the default container + if (!dct->take(stack_size)) + { + return CELL_ENOMEM; + } + const vm::addr_t stack_base{vm::alloc(stack_size, vm::stack, 4096)}; if (!stack_base) { + dct->used -= stack_size; return CELL_ENOMEM; } @@ -408,6 +418,7 @@ error_code _sys_ppu_thread_create(vm::ptr thread_id, vm::ptrused -= stack_size; return CELL_EAGAIN; }