SImplify init_physical_frame_allocator() even more
This commit is contained in:
parent
5f6c48bd12
commit
0d10c98477
@ -54,29 +54,26 @@ namespace MemoryManager
|
|||||||
|
|
||||||
void init_physical_frame_allocator()
|
void init_physical_frame_allocator()
|
||||||
{
|
{
|
||||||
u64 total_mem = 0;
|
|
||||||
|
|
||||||
MemoryMapIterator iter;
|
MemoryMapIterator iter;
|
||||||
|
|
||||||
MemoryMapEntry entry;
|
MemoryMapEntry entry;
|
||||||
while (iter.next().try_set_value(entry)) { total_mem += entry.size; }
|
|
||||||
|
|
||||||
auto largest_free = iter.largest_free();
|
auto largest_free = iter.largest_free();
|
||||||
|
|
||||||
void* biggest_usable_memory_block = (void*)largest_free.ptr;
|
expect(largest_free.free, "We were given a largest free block that isn't even free!");
|
||||||
u64 biggest_usable_memory_block_size = largest_free.size;
|
|
||||||
|
|
||||||
// The entire physical address space. May contain inexistent memory holes, thus differs from total_mem which
|
// The entire physical address space. May contain inexistent memory holes, thus differs from total_mem which
|
||||||
// only counts existent memory. Our bitmap needs to have space for all of the physical address space, since
|
// only counts existent memory. Our bitmap needs to have space for all of the physical address space, since
|
||||||
// usable addresses will be scattered across it.
|
// usable addresses will be scattered across it.
|
||||||
usize physical_address_space_size = get_physical_address_space_size();
|
usize physical_address_space_size = get_physical_address_space_size();
|
||||||
|
|
||||||
char* frame_bitmap_addr = (char*)biggest_usable_memory_block;
|
// We store our frame bitmap at the beginning of the largest free memory block.
|
||||||
|
char* frame_bitmap_addr = (char*)largest_free.ptr;
|
||||||
|
|
||||||
usize frame_bitmap_size = physical_address_space_size / ARCH_PAGE_SIZE / 8 + 1;
|
usize frame_bitmap_size = physical_address_space_size / ARCH_PAGE_SIZE / 8 + 1;
|
||||||
|
|
||||||
// This should never happen, unless memory is very fragmented. Usually there is always a very big block of
|
// This should never happen, unless memory is very fragmented. Usually there is always a very big block of
|
||||||
// usable memory and then some tiny blocks around it.
|
// usable memory and then some tiny blocks around it.
|
||||||
if (frame_bitmap_size >= biggest_usable_memory_block_size) [[unlikely]]
|
if (frame_bitmap_size >= largest_free.size) [[unlikely]]
|
||||||
{
|
{
|
||||||
kerrorln("ERROR: No single memory block is enough to hold the frame bitmap");
|
kerrorln("ERROR: No single memory block is enough to hold the frame bitmap");
|
||||||
CPU::efficient_halt();
|
CPU::efficient_halt();
|
||||||
|
Loading…
Reference in New Issue
Block a user