hrev44613 adds 1 changeset to branch 'master' old head: 3e01905acab8ae1775fe35e2dab4e7ad70f7e581 new head: 4517ef57289459f01979c81969587cc1abcbdd9f ---------------------------------------------------------------------------- 4517ef5: Kernel VM: A few changes as per Axel in #7742 * Avoid floating point numbers in the kernel * Warning would always show if custom swap file in use * Don't change a custom swap file size if low space occurs * Ram > 1GB? Don't double the memory for the automatic size [ Alexander von Gluck IV <kallisti5@xxxxxxxxxxx> ] ---------------------------------------------------------------------------- Revision: hrev44613 Commit: 4517ef57289459f01979c81969587cc1abcbdd9f URL: http://cgit.haiku-os.org/haiku/commit/?id=4517ef5 Author: Alexander von Gluck IV <kallisti5@xxxxxxxxxxx> Date: Tue Sep 4 20:35:10 2012 UTC Ticket: https://dev.haiku-os.org/ticket/7742 ---------------------------------------------------------------------------- 1 file changed, 14 insertions(+), 17 deletions(-) src/system/kernel/vm/VMAnonymousCache.cpp | 31 +++++++++++-------------- ---------------------------------------------------------------------------- diff --git a/src/system/kernel/vm/VMAnonymousCache.cpp b/src/system/kernel/vm/VMAnonymousCache.cpp index 4c597d9..ae0d979 100644 --- a/src/system/kernel/vm/VMAnonymousCache.cpp +++ b/src/system/kernel/vm/VMAnonymousCache.cpp @@ -1493,7 +1493,11 @@ swap_init_post_modules() if (swapAutomatic) { swapEnabled = true; - swapSize = (off_t)vm_page_num_pages() * B_PAGE_SIZE * 2; + swapSize = (off_t)vm_page_num_pages() * B_PAGE_SIZE; + if (swapSize <= (1024 * 1024 * 1024)) { + // Memory under 1GB? double the swap + swapSize *= 2; + } } if (!swapEnabled || swapSize < B_PAGE_SIZE) @@ -1557,26 +1561,19 @@ swap_init_post_modules() const char* swapPath = path.Path(); // Swap size limits prevent oversized swap files - off_t existingSwapSize = 0; - struct stat existingSwapStat; - if (stat(swapPath, &existingSwapStat) == 0) - existingSwapSize = existingSwapStat.st_size; - - off_t freeSpace = info.free_blocks * info.block_size + existingSwapSize; - off_t maxSwap = freeSpace; if (swapAutomatic) { + off_t existingSwapSize = 0; + struct stat existingSwapStat; + if (stat(swapPath, &existingSwapStat) == 0) + existingSwapSize = existingSwapStat.st_size; + + off_t freeSpace = info.free_blocks * info.block_size + existingSwapSize; + // Adjust automatic swap to a maximum of 25% of the free space - maxSwap = (off_t)(0.25 * freeSpace); - } else { - // If user specified, leave 10% of the disk free - maxSwap = freeSpace - (off_t)(0.10 * freeSpace); - dprintf("%s: Warning: User specified swap file consumes over 90%% of " - "the available free space, limiting to 90%%\n", __func__); + if (swapSize > (freeSpace / 4)) + swapSize = (freeSpace / 4); } - if (swapSize > maxSwap) - swapSize = maxSwap; - // Create swap file int fd = open(swapPath, O_RDWR | O_CREAT | O_NOCACHE, S_IRUSR | S_IWUSR); if (fd < 0) {