How to implement a Physical Memory Manager?
Posted: Tue Mar 09, 2021 7:32 am
There are couple ways I know of - bitmap, linked list, array.
Using a bitmap is the simplest approach. 1 bit in the bitmap is one memory block of physical memory. The address of the block depends on index of the bit set.
The allocation is fast as it's just search for 1 or n number of bits indicating a free block.
The problem I can see is that it can get quite big. I know that today's memory is cheap but 128 KiB is a bit big (4 GiB memory, 1 bit - 4096 B block).
In a linked list, a single entry can span multiple blocks. So instead of spending 160B to cover 20 blocks, I can just add one entry that is 8B and covers that 20 blocks.
One entry points to another. The allocation is slower since we need to jump around the memory.
Array is like the merge of the two previous approaches.
Fast access, single entry can cover multiple entries. The problem is in keeping it sorted and possibly making it resizable.
I've considered a tree, but it's rather too complex for just keeping track of allocated physical memory.
What's is a good approach on this?
Using a bitmap is the simplest approach. 1 bit in the bitmap is one memory block of physical memory. The address of the block depends on index of the bit set.
The allocation is fast as it's just search for 1 or n number of bits indicating a free block.
The problem I can see is that it can get quite big. I know that today's memory is cheap but 128 KiB is a bit big (4 GiB memory, 1 bit - 4096 B block).
In a linked list, a single entry can span multiple blocks. So instead of spending 160B to cover 20 blocks, I can just add one entry that is 8B and covers that 20 blocks.
One entry points to another. The allocation is slower since we need to jump around the memory.
Array is like the merge of the two previous approaches.
Fast access, single entry can cover multiple entries. The problem is in keeping it sorted and possibly making it resizable.
I've considered a tree, but it's rather too complex for just keeping track of allocated physical memory.
What's is a good approach on this?