Memory management questions.
Posted: Wed Jan 28, 2009 7:19 am
Hello there!
I want to ask few questions about memory management:
For now I got paging run and work: I mapped the whole area from 0 to _end (as defined in linker script) as the kernel directory. I used placement malloc as was described in James Molloy's tutorial, to allocate space for kernel needed stuff. Now I want to implant heap.
But I have a question, the heap is actually the memory manager? I mean if I do heap for kernel and heap for user I got memory management? Or I have to do something else?
Also I would like to ask about how to implement heap:
I tough about linked list, The list will hold pointers to free areas and their size, from the beginning the list will have only 1 pointer that points to the start of the kernel heap (I don't bother thinking about user heap, I have pretty long way till Ill reach the user space), and the size of the heap. When Ill want to allocate X bytes Ill go trough the list and find the first free block that is >= X, Ill put a header in front of that block that will contain data about this block, and at the end Ill put a footer (The approach is pretty similar to James Malloy's heap tutorial). IMHO this is pretty good method, but can be slow if I have a lot of free blocks referenced to different places in memory. So I tough also about binary search tree or even AVL tree, what do you think?
Thanks a lot!
I want to ask few questions about memory management:
For now I got paging run and work: I mapped the whole area from 0 to _end (as defined in linker script) as the kernel directory. I used placement malloc as was described in James Molloy's tutorial, to allocate space for kernel needed stuff. Now I want to implant heap.
But I have a question, the heap is actually the memory manager? I mean if I do heap for kernel and heap for user I got memory management? Or I have to do something else?
Also I would like to ask about how to implement heap:
I tough about linked list, The list will hold pointers to free areas and their size, from the beginning the list will have only 1 pointer that points to the start of the kernel heap (I don't bother thinking about user heap, I have pretty long way till Ill reach the user space), and the size of the heap. When Ill want to allocate X bytes Ill go trough the list and find the first free block that is >= X, Ill put a header in front of that block that will contain data about this block, and at the end Ill put a footer (The approach is pretty similar to James Malloy's heap tutorial). IMHO this is pretty good method, but can be slow if I have a lot of free blocks referenced to different places in memory. So I tough also about binary search tree or even AVL tree, what do you think?
Thanks a lot!