Increase open file limit on Linux

Add some assertions to VirtualMemory.cpp
This commit is contained in:
Nekotekina 2018-05-13 22:50:38 +03:00
parent 3c70645f0b
commit a46ef4f29a
2 changed files with 34 additions and 7 deletions

View File

@ -12,6 +12,14 @@
#include <sys/types.h>
#endif
#if 0
#include <sys/syscall.h>
static int memfd_create(const char *name, unsigned int flags)
{
return syscall(__NR_memfd_create, name, flags);
}
#endif
namespace utils
{
// Convert memory protection (internal)
@ -115,21 +123,27 @@ namespace utils
{
#ifdef _WIN32
m_handle = ::CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_EXECUTE_READWRITE, 0, m_size, NULL);
verify(HERE), m_handle != INVALID_HANDLE_VALUE;
//#elif __linux__
// m_file = ::memfd_create("mem1", 0);
// ::ftruncate(m_file, m_size);
// m_file = ::memfd_create("", 0);
// 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)
{
if (errno != EEXIST)
return;
if (m_file == -1 && errno == EMFILE)
{
fmt::throw_exception("Too many open files. Raise the limit and try again.");
}
verify(HERE), errno == EEXIST;
}
::shm_unlink("/rpcs3-mem1");
::ftruncate(m_file, m_size);
verify(HERE), ::shm_unlink("/rpcs3-mem1") >= 0;
verify(HERE), ::ftruncate(m_file, m_size) >= 0;
#endif
m_ptr = this->map(nullptr);
m_ptr = verify(HERE, this->map(nullptr));
}
shm::~shm()

View File

@ -13,6 +13,11 @@
#include <windows.h>
#endif
#ifdef __linux__
#include <sys/time.h>
#include <sys/resource.h>
#endif
inline std::string sstr(const QString& _in) { return _in.toStdString(); }
template <typename... Args>
@ -85,6 +90,14 @@ int main(int argc, char** argv)
qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");
#endif
#ifdef __linux__
struct ::rlimit rlim;
rlim.rlim_cur = 4096;
rlim.rlim_max = 4096;
if (::setrlimit(RLIMIT_NOFILE, &rlim) != 0)
std::fprintf(stderr, "Failed to set max open file limit (4096).");
#endif
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QCoreApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton);