diff --git a/Utilities/JIT.cpp b/Utilities/JIT.cpp index 73ba3a7159..56e45e2de7 100644 --- a/Utilities/JIT.cpp +++ b/Utilities/JIT.cpp @@ -88,9 +88,7 @@ static u8* add_jit_memory(std::size_t size, uint align) if (olda != newa) [[unlikely]] { -#ifdef CAN_OVERCOMMIT - madvise(pointer + olda, newa - olda, MADV_WILLNEED); -#else +#ifndef CAN_OVERCOMMIT // Commit more memory utils::memory_commit(pointer + olda, newa - olda, Prot); #endif diff --git a/Utilities/VirtualMemory.cpp b/Utilities/VirtualMemory.cpp index 6214e938d4..e3e496ce78 100644 --- a/Utilities/VirtualMemory.cpp +++ b/Utilities/VirtualMemory.cpp @@ -112,6 +112,7 @@ namespace utils #else const u64 ptr64 = reinterpret_cast(pointer); verify(HERE), ::mprotect(reinterpret_cast(ptr64 & -4096), size + (ptr64 & 4095), +prot) != -1; + verify(HERE), ::madvise(reinterpret_cast(ptr64 & -4096), size + (ptr64 & 4095), MADV_WILLNEED) != -1; #endif } @@ -120,7 +121,13 @@ namespace utils #ifdef _WIN32 verify(HERE), ::VirtualFree(pointer, size, MEM_DECOMMIT); #else + const u64 ptr64 = reinterpret_cast(pointer); verify(HERE), ::mmap(pointer, size, PROT_NONE, MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0) != reinterpret_cast(-1); +#ifdef MADV_FREE + verify(HERE), ::madvise(reinterpret_cast(ptr64 & -4096), size + (ptr64 & 4095), MADV_FREE) != -1; +#else + verify(HERE), ::madvise(reinterpret_cast(ptr64 & -4096), size + (ptr64 & 4095), MADV_DONTNEED) != -1; +#endif #endif } @@ -130,7 +137,14 @@ namespace utils memory_decommit(pointer, size); memory_commit(pointer, size, prot); #else + const u64 ptr64 = reinterpret_cast(pointer); +#ifdef MADV_FREE + verify(HERE), ::madvise(reinterpret_cast(ptr64 & -4096), size + (ptr64 & 4095), MADV_FREE) != -1; +#else + verify(HERE), ::madvise(reinterpret_cast(ptr64 & -4096), size + (ptr64 & 4095), MADV_DONTNEED) != -1; +#endif verify(HERE), ::mmap(pointer, size, +prot, MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0) != reinterpret_cast(-1); + verify(HERE), ::madvise(reinterpret_cast(ptr64 & -4096), size + (ptr64 & 4095), MADV_WILLNEED) != -1; #endif } @@ -178,7 +192,9 @@ namespace utils verify(HERE), m_file >= 0; verify(HERE), ::ftruncate(m_file, m_size) >= 0; #else - while ((m_file = ::shm_open("/rpcs3-mem1", O_RDWR | O_CREAT | O_EXCL, S_IWUSR | S_IRUSR)) == -1) + const std::string name = "/rpcs3-mem-" + std::to_string(reinterpret_cast(this)); + + while ((m_file = ::shm_open(name.c_str(), O_RDWR | O_CREAT | O_EXCL, S_IWUSR | S_IRUSR)) == -1) { if (errno == EMFILE) { @@ -188,7 +204,7 @@ namespace utils verify(HERE), errno == EEXIST; } - verify(HERE), ::shm_unlink("/rpcs3-mem1") >= 0; + verify(HERE), ::shm_unlink(name.c_str()) >= 0; verify(HERE), ::ftruncate(m_file, m_size) >= 0; #endif }