I'm not sure if I understand memory management properly
Posted: Thu May 07, 2015 1:03 am
My kernel's memory manager is a mess and I've decided to redo it properly. I'm worried that I had the wrong idea about how memory is supposed to work and I built it horribly because of that. Now, obviously the implementation of this stuff in my kernel is subjective, and I'm not looking for someone to tell me a specific algorithm (what would be the fun in that?) but I want to make sure I understand the general process I should look implement.
My first question:
What is the difference (if there is one) between kmalloc and the physical memory manager? The way I understand it, the physical memory manager hands out 4KiB 'pages', and kmalloc divys the pages up into smaller sections so the kernel can request, for example a 4 int array by using kmalloc(4*sizeof(int)). Kmalloc then looks at the 'pages' it has to work with and then sees if it needs more space, at which point it asks the physical memory manager to give it the next page. Basically, my current implementation is that kmalloc is just malloc for kernel-specific memory. Is my understanding of this process correct?
Where does paging come into this? I understand that it enables memory protection and lets you address pages in a different order than they are physically, but when I enable paging, should I go through with my physical memory manager and set up the page tables so that all the pages I have to work with are contiguous when addressed virtually through paging? The pages in which my kernel exists, however, should be 'identity mapped' (am I using that term correctly?) such that addressing it physically and addressing it virtually both work the same, correct?
Where does userspace come into all of this? Should I set up all my page tables to belong to the kernel and then change them as programs request memory? Should malloc rely on the physical memory manager, or some other process?
Thanks
My first question:
What is the difference (if there is one) between kmalloc and the physical memory manager? The way I understand it, the physical memory manager hands out 4KiB 'pages', and kmalloc divys the pages up into smaller sections so the kernel can request, for example a 4 int array by using kmalloc(4*sizeof(int)). Kmalloc then looks at the 'pages' it has to work with and then sees if it needs more space, at which point it asks the physical memory manager to give it the next page. Basically, my current implementation is that kmalloc is just malloc for kernel-specific memory. Is my understanding of this process correct?
Where does paging come into this? I understand that it enables memory protection and lets you address pages in a different order than they are physically, but when I enable paging, should I go through with my physical memory manager and set up the page tables so that all the pages I have to work with are contiguous when addressed virtually through paging? The pages in which my kernel exists, however, should be 'identity mapped' (am I using that term correctly?) such that addressing it physically and addressing it virtually both work the same, correct?
Where does userspace come into all of this? Should I set up all my page tables to belong to the kernel and then change them as programs request memory? Should malloc rely on the physical memory manager, or some other process?
Thanks