VM Preflet: Add an automatic swap option swap_auto
* Add swap_auto to the virtual memory settings file * Disable controls based on the context of what is enabled * hamishm gave permission to adjust his copyrights to Haiku, Inc.
This commit is contained in:
@@ -1,7 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2011, Hamish Morrison, [email protected]
|
|
||||||
* Copyright 2005, Axel Dörfler, [email protected]
|
* Copyright 2005, Axel Dörfler, [email protected]
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Copyright 2010-2012 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Hamish Morrison, [email protected]
|
||||||
|
* Alexander von Gluck, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -27,6 +33,7 @@ static const off_t kMegaByte = 1024 * 1024;
|
|||||||
Settings::Settings()
|
Settings::Settings()
|
||||||
{
|
{
|
||||||
fDefaultSettings.enabled = true;
|
fDefaultSettings.enabled = true;
|
||||||
|
fDefaultSettings.automatic = true;
|
||||||
|
|
||||||
system_info sysInfo;
|
system_info sysInfo;
|
||||||
get_system_info(&sysInfo);
|
get_system_info(&sysInfo);
|
||||||
@@ -44,6 +51,15 @@ Settings::SetSwapEnabled(bool enabled, bool revertable)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Settings::SetSwapAutomatic(bool automatic, bool revertable)
|
||||||
|
{
|
||||||
|
fCurrentSettings.automatic = automatic;
|
||||||
|
if (!revertable)
|
||||||
|
fInitialSettings.automatic = automatic;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Settings::SetSwapSize(off_t size, bool revertable)
|
Settings::SetSwapSize(off_t size, bool revertable)
|
||||||
{
|
{
|
||||||
@@ -116,6 +132,8 @@ Settings::ReadSwapSettings()
|
|||||||
return kErrorSettingsNotFound;
|
return kErrorSettingsNotFound;
|
||||||
|
|
||||||
const char* enabled = get_driver_parameter(settings, "vm", NULL, NULL);
|
const char* enabled = get_driver_parameter(settings, "vm", NULL, NULL);
|
||||||
|
const char* automatic = get_driver_parameter(settings, "swap_auto",
|
||||||
|
NULL, NULL);
|
||||||
const char* size = get_driver_parameter(settings, "swap_size", NULL, NULL);
|
const char* size = get_driver_parameter(settings, "swap_size", NULL, NULL);
|
||||||
const char* volume = get_driver_parameter(settings, "swap_volume_name",
|
const char* volume = get_driver_parameter(settings, "swap_volume_name",
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
@@ -126,14 +144,16 @@ Settings::ReadSwapSettings()
|
|||||||
const char* capacity = get_driver_parameter(settings,
|
const char* capacity = get_driver_parameter(settings,
|
||||||
"swap_volume_capacity", NULL, NULL);
|
"swap_volume_capacity", NULL, NULL);
|
||||||
|
|
||||||
if (enabled == NULL || size == NULL || device == NULL || volume == NULL
|
if (enabled == NULL || automatic == NULL || size == NULL || device == NULL
|
||||||
|| capacity == NULL || filesystem == NULL)
|
|| volume == NULL || capacity == NULL || filesystem == NULL)
|
||||||
return kErrorSettingsInvalid;
|
return kErrorSettingsInvalid;
|
||||||
|
|
||||||
off_t volCapacity = atoll(capacity);
|
off_t volCapacity = atoll(capacity);
|
||||||
|
|
||||||
SetSwapEnabled(get_driver_boolean_parameter(settings,
|
SetSwapEnabled(get_driver_boolean_parameter(settings,
|
||||||
"vm", false, false));
|
"vm", true, false));
|
||||||
|
SetSwapAutomatic(get_driver_boolean_parameter(settings,
|
||||||
|
"swap_auto", true, false));
|
||||||
SetSwapSize(atoll(size));
|
SetSwapSize(atoll(size));
|
||||||
unload_driver_settings(settings);
|
unload_driver_settings(settings);
|
||||||
|
|
||||||
@@ -193,11 +213,12 @@ Settings::WriteSwapSettings()
|
|||||||
fs_stat_dev(SwapVolume(), &info);
|
fs_stat_dev(SwapVolume(), &info);
|
||||||
|
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
snprintf(buffer, sizeof(buffer), "vm %s\nswap_size %lld\n"
|
snprintf(buffer, sizeof(buffer), "vm %s\nswap_auto %s\nswap_size %lld\n"
|
||||||
"swap_volume_name %s\nswap_volume_device %s\n"
|
"swap_volume_name %s\nswap_volume_device %s\n"
|
||||||
"swap_volume_filesystem %s\nswap_volume_capacity %lld\n",
|
"swap_volume_filesystem %s\nswap_volume_capacity %lld\n",
|
||||||
SwapEnabled() ? "on" : "off", SwapSize(), info.volume_name,
|
SwapEnabled() ? "on" : "off", SwapAutomatic() ? "yes" : "no",
|
||||||
info.device_name, info.fsh_name, info.total_blocks * info.block_size);
|
SwapSize(), info.volume_name, info.device_name, info.fsh_name,
|
||||||
|
info.total_blocks * info.block_size);
|
||||||
|
|
||||||
file.Write(buffer, strlen(buffer));
|
file.Write(buffer, strlen(buffer));
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -208,6 +229,7 @@ bool
|
|||||||
Settings::IsRevertable()
|
Settings::IsRevertable()
|
||||||
{
|
{
|
||||||
return SwapEnabled() != fInitialSettings.enabled
|
return SwapEnabled() != fInitialSettings.enabled
|
||||||
|
|| SwapAutomatic() != fInitialSettings.automatic
|
||||||
|| SwapSize() != fInitialSettings.size
|
|| SwapSize() != fInitialSettings.size
|
||||||
|| SwapVolume() != fInitialSettings.volume;
|
|| SwapVolume() != fInitialSettings.volume;
|
||||||
}
|
}
|
||||||
@@ -217,6 +239,7 @@ void
|
|||||||
Settings::RevertSwapSettings()
|
Settings::RevertSwapSettings()
|
||||||
{
|
{
|
||||||
SetSwapEnabled(fInitialSettings.enabled);
|
SetSwapEnabled(fInitialSettings.enabled);
|
||||||
|
SetSwapAutomatic(fInitialSettings.automatic);
|
||||||
SetSwapSize(fInitialSettings.size);
|
SetSwapSize(fInitialSettings.size);
|
||||||
SetSwapVolume(fInitialSettings.volume);
|
SetSwapVolume(fInitialSettings.volume);
|
||||||
}
|
}
|
||||||
@@ -226,6 +249,7 @@ bool
|
|||||||
Settings::IsDefaultable()
|
Settings::IsDefaultable()
|
||||||
{
|
{
|
||||||
return SwapEnabled() != fDefaultSettings.enabled
|
return SwapEnabled() != fDefaultSettings.enabled
|
||||||
|
|| SwapAutomatic() != fDefaultSettings.automatic
|
||||||
|| SwapSize() != fDefaultSettings.size
|
|| SwapSize() != fDefaultSettings.size
|
||||||
|| SwapVolume() != fDefaultSettings.volume;
|
|| SwapVolume() != fDefaultSettings.volume;
|
||||||
}
|
}
|
||||||
@@ -235,6 +259,7 @@ void
|
|||||||
Settings::DefaultSwapSettings(bool revertable)
|
Settings::DefaultSwapSettings(bool revertable)
|
||||||
{
|
{
|
||||||
SetSwapEnabled(fDefaultSettings.enabled);
|
SetSwapEnabled(fDefaultSettings.enabled);
|
||||||
|
SetSwapAutomatic(fDefaultSettings.automatic);
|
||||||
SetSwapSize(fDefaultSettings.size);
|
SetSwapSize(fDefaultSettings.size);
|
||||||
SetSwapVolume(fDefaultSettings.volume);
|
SetSwapVolume(fDefaultSettings.volume);
|
||||||
if (!revertable)
|
if (!revertable)
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011, Hamish Morrison, [email protected]
|
|
||||||
* Copyright 2005, Axel Dörfler, [email protected]
|
* Copyright 2005, Axel Dörfler, [email protected]
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Copyright 2010-2012 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Hamish Morrison, [email protected]
|
||||||
|
* Alexander von Gluck, [email protected]
|
||||||
*/
|
*/
|
||||||
#ifndef SETTINGS_H
|
#ifndef SETTINGS_H
|
||||||
#define SETTINGS_H
|
#define SETTINGS_H
|
||||||
@@ -18,19 +24,23 @@ static const int32 kErrorSettingsInvalid = B_ERRORS_END + 2;
|
|||||||
static const int32 kErrorVolumeNotFound = B_ERRORS_END + 3;
|
static const int32 kErrorVolumeNotFound = B_ERRORS_END + 3;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Settings {
|
class Settings {
|
||||||
public:
|
public:
|
||||||
Settings();
|
Settings();
|
||||||
|
|
||||||
bool SwapEnabled() const
|
bool SwapEnabled() const
|
||||||
{ return fCurrentSettings.enabled; }
|
{ return fCurrentSettings.enabled; }
|
||||||
|
bool SwapAutomatic() const
|
||||||
|
{ return fCurrentSettings.automatic; }
|
||||||
off_t SwapSize() const { return fCurrentSettings.size; }
|
off_t SwapSize() const { return fCurrentSettings.size; }
|
||||||
dev_t SwapVolume() { return fCurrentSettings.volume; }
|
dev_t SwapVolume() { return fCurrentSettings.volume; }
|
||||||
BPoint WindowPosition() const { return fWindowPosition; }
|
BPoint WindowPosition() const { return fWindowPosition; }
|
||||||
|
|
||||||
|
|
||||||
void SetSwapEnabled(bool enabled,
|
void SetSwapEnabled(bool enabled,
|
||||||
bool revertable = true);
|
bool revertable = true);
|
||||||
|
void SetSwapAutomatic(bool automatic,
|
||||||
|
bool revertable = true);
|
||||||
void SetSwapSize(off_t size, bool revertable = true);
|
void SetSwapSize(off_t size, bool revertable = true);
|
||||||
void SetSwapVolume(dev_t volume,
|
void SetSwapVolume(dev_t volume,
|
||||||
bool revertable = true);
|
bool revertable = true);
|
||||||
@@ -49,6 +59,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
struct SwapSettings {
|
struct SwapSettings {
|
||||||
bool enabled;
|
bool enabled;
|
||||||
|
bool automatic;
|
||||||
off_t size;
|
off_t size;
|
||||||
dev_t volume;
|
dev_t volume;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2011, Hamish Morrison, [email protected]
|
|
||||||
* Copyright 2005-2009, Axel Dörfler, [email protected]
|
* Copyright 2005-2009, Axel Dörfler, [email protected]
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Copyright 2010-2012 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Hamish Morrison, [email protected]
|
||||||
|
* Alexander von Gluck, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -41,6 +47,7 @@ static const uint32 kMsgDefaults = 'dflt';
|
|||||||
static const uint32 kMsgRevert = 'rvrt';
|
static const uint32 kMsgRevert = 'rvrt';
|
||||||
static const uint32 kMsgSliderUpdate = 'slup';
|
static const uint32 kMsgSliderUpdate = 'slup';
|
||||||
static const uint32 kMsgSwapEnabledUpdate = 'swen';
|
static const uint32 kMsgSwapEnabledUpdate = 'swen';
|
||||||
|
static const uint32 kMsgSwapAutomaticUpdate = 'swat';
|
||||||
static const uint32 kMsgVolumeSelected = 'vlsl';
|
static const uint32 kMsgVolumeSelected = 'vlsl';
|
||||||
static const off_t kMegaByte = 1024 * 1024;
|
static const off_t kMegaByte = 1024 * 1024;
|
||||||
static dev_t gBootDev = -1;
|
static dev_t gBootDev = -1;
|
||||||
@@ -154,6 +161,11 @@ SettingsWindow::SettingsWindow()
|
|||||||
new BMessage(kMsgSwapEnabledUpdate));
|
new BMessage(kMsgSwapEnabledUpdate));
|
||||||
fSwapEnabledCheckBox->SetExplicitAlignment(align);
|
fSwapEnabledCheckBox->SetExplicitAlignment(align);
|
||||||
|
|
||||||
|
fSwapAutomaticCheckBox = new BCheckBox("auto swap",
|
||||||
|
B_TRANSLATE("Choose swap size automatically"),
|
||||||
|
new BMessage(kMsgSwapAutomaticUpdate));
|
||||||
|
fSwapEnabledCheckBox->SetExplicitAlignment(align);
|
||||||
|
|
||||||
char sizeStr[16];
|
char sizeStr[16];
|
||||||
system_info info;
|
system_info info;
|
||||||
get_system_info(&info);
|
get_system_info(&info);
|
||||||
@@ -204,6 +216,7 @@ SettingsWindow::SettingsWindow()
|
|||||||
box->AddChild(BLayoutBuilder::Group<>(B_VERTICAL, B_USE_DEFAULT_SPACING)
|
box->AddChild(BLayoutBuilder::Group<>(B_VERTICAL, B_USE_DEFAULT_SPACING)
|
||||||
.Add(memoryView)
|
.Add(memoryView)
|
||||||
.Add(swapFileView)
|
.Add(swapFileView)
|
||||||
|
.Add(fSwapAutomaticCheckBox)
|
||||||
.Add(fVolumeMenuField)
|
.Add(fVolumeMenuField)
|
||||||
.Add(fSizeSlider)
|
.Add(fSizeSlider)
|
||||||
.Add(fWarningStringView)
|
.Add(fWarningStringView)
|
||||||
@@ -331,6 +344,12 @@ SettingsWindow::MessageReceived(BMessage* message)
|
|||||||
_Update();
|
_Update();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case kMsgSwapAutomaticUpdate:
|
||||||
|
{
|
||||||
|
fSettings.SetSwapAutomatic(fSwapAutomaticCheckBox->Value());
|
||||||
|
_Update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(message);
|
BWindow::MessageReceived(message);
|
||||||
@@ -404,6 +423,7 @@ void
|
|||||||
SettingsWindow::_Update()
|
SettingsWindow::_Update()
|
||||||
{
|
{
|
||||||
fSwapEnabledCheckBox->SetValue(fSettings.SwapEnabled());
|
fSwapEnabledCheckBox->SetValue(fSettings.SwapEnabled());
|
||||||
|
fSwapAutomaticCheckBox->SetValue(fSettings.SwapAutomatic());
|
||||||
|
|
||||||
VolumeMenuItem* item = _FindVolumeMenuItem(fSettings.SwapVolume());
|
VolumeMenuItem* item = _FindVolumeMenuItem(fSettings.SwapVolume());
|
||||||
if (item != NULL) {
|
if (item != NULL) {
|
||||||
@@ -445,4 +465,14 @@ SettingsWindow::_Update()
|
|||||||
fWarningStringView->Hide();
|
fWarningStringView->Hide();
|
||||||
fRevertButton->SetEnabled(revertable);
|
fRevertButton->SetEnabled(revertable);
|
||||||
fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
|
fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
|
||||||
|
|
||||||
|
// Automatic Swap depends on swap being enabled
|
||||||
|
fSwapAutomaticCheckBox->SetEnabled(fSettings.SwapEnabled());
|
||||||
|
|
||||||
|
// Manual swap settings depend on enabled swap
|
||||||
|
// and automatic swap being disabled
|
||||||
|
fSizeSlider->SetEnabled(fSettings.SwapEnabled()
|
||||||
|
&& !fSwapAutomaticCheckBox->Value());
|
||||||
|
fVolumeMenuField->SetEnabled(fSettings.SwapEnabled()
|
||||||
|
&& !fSwapAutomaticCheckBox->Value());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011, Hamish Morrison, [email protected]
|
|
||||||
* Copyright 2005-2006, Axel Dörfler, [email protected]
|
* Copyright 2005-2006, Axel Dörfler, [email protected]
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Copyright 2010-2012 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Hamish Morrison, [email protected]
|
||||||
|
* Alexander von Gluck, [email protected]
|
||||||
*/
|
*/
|
||||||
#ifndef SETTINGS_WINDOW_H
|
#ifndef SETTINGS_WINDOW_H
|
||||||
#define SETTINGS_WINDOW_H
|
#define SETTINGS_WINDOW_H
|
||||||
@@ -66,6 +72,7 @@ private:
|
|||||||
void _Update();
|
void _Update();
|
||||||
|
|
||||||
BCheckBox* fSwapEnabledCheckBox;
|
BCheckBox* fSwapEnabledCheckBox;
|
||||||
|
BCheckBox* fSwapAutomaticCheckBox;
|
||||||
BSlider* fSizeSlider;
|
BSlider* fSizeSlider;
|
||||||
BButton* fDefaultsButton;
|
BButton* fDefaultsButton;
|
||||||
BButton* fRevertButton;
|
BButton* fRevertButton;
|
||||||
|
|||||||
Reference in New Issue
Block a user