Ok, so maybe I am way overthinking / overcomplicating this topic in my head. I think I posted on this once before but I can't for the life of me find the post (on a different board maybe? I don't know!) I am trying to figure out how to map virtual memory to dynamically allocated physical memory but I can't come up with what seems like should be a simple answer. So my page frame allocator hands out pages on a 4kb basis, so each physical page maps to a virtual page. The userspace will be from 0x00000000 to 0xbfffffff, and above the 3gb mark belongs to the kernel (this is pretty typical from what I can tell.) The kernel is mapped in at 0xc0000000 and I would ideally like to make a small buffer space for file transfers at the 0xd0000000 mark, map device drivers in at 0xe0000000, and kernel heap at 0xf0000000. The problem is, how do I determine where the physical pages should map into the address space? For example, if I would do something like:
Code: Select all
char *buffer = kernel_pages_allocate(5);
to allocate 5 blocks of 4Kb. The function should return a virtual address somewhere in the kernel heap where 5 blocks of 4kb exist. Now, when I free this memory:
and reallocate a new block of memory, how do I know where to go back into the virtual address space; in other words, how do I know that frame has been unmapped? I am trying to figure out the best way to handle the virtual address mapping; how would you guys do it? Should I look at something like a bitmap to show where there are holes in the virtual address space for the heap? Am I making any sense, or do I have no clue and need to rethink my entire existence? This feels like a huge mental block to me. I just can't seem to make sense of it in my head, so any insight or clarification is appreciated. It will greatly help me to see working examples or even just some clear examples, something that will help it click. Thanks guys!