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.
This commit is contained in:
Augustin Cavalier 2024-10-12 12:40:18 -04:00
parent bb7ace43c2
commit 12357279a8

View File

@ -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;