diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 27815720..f96e54d1 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -727,6 +727,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) m_settings->registerSetting({"MinMemAlloc", "MinMemoryAlloc"}, 512); m_settings->registerSetting({"MaxMemAlloc", "MaxMemoryAlloc"}, 1024); m_settings->registerSetting("PermGen", 128); + m_settings->registerSetting("AllowSwap", false); // Java Settings m_settings->registerSetting("JavaPath", ""); diff --git a/launcher/ui/pages/global/JavaPage.cpp b/launcher/ui/pages/global/JavaPage.cpp index bd79f11a..cb17d6af 100644 --- a/launcher/ui/pages/global/JavaPage.cpp +++ b/launcher/ui/pages/global/JavaPage.cpp @@ -37,9 +37,13 @@ JavaPage::JavaPage(QWidget *parent) : QWidget(parent), ui(new Ui::JavaPage) ui->setupUi(this); ui->tabWidget->tabBar()->hide(); - auto sysMiB = Sys::getSystemRam() / Sys::mebibyte; - ui->maxMemSpinBox->setMaximum(sysMiB); +#if !defined(Q_OS_LINUX) + ui->allowSwapCheckBox->setEnabled(false); + ui->allowSwapCheckBox->setVisible(false); +#endif + loadSettings(); + updateMemMax(); } JavaPage::~JavaPage() @@ -71,6 +75,7 @@ void JavaPage::applySettings() s->set("MaxMemAlloc", min); } s->set("PermGen", ui->permGenSpinBox->value()); + s->set("AllowSwap", ui->allowSwapCheckBox->isChecked()); // Java Settings s->set("JavaPath", ui->javaPathTextBox->text()); @@ -94,12 +99,27 @@ void JavaPage::loadSettings() ui->maxMemSpinBox->setValue(min); } ui->permGenSpinBox->setValue(s->get("PermGen").toInt()); + ui->allowSwapCheckBox->setChecked(s->get("AllowSwap").toBool()); // Java Settings ui->javaPathTextBox->setText(s->get("JavaPath").toString()); ui->jvmArgsTextBox->setText(s->get("JvmArgs").toString()); } +void JavaPage::updateMemMax() { + auto sysMiB = Sys::getSystemRam() / Sys::mebibyte; + + if (ui->allowSwapCheckBox->isChecked()) + sysMiB += Sys::getSystemSwap() / Sys::mebibyte; + + ui->maxMemSpinBox->setMaximum(sysMiB); +} + +void JavaPage::on_allowSwapCheckBox_clicked(bool checked) +{ + updateMemMax(); +} + void JavaPage::on_javaDetectBtn_clicked() { JavaInstallPtr java; diff --git a/launcher/ui/pages/global/JavaPage.h b/launcher/ui/pages/global/JavaPage.h index 8f9b3323..e1d5547e 100644 --- a/launcher/ui/pages/global/JavaPage.h +++ b/launcher/ui/pages/global/JavaPage.h @@ -58,9 +58,11 @@ public: private: void applySettings(); void loadSettings(); + void updateMemMax(); private slots: + void on_allowSwapCheckBox_clicked(bool clicked); void on_javaDetectBtn_clicked(); void on_javaTestBtn_clicked(); void on_javaBrowseBtn_clicked(); diff --git a/launcher/ui/pages/global/JavaPage.ui b/launcher/ui/pages/global/JavaPage.ui index b67e9994..af430f8b 100644 --- a/launcher/ui/pages/global/JavaPage.ui +++ b/launcher/ui/pages/global/JavaPage.ui @@ -132,6 +132,16 @@ + + + + Allow use of swap + + + Allows the usage of swap when specifying memory allocation. + + + diff --git a/libraries/systeminfo/include/sys.h b/libraries/systeminfo/include/sys.h index c1d4ecf8..e34730fe 100644 --- a/libraries/systeminfo/include/sys.h +++ b/libraries/systeminfo/include/sys.h @@ -57,6 +57,8 @@ DistributionInfo getDistributionInfo(); uint64_t getSystemRam(); +uint64_t getSystemSwap(); + bool isSystem64bit(); bool isCPU64bit(); diff --git a/libraries/systeminfo/src/sys_apple.cpp b/libraries/systeminfo/src/sys_apple.cpp index b1ec6760..78fb30b9 100644 --- a/libraries/systeminfo/src/sys_apple.cpp +++ b/libraries/systeminfo/src/sys_apple.cpp @@ -55,6 +55,11 @@ uint64_t Sys::getSystemRam() } } +uint64_t Sys::getSystemSwap() +{ + return 0; +} + bool Sys::isCPU64bit() { // not even going to pretend I'm going to support anything else diff --git a/libraries/systeminfo/src/sys_unix.cpp b/libraries/systeminfo/src/sys_unix.cpp index 66928ae3..96ad7e6b 100644 --- a/libraries/systeminfo/src/sys_unix.cpp +++ b/libraries/systeminfo/src/sys_unix.cpp @@ -82,6 +82,31 @@ uint64_t Sys::getSystemRam() return 0; // nothing found } +uint64_t Sys::getSystemSwap() +{ + std::string token; +#ifdef Q_OS_LINUX + std::ifstream file("/proc/meminfo"); + while(file >> token) + { + if(token == "SwapTotal:") + { + uint64_t swap; + if(file >> swap) + { + return swap * 1024ull; + } + else + { + return 0; + } + } + file.ignore(std::numeric_limits::max(), '\n'); + } +#endif + return 0; +} + bool Sys::isCPU64bit() { return isSystem64bit(); diff --git a/libraries/systeminfo/src/sys_win32.cpp b/libraries/systeminfo/src/sys_win32.cpp index 752bbe0c..f9fcf98f 100644 --- a/libraries/systeminfo/src/sys_win32.cpp +++ b/libraries/systeminfo/src/sys_win32.cpp @@ -30,6 +30,11 @@ uint64_t Sys::getSystemRam() return (uint64_t)status.ullTotalPhys; } +uint64_t Sys::getSystemSwap() +{ + return 0; +} + bool Sys::isSystem64bit() { #if defined(_WIN64)