From 6f874be41b5c284e18d5e735690e9c30198eb0f8 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 12 Jun 2021 19:12:59 +0300 Subject: [PATCH] vm_native: bypass rpcs3_vm creation if overcommit is enabled (Linux) Unfortunately, different systems need different approach here. --- rpcs3/util/vm_native.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/rpcs3/util/vm_native.cpp b/rpcs3/util/vm_native.cpp index 6def1a98b6..906e4b9745 100644 --- a/rpcs3/util/vm_native.cpp +++ b/rpcs3/util/vm_native.cpp @@ -428,13 +428,30 @@ namespace utils m_handle = ensure(::CreateFileMappingW(f.get_handle(), nullptr, PAGE_READWRITE, 0, 0, nullptr)); #else + + // TODO: check overcommit configuration of other supported platforms to bypass rpcs3_vm creation +#ifdef __linux__ + if (const char c = fs::file("/proc/sys/vm/overcommit_memory").read(); c == '0' || c == '1') + { + // Simply use memfd for overcommit memory + m_file = ::memfd_create_("", 0); + ensure(m_file >= 0); + ensure(::ftruncate(m_file, m_size) >= 0); + return; + } + else + { + fprintf(stderr, "Reading /proc/sys/vm/overcommit_memory: %c", c); + } +#endif + if (!storage.empty()) { m_file = ::open(storage.c_str(), O_RDWR | O_CREAT, S_IWUSR | S_IRUSR); } else { - m_file = ::open((fs::get_cache_dir() + "rpcs3_vm").c_str(), O_RDWR | O_CREAT, S_IWUSR | S_IRUSR); + m_file = ::open((fs::get_cache_dir() + "rpcs3_vm_sparse.tmp").c_str(), O_RDWR | O_CREAT, S_IWUSR | S_IRUSR); } ensure(m_file >= 0);