Clarification on how kmalloc works
Posted: Sun Dec 21, 2014 10:52 pm
I'm ready to begin more memory management for my OS. I have a physical memory manager set up, and paging enabled. Now I want to work on kmalloc, but I wanted to be sure I understood the process. Here's the way I see it, and I'd love to get more information about how the kmalloc process usually works:
1: Find the first amount of contiguous memory big enough to hold what is requested. I plan to use a doubly-linked list to map out memory, with pointers to the next and previous spaces, as well as information about the size and availabilty (free/allocated) of each section of memory.
2: If the current amount of memory we're using is not big enough, request from the physical memory manager to free a new block(s) for use. We'll have the end of our previous block point to this new one, and the beginning of our new one will point back to the old one.
3: If we had to request a new block(s), give it a page table entry that registers it as both present and belonging to the kernel
4: Now we can divy up the block(s) into the amount of memory requested. Mark the section as allocated.
5: Return the pointer to our section
6: Freeing works by checking neighboring blocks for contiguous free space and consolidating. If an entire block is free, we free it in the physical memory manager and set its page table entry to 'Not present'
Is this a viable process for a memory manager? Am I forgetting anything important?
1: Find the first amount of contiguous memory big enough to hold what is requested. I plan to use a doubly-linked list to map out memory, with pointers to the next and previous spaces, as well as information about the size and availabilty (free/allocated) of each section of memory.
2: If the current amount of memory we're using is not big enough, request from the physical memory manager to free a new block(s) for use. We'll have the end of our previous block point to this new one, and the beginning of our new one will point back to the old one.
3: If we had to request a new block(s), give it a page table entry that registers it as both present and belonging to the kernel
4: Now we can divy up the block(s) into the amount of memory requested. Mark the section as allocated.
5: Return the pointer to our section
6: Freeing works by checking neighboring blocks for contiguous free space and consolidating. If an entire block is free, we free it in the physical memory manager and set its page table entry to 'Not present'
Is this a viable process for a memory manager? Am I forgetting anything important?