Valix Memory Management
Posted: Sun Aug 02, 2009 7:44 pm
This is how I plan on implementing memory management in my kernel (less=more) for my OS Valix:
Two binary trees make up the kernel heap. One binary tree keeps track of all free memory blocks, sorted by size, so that the smallest one that is just large enough can be selected easily. The other binary tree keeps track of memory that is in use but may be freed later. This second tree is sorted by address instead of size so that the blocks can be easily freed. When a block of memory is allocated, it moves from the first tree to the second. When a block is deallocated, it does just the opposite.
Memory blocks are found by getting the information GRUB provides for us during boot. When a block is allocated, if the block is bigger than needed, it is split up. When there is no block large enough to use, contiguous blocks are joined.
This is done entirely without paging or any sort of virtual memory, it is a physical memory manager. Valix doesn't run userland binaries, so virtual memory is unnecessary: the kernel is the only binary running.
What do you guys think? I've already implemented 90% of this, and it *seems* to work just fine... Is there a way to increase the efficiency? I do plan on using some sort of self-balancing setup later (red-black trees, perhaps?) More importantly, are there any drawbacks?
Two binary trees make up the kernel heap. One binary tree keeps track of all free memory blocks, sorted by size, so that the smallest one that is just large enough can be selected easily. The other binary tree keeps track of memory that is in use but may be freed later. This second tree is sorted by address instead of size so that the blocks can be easily freed. When a block of memory is allocated, it moves from the first tree to the second. When a block is deallocated, it does just the opposite.
Memory blocks are found by getting the information GRUB provides for us during boot. When a block is allocated, if the block is bigger than needed, it is split up. When there is no block large enough to use, contiguous blocks are joined.
This is done entirely without paging or any sort of virtual memory, it is a physical memory manager. Valix doesn't run userland binaries, so virtual memory is unnecessary: the kernel is the only binary running.
What do you guys think? I've already implemented 90% of this, and it *seems* to work just fine... Is there a way to increase the efficiency? I do plan on using some sort of self-balancing setup later (red-black trees, perhaps?) More importantly, are there any drawbacks?