The commit 97fe8aa3d2d8f2c938fcaa379c44ae5a80dfbf33 adjusted logic in arch_setup_free_memory() to improve memory utilization by making OSv use memory below kernel (<= 2MB).
Ironically the new logic introduced new bug which led to much bigger waste of memory. Specifically it did not take into account the case of memory region starting below 2MB and ending above 1GB at the same time and make it skip the part above 1GB altogether. This patch fixes this bug and makes issue reported below go away. Fixes #1048 Signed-off-by: Waldemar Kozaczuk <[email protected]> --- arch/x64/arch-setup.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/x64/arch-setup.cc b/arch/x64/arch-setup.cc index e5fb7a6e..986a0928 100644 --- a/arch/x64/arch-setup.cc +++ b/arch/x64/arch-setup.cc @@ -175,11 +175,15 @@ void arch_setup_free_memory() // // Free the memory below elf_phys_start which we could not before if (ent.addr < (u64)elf_phys_start) { + auto ent_below_kernel = ent; if (ent.addr + ent.size >= (u64)elf_phys_start) { - ent = truncate_above(ent, (u64) elf_phys_start); + ent_below_kernel = truncate_above(ent, (u64) elf_phys_start); + } + mmu::free_initial_memory_range(ent_below_kernel.addr, ent_below_kernel.size); + // If there is nothing left below elf_phys_start return + if (ent.addr + ent.size <= (u64)elf_phys_start) { + return; } - mmu::free_initial_memory_range(ent.addr, ent.size); - return; } // // Ignore memory already freed above @@ -331,4 +335,4 @@ void reset_bootchart(osv_multiboot_info_type* mb_info) mb_info->tsc_uncompress_done_hi = now_high; mb_info->tsc_uncompress_done = now_low; -} \ No newline at end of file +} -- 2.20.1 -- You received this message because you are subscribed to the Google Groups "OSv Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/osv-dev/20190821025311.8383-1-jwkozaczuk%40gmail.com.
