From: Waldemar Kozaczuk <jwkozac...@gmail.com>
Committer: Nadav Har'El <n...@scylladb.com>
Branch: master

Fix bug in arch_setup_free_memory

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 <jwkozac...@gmail.com>
Message-Id: <20190821025311.8383-1-jwkozac...@gmail.com>

---
diff --git a/arch/x64/arch-setup.cc b/arch/x64/arch-setup.cc
--- 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
+}

--
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 osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/000000000000b2907405909c10a0%40google.com.

Reply via email to