From 3dbd9c1148a996711d415e6750ec71d4abdb13f2 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Wed, 16 Nov 2011 10:29:33 +0100 Subject: [PATCH] Fix the LIMIT_AVAILABLE_MEMORY debug option. When limiting the available memory by reducing the page count it may not be enough to just limit sNumPages. Depending on the physical memory map non existing pages between ranges (sNonExistingPages) would still be added up and later subtracted from the sNumPages, resulting in a wrong max page count. Also due to the fixed removal of non existing page ranges the actually available memory would usually not be the amount set via LIMIT_AVAILABLE_MEMORY. Instead we now calculate the available memory when going through the physical memory ranges and limit/exit as soon as we've reached the desired amount of available memory (also ignoring further non-existing pages). --- src/system/kernel/vm/vm_page.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/system/kernel/vm/vm_page.cpp b/src/system/kernel/vm/vm_page.cpp index 6a6dbb1700..680e3f2d8d 100644 --- a/src/system/kernel/vm/vm_page.cpp +++ b/src/system/kernel/vm/vm_page.cpp @@ -3236,17 +3236,22 @@ vm_page_init_num_pages(kernel_args *args) sNonExistingPages += start - physicalPagesEnd; physicalPagesEnd = start + args->physical_memory_range[i].size / B_PAGE_SIZE; + +#ifdef LIMIT_AVAILABLE_MEMORY + page_num_t available + = physicalPagesEnd - sPhysicalPageOffset - sNonExistingPages; + if (available > LIMIT_AVAILABLE_MEMORY * (1024 * 1024 / B_PAGE_SIZE)) { + physicalPagesEnd = sPhysicalPageOffset + sNonExistingPages + + LIMIT_AVAILABLE_MEMORY * (1024 * 1024 / B_PAGE_SIZE); + break; + } +#endif } TRACE(("first phys page = %#" B_PRIxPHYSADDR ", end %#" B_PRIxPHYSADDR "\n", sPhysicalPageOffset, physicalPagesEnd)); sNumPages = physicalPagesEnd - sPhysicalPageOffset; - -#ifdef LIMIT_AVAILABLE_MEMORY - if (sNumPages > LIMIT_AVAILABLE_MEMORY * (1024 * 1024 / B_PAGE_SIZE)) - sNumPages = LIMIT_AVAILABLE_MEMORY * (1024 * 1024 / B_PAGE_SIZE); -#endif }