Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOISSUE count swaptotal in total ram (linux) #4599

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions launcher/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,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", "");
Expand Down
24 changes: 22 additions & 2 deletions launcher/ui/pages/global/JavaPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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());
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions launcher/ui/pages/global/JavaPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ class JavaPage : public QWidget, public BasePage
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();
Expand Down
10 changes: 10 additions & 0 deletions launcher/ui/pages/global/JavaPage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="allowSwapCheckBox">
<property name="text">
<string>Allow use of swap</string>
</property>
<property name="toolTip">
<string>Allows the usage of swap when specifying memory allocation.</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
2 changes: 2 additions & 0 deletions libraries/systeminfo/include/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ DistributionInfo getDistributionInfo();

uint64_t getSystemRam();

uint64_t getSystemSwap();

bool isSystem64bit();

bool isCPU64bit();
Expand Down
5 changes: 5 additions & 0 deletions libraries/systeminfo/src/sys_apple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions libraries/systeminfo/src/sys_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::streamsize>::max(), '\n');
}
#endif
return 0;
}

bool Sys::isCPU64bit()
{
return isSystem64bit();
Expand Down
5 changes: 5 additions & 0 deletions libraries/systeminfo/src/sys_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ uint64_t Sys::getSystemRam()
return (uint64_t)status.ullTotalPhys;
}

uint64_t Sys::getSystemSwap()
{
return 0;
}

bool Sys::isSystem64bit()
{
#if defined(_WIN64)
Expand Down