-
Notifications
You must be signed in to change notification settings - Fork 389
support booting with more than 4G of memory #2361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
08c9539
3b0b641
8a39558
b3e365f
b49ef65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,16 @@ | ||
| #include "kernel/memory.hpp" | ||
| #include <os> | ||
| #include <service> | ||
|
|
||
| void Service::start(const std::string& args){ | ||
| printf("Args = %s\n", args.c_str()); | ||
| printf("Try giving the service less memory, eg. 10MB in vm.json\n"); | ||
| printf("Service done. Shutting down...\n"); | ||
| std::println("Hello from the example unikernel!"); | ||
|
|
||
| std::println("Current virtual mappings:"); | ||
| for (const auto& entry : os::mem::vmmap()) | ||
| std::println(" {}", entry.second.to_string()); | ||
|
|
||
| std::println("Tip: Try changing how much memory you give to the service in vm.json"); | ||
| std::println("Service done. Shutting down..."); | ||
|
|
||
| os::shutdown(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "mem": 16384 | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -376,6 +376,8 @@ uintptr_t mem::active_page_size(uintptr_t addr){ | |
|
|
||
| void allow_executable() | ||
| { | ||
| // FIXME: this seems weird. is this only used for tests? | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is used for the executable part of the IncludeOS service binary |
||
|
|
||
| INFO2("* Allowing execute on %p -> %p", | ||
| (void*) __exec_begin, (void*)__exec_end); | ||
|
|
||
|
|
@@ -391,7 +393,7 @@ void allow_executable() | |
| m.page_sizes = os::mem::Map::any_size; | ||
| m.flags = os::mem::Access::execute | os::mem::Access::read; | ||
|
|
||
| os::mem::map(m, "ELF .text"); | ||
| os::mem::map(m, "Executable"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps the text could be "ELF executable" |
||
| } | ||
|
|
||
| /* TODO: Compiler warning unused | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,7 @@ template<typename Fn, typename ...Args> | |
| inline auto strace(Fn func, [[maybe_unused]]const char* name, Args&&... args) { | ||
| if (!kernel::state().allow_syscalls) { | ||
| fprintf(stderr, "Syscalls not allowed here. Unexpected call to %s - terminating\n", name); | ||
| os::halt(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of halt here it would better to fix the Expect-call so we can get stack traces when this happens after boot (and heap is available) |
||
| Expects(kernel::state().allow_syscalls); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,8 @@ extern uintptr_t _ELF_END_; | |
| // in kernel/os.cpp | ||
| extern bool os_default_stdout; | ||
|
|
||
| extern std::span<multiboot_memory_map_t> _multiboot_memory_maps(); | ||
|
|
||
| struct alignas(SMP_ALIGN) OS_CPU { | ||
| uint64_t cycles_hlt = 0; | ||
| }; | ||
|
|
@@ -125,10 +127,6 @@ void kernel::start(uint32_t boot_magic, uint32_t boot_addr) | |
|
|
||
| MYINFO("Total memory detected as %s ", util::Byte_r(kernel::memory_end()).to_string().c_str()); | ||
|
|
||
| // Give the rest of physical memory to heap | ||
| kernel::state().heap_max = kernel::memory_end() - 1; | ||
| assert(kernel::heap_begin() != 0x0 and kernel::heap_max() != 0x0); | ||
|
|
||
| PROFILE("Memory map"); | ||
| // Assign memory ranges used by the kernel | ||
| auto& memmap = os::mem::vmmap(); | ||
|
|
@@ -145,13 +143,28 @@ void kernel::start(uint32_t boot_magic, uint32_t boot_addr) | |
| memmap.assign_range({0x10000, 0x9d3ff, "Stack"}); | ||
| #endif | ||
|
|
||
| // heap (physical) area | ||
| uintptr_t span_max = std::numeric_limits<std::ptrdiff_t>::max(); | ||
| uintptr_t heap_range_max_ = std::min(span_max, kernel::heap_max()); | ||
| multiboot_memory_map_t heap_map = {0,0,0,0}; | ||
| for (auto entry : _multiboot_memory_maps()) | ||
| { | ||
| if (not entry.is_available()) continue; | ||
|
|
||
| if (entry.len > heap_map.len) { | ||
| heap_map = entry; | ||
| } | ||
| } | ||
| uintptr_t end = heap_map.addr + heap_map.len - 1; | ||
|
|
||
| if (heap_map.addr < 0x1'000'000) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be solved by adding the LiveUpdate and Syslog ranges to the map statically? Should at least be commented here why there's a check |
||
| kernel::state().heap_begin = std::max((uintptr_t)0x1'000'000, (uintptr_t)heap_map.addr); | ||
| kernel::state().heap_max = std::min(kernel::heap_max(), end); | ||
| } else { | ||
| kernel::state().heap_begin = heap_map.addr; | ||
| kernel::state().heap_max = end; | ||
| } | ||
|
|
||
| INFO2("* Assigning heap 0x%zx -> 0x%zx", kernel::heap_begin(), heap_range_max_); | ||
| memmap.assign_range({kernel::heap_begin(), heap_range_max_, | ||
| "Dynamic memory", kernel::heap_usage }); | ||
|
|
||
| INFO2("* Assigning heap 0x%lx -> 0x%lx", kernel::heap_begin(), kernel::heap_max()); | ||
| memmap.assign_range({kernel::heap_begin(), kernel::heap_max(), "Heap", kernel::heap_usage }); | ||
|
|
||
| MYINFO("Virtual memory map"); | ||
| for (const auto& entry : memmap) | ||
|
|
@@ -182,7 +195,7 @@ void os::event_loop() | |
| __arch_poweroff(); | ||
| } | ||
|
|
||
|
|
||
| /* legacy boot is used when MULTIBOOT_BOOTLOADER_MAGIC is unset, see x86_pc/kernel_start.cpp */ | ||
| void kernel::legacy_boot() | ||
| { | ||
| // Fetch CMOS memory info (unfortunately this is maximally 10^16 kb) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a lot - could we make it smaller?