Questions on memory management / buddy allocation
Posted: Sat Oct 18, 2008 6:23 pm
I've gotten to the point where I want to add some basic memory management, so I've been reading up on all sorts of ways to implement things. The buddy algorithm seems to make the most sense to me, but I have a few questions.
I like to think of a system in terms of layers, so I envision that allocating memory would consist of a few layers where each layer calls the one below:
malloc/kmalloc etc. (handles management of the allocated pages, and would be implemented in user-space as well)
page mapping (handles page tables and mapping of physical pages to virtual ones)
page allocation (handles allocation of physical pages, which is where the buddy algorithm would go)
I'd like to know if this is a sensible division or if I'm missing something, or making things needlessly complicated?
Secondly, I noticed that the buddy algorithm allows you to specify the order of allocation size, where 2^order decides the amount of pages allocated. But since you can normally simply re-map noncontiguous physical pages to contiguous virtual ones, why would you ever need to use an order other than 0? For example if something asks for 16 kB, couldn't you just allocate 4 kB four times and use the page mapping to string it together inside the virtual address space rather than demanding that it's also contiguous physically?
I like to think of a system in terms of layers, so I envision that allocating memory would consist of a few layers where each layer calls the one below:
malloc/kmalloc etc. (handles management of the allocated pages, and would be implemented in user-space as well)
page mapping (handles page tables and mapping of physical pages to virtual ones)
page allocation (handles allocation of physical pages, which is where the buddy algorithm would go)
I'd like to know if this is a sensible division or if I'm missing something, or making things needlessly complicated?
Secondly, I noticed that the buddy algorithm allows you to specify the order of allocation size, where 2^order decides the amount of pages allocated. But since you can normally simply re-map noncontiguous physical pages to contiguous virtual ones, why would you ever need to use an order other than 0? For example if something asks for 16 kB, couldn't you just allocate 4 kB four times and use the page mapping to string it together inside the virtual address space rather than demanding that it's also contiguous physically?