AndrewAPrice wrote:
Do you need a kernel heap before you setting up a physical allocator and paging?
I ask this because the paging structures (page tables, page directories, etc.) are 4KB - the size of a page. I allocate my boot stack and boot-time paging structures in the linker script, and I use GRUB as my bootloader, so I'd asssume GRUB would give me an error if it tries to load my kernel into memory that doesn't exist.
One of the first things I do is loop through the multiboot header that GRUB populates, and create a linked stack of free memory pages (I store the pointer to the next free page at the start of the previous page.)
Do you store the pointer in the page itself, or in some external management structure? I ask, because while your scheme has the benefit of O(1) allocation, it does require all your physical memory to be mapped into virtual memory if you store the pointers in the page itself.
Of course, that's not likely to be a problem for a 64-bit only OS, with vast swathes of VM at its disposal. My OS, on the other hand, is currently 32-bit (and I want to keep it 32-bit capable and not assume I can map all of HW memory in VM) and just as an added bonus, I'm trying to keep the OS mapped above 0xf0000000 on x86, to give me as much user address space as possible.
My page allocator is bit mapped, and so there is a small cost to scanning memory for free pages.