Alpha wrote:
Thanks for all the replies.
I have chosen the bitmap because of its simplicity. However now i think of it, it would indeed have a lot of overhead when there are a lot of gaps. However, worst case it would consume 128 kB when it has to map the full address space.
36-bit physical address space has been standard for almost 25 years now, even on stricktly 32-bit PMode systems
Quote:
When i choose for a stack or linked-list based manager. how do i choose the space it requires? Because it will grow when the memory becomes segmentated, resulting in small area's of free space.
this is not how a stack system works, a stack keeps a list of all frames (not a list of free regions)
the stack-based system will never take more than 8 bytes of memory (4bytes if you only support 32-bit physical addresses) -- those 8 bytes of memory should be a static variable in your code
for your simplest setup, after processing your memory map (to remove duplicate, overlapping, or incomplete frames and non-available types) you would do something like this: (note: pseudo code, do not attempt to actually use -- this code doesn't account for large stack requiring multiple frames)
Code:
for (auto frame: memMap)
{
if(IsInUse(frame)) continue;
if(stackPointer == nullptr)
{
stackPointer == frame;
}
*stackPointer = frame;
stackPointer++
}
this will allow you to build your initial stack -- once paging is enabled, you should map all the frames holding this stack consecutively in a reserved region of your address space, and modify your stackPointer to point to the paging-enabled address
then your allocate function looks like this:
Code:
if(stackPointer < STACK_BASE) //this indicates soft OOM
{
if(ZeroFrames())
{
return AllocateFrame;
}
else
{
goto BSOD; // hard OOM: more sophisticated systems will do other things to free memory
}
}
stackPointer--;
if (stackPointer & FRAME_SIZE-1 == FRAME_SIZE-1)
{
UnmapPage(stackPointer+1);
}
return *stackPointer;
and your de-allocate code:
Code:
if (stackPointer & FRAME_SIZE-1 == FRAME_SIZE-1)
{
MapPage (stackPointer+1, frame)
}
*stackPointer = frame
stackPointer++;