diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2025-12-23 20:30:57 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2025-12-23 20:30:57 +0100 |
| commit | 47209f32e5b68f2b1190afd9c409da7dcc369514 (patch) | |
| tree | feab4c1af141cf25a2a4a2649023334f04a06ced /arch/x86_64/src | |
| parent | 2fc7576c3375dabeb273ca95cc702a1957dbab10 (diff) | |
| download | teachos-47209f32e5b68f2b1190afd9c409da7dcc369514.tar.xz teachos-47209f32e5b68f2b1190afd9c409da7dcc369514.zip | |
kapi/memory: implement multi-frame allocation
Diffstat (limited to 'arch/x86_64/src')
| -rw-r--r-- | arch/x86_64/src/memory/region_allocator.cpp | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/arch/x86_64/src/memory/region_allocator.cpp b/arch/x86_64/src/memory/region_allocator.cpp index efa1f4a..7a8fb8b 100644 --- a/arch/x86_64/src/memory/region_allocator.cpp +++ b/arch/x86_64/src/memory/region_allocator.cpp @@ -6,6 +6,7 @@ #include <multiboot2/information.hpp> #include <algorithm> +#include <cstddef> #include <optional> #include <ranges> #include <utility> @@ -56,7 +57,7 @@ namespace teachos::memory::x86_64 m_current_region = *lowest_region; if (auto start_of_region = frame::containing(physical_address{m_current_region->base}); - start_of_region < m_next_frame) + start_of_region > m_next_frame) { m_next_frame = start_of_region; } @@ -96,16 +97,32 @@ namespace teachos::memory::x86_64 return m_current_region.transform([this](auto) -> auto { return m_next_frame; }); } - auto region_allocator::allocate() noexcept -> std::optional<frame> + auto region_allocator::allocate_many(std::size_t count) noexcept -> std::optional<std::pair<frame, std::size_t>> { - return find_next_frame().transform([this](auto frame) -> auto { - auto result = frame; - ++m_next_frame; - return result; - }); + while (m_current_region) + { + auto result = find_next_frame(); + + if (result) + { + auto region_end = last_frame(*m_current_region); + if ((region_end.number() - result->number()) >= count) + { + m_next_frame = m_next_frame + count; + return std::make_pair(*result, count); + } + else + { + m_next_frame = region_end + 1; + choose_next_region(); + } + } + } + + return std::nullopt; } - auto region_allocator::release(frame) -> void {} + auto region_allocator::release_many(std::pair<frame, std::size_t>) -> void {} auto region_allocator::next_free_frame() noexcept -> std::optional<frame> { |
