Kernel VM: Utilize swap_auto option
* Refine the swap logic a little * Refine header copyright to preferred format I had hamishm's verbal permission to change his entry
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012, Alexander von Gluck IV, [email protected].
|
|
||||||
* Copyright 2011, Hamish Morrison, [email protected].
|
|
||||||
* Copyright 2008, Zhao Shuai, [email protected].
|
* Copyright 2008, Zhao Shuai, [email protected].
|
||||||
* Copyright 2008-2011, Ingo Weinhold, [email protected].
|
* Copyright 2008-2011, Ingo Weinhold, [email protected].
|
||||||
* Copyright 2002-2009, Axel Dörfler, [email protected].
|
* Copyright 2002-2009, Axel Dörfler, [email protected].
|
||||||
@@ -8,6 +6,13 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
||||||
* Distributed under the terms of the NewOS License.
|
* Distributed under the terms of the NewOS License.
|
||||||
|
*
|
||||||
|
* Copyright 2011-2012 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Hamish Morrison, [email protected]
|
||||||
|
* Alexander von Gluck IV, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -1456,8 +1461,11 @@ swap_init_post_modules()
|
|||||||
|
|
||||||
if (enabled != NULL) {
|
if (enabled != NULL) {
|
||||||
swapEnabled = get_driver_boolean_parameter(settings, "vm",
|
swapEnabled = get_driver_boolean_parameter(settings, "vm",
|
||||||
false, false);
|
true, false);
|
||||||
|
swapAutomatic = get_driver_boolean_parameter(settings, "swap_auto",
|
||||||
|
true, false);
|
||||||
|
|
||||||
|
if (swapEnabled && !swapAutomatic) {
|
||||||
const char* size = get_driver_parameter(settings, "swap_size",
|
const char* size = get_driver_parameter(settings, "swap_size",
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
const char* volume = get_driver_parameter(settings,
|
const char* volume = get_driver_parameter(settings,
|
||||||
@@ -1471,7 +1479,7 @@ swap_init_post_modules()
|
|||||||
|
|
||||||
if (size != NULL && device != NULL && volume != NULL
|
if (size != NULL && device != NULL && volume != NULL
|
||||||
&& filesystem != NULL && capacity != NULL) {
|
&& filesystem != NULL && capacity != NULL) {
|
||||||
// User specified a size / volume
|
// User specified a size / volume that seems valid
|
||||||
swapAutomatic = false;
|
swapAutomatic = false;
|
||||||
swapSize = atoll(size);
|
swapSize = atoll(size);
|
||||||
strncpy(selectedVolume.name, volume,
|
strncpy(selectedVolume.name, volume,
|
||||||
@@ -1481,27 +1489,31 @@ swap_init_post_modules()
|
|||||||
strncpy(selectedVolume.filesystem, filesystem,
|
strncpy(selectedVolume.filesystem, filesystem,
|
||||||
sizeof(selectedVolume.filesystem));
|
sizeof(selectedVolume.filesystem));
|
||||||
selectedVolume.capacity = atoll(capacity);
|
selectedVolume.capacity = atoll(capacity);
|
||||||
} else if (size != NULL) {
|
} else {
|
||||||
// Older file format, no location information (assume /var/swap)
|
// Something isn't right with swap config, go auto
|
||||||
swapAutomatic = false;
|
swapAutomatic = true;
|
||||||
swapSize = atoll(size);
|
dprintf("%s: virtual_memory configuration is invalid, "
|
||||||
swapDeviceID = gBootDevice;
|
"using automatic swap\n", __func__);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unload_driver_settings(settings);
|
unload_driver_settings(settings);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (swapAutomatic) {
|
if (swapAutomatic) {
|
||||||
swapEnabled = true;
|
|
||||||
swapSize = (off_t)vm_page_num_pages() * B_PAGE_SIZE;
|
swapSize = (off_t)vm_page_num_pages() * B_PAGE_SIZE;
|
||||||
if (swapSize <= (1024 * 1024 * 1024)) {
|
if (swapSize <= (1024 * 1024 * 1024)) {
|
||||||
// Memory under 1GB? double the swap
|
// Memory under 1GB? double the swap
|
||||||
swapSize *= 2;
|
swapSize *= 2;
|
||||||
}
|
}
|
||||||
|
// Automatic swap defaults to the boot device
|
||||||
|
swapDeviceID = gBootDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!swapEnabled || swapSize < B_PAGE_SIZE)
|
if (!swapEnabled || swapSize < B_PAGE_SIZE) {
|
||||||
|
dprintf("%s: virtual_memory is disabled\n", __func__);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!swapAutomatic && swapDeviceID < 0) {
|
if (!swapAutomatic && swapDeviceID < 0) {
|
||||||
// If user-specified swap, and no swap device has been chosen yet...
|
// If user-specified swap, and no swap device has been chosen yet...
|
||||||
|
|||||||
Reference in New Issue
Block a user