Skip to content

Commit 97fe8aa

Browse files
wkozaczuknyh
authored andcommitted
Start using memory below kernel
This patch improves memory utilization by making OSv use area below where kernel is loaded. This normally saves only 1M + 640K (low memory) howewer makes bigger difference when kernel_base in Makefile is bumped higher. So if one changes kernel_base to 10M then before this patch we would waste almost 10M of memory. Fixes #1012 Signed-off-by: Waldemar Kozaczuk <jwkozaczuk@gmail.com> Message-Id: <20190605043342.31586-1-jwkozaczuk@gmail.com>
1 parent 982acdb commit 97fe8aa

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

arch/x64/arch-setup.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void arch_setup_free_memory()
130130
// freed.
131131
for_each_e820_entry(e820_buffer, e820_size, [] (e820ent ent) {
132132
// can't free anything below edata, it's core code.
133-
// FIXME: can free below 2MB.
133+
// can't free anything below kernel at this moment
134134
if (ent.addr + ent.size <= edata) {
135135
return;
136136
}
@@ -159,6 +159,16 @@ void arch_setup_free_memory()
159159
// now that we have some free memory, we can start mapping the rest
160160
mmu::switch_to_runtime_page_tables();
161161
for_each_e820_entry(e820_buffer, e820_size, [] (e820ent ent) {
162+
//
163+
// Free the memory below elf_start which we could not before
164+
if (ent.addr < (u64)elf_start) {
165+
if (ent.addr + ent.size >= (u64)elf_start) {
166+
ent = truncate_above(ent, (u64) elf_start);
167+
}
168+
mmu::free_initial_memory_range(ent.addr, ent.size);
169+
return;
170+
}
171+
//
162172
// Ignore memory already freed above
163173
if (ent.addr + ent.size <= initial_map) {
164174
return;
@@ -167,7 +177,7 @@ void arch_setup_free_memory()
167177
ent = truncate_below(ent, initial_map);
168178
}
169179
for (auto&& area : mmu::identity_mapped_areas) {
170-
auto base = reinterpret_cast<void*>(get_mem_area_base(area));
180+
auto base = reinterpret_cast<void*>(get_mem_area_base(area));
171181
mmu::linear_map(base + ent.addr, ent.addr, ent.size, ~0);
172182
}
173183
mmu::free_initial_memory_range(ent.addr, ent.size);

0 commit comments

Comments
 (0)