From 12357279a88653971339f1cd5bf745c86bb8aea4 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sat, 12 Oct 2024 12:40:18 -0400 Subject: [PATCH] kernel/vm: Try expanding upwards from the last allocated range. The most likely case is that the last range is the one we actually want to try expanding, so this should be a slight efficiency gain. But it also will help in avoiding allocating "low" memory when it isn't necessary. --- src/system/kernel/vm/vm.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index 44c59058b4..7540c677b0 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -4341,12 +4341,12 @@ vm_allocate_early_physical_page(kernel_args* args) } // Try expanding the existing physical ranges upwards. - for (uint32 i = 0; i < args->num_physical_allocated_ranges; i++) { + for (int32 i = args->num_physical_allocated_ranges - 1; i > 0; i--) { addr_range& range = args->physical_allocated_range[i]; phys_addr_t nextPage = range.start + range.size; // make sure the next page does not collide with the next allocated range - if ((i + 1) < args->num_physical_allocated_ranges) { + if ((i + 1) < (int32)args->num_physical_allocated_ranges) { addr_range& nextRange = args->physical_allocated_range[i + 1]; if (nextRange.size != 0 && nextPage >= nextRange.start) continue;