I have been thinking about making a new OS..and well, I began trying to think of a "better" way to allocate pages..
so far I only have 2 methods though...
1. Use a huge bitmap to mark pages as used or not..
this can be very optimized out by having a "super-page" bitmap that tells if a 4mb page is allocated, this is so you don't have to skim through the bitmap as much..
2. Use a stack of what unallocated. basically, just have a stack of structs that tells a range of unallocated pages..This works out well in the beginning, though after a while, the whole thing is so fragmented that you get out of memory errors without defragging..
are there any other methods? I've tried to think of about everything
what is the best way for page allocation?
Re: what is the best way for page allocation?
Perhaps the Wiki?hckr83 wrote:are there any other methods? I've tried to think of about everything
C8H10N4O2 | #446691 | Trust the nodes.
I just removed my whole physical memory manager procedures and functions because I was not really happy with how they worked. Now I am writing a new one and basically, I am not using any bitmaps or bytemaps or anything else. I am taking advantage of Bits 9, 10, 11 of each PTE.
I am using all 1024 PDEs and I set all the PTEs in my physical memory manager initializer so when I want to allocate them I won't have to deal with setting their base address.
I have two important types of physically allocated memory:
1) Fixed memory
2) Moveable memory
Each of these can each be allocated as:
a) Committed
b) Reserved
So for example, if the user requests a Fixed Reserved memory, my memory manager will allocate it right at that time but if the memory is moveable, it will just save the allocation information in a structure like this:
Then I have one function called [__PhysicalMemoryLock] that will allocate the moveable memory by setting it as FIXED memory. I know it is confusing but that's just the best way I found for physical memory allocation.
The set of functions that I have written for my physical memory manager is:
I am going to have to add fragmentation manager as a process that moves moveable memory from here to there in the physical memory so avoid fragmentation. That is going to be tough.
I am using all 1024 PDEs and I set all the PTEs in my physical memory manager initializer so when I want to allocate them I won't have to deal with setting their base address.
I have two important types of physically allocated memory:
1) Fixed memory
2) Moveable memory
Each of these can each be allocated as:
a) Committed
b) Reserved
So for example, if the user requests a Fixed Reserved memory, my memory manager will allocate it right at that time but if the memory is moveable, it will just save the allocation information in a structure like this:
Code: Select all
; typedef STRUCT AllocatedPhysicalMemoryDescriptor{
; void* Base;
; DWORD LengthInBytes;
; DWORD Flags;
; DWORD OwenerProcess;
; DWORD Reserved1;
; DWORD Reserved2;
; DWORD Reserved3;
; DWORD Reserved4;
; } *PAllocatedPhysicalMemoryDescriptor;
The set of functions that I have written for my physical memory manager is:
Code: Select all
Boolean __InitializePhysicalMemoryManager (DWORD AvailableMemoryStart, DWORD AvailableMemoryEnd); StdCall;
void* PhysicalMemoryAllocate (DWORD NumberofPages, DWORD AccessFlags);
void* __PhysicalMemoryLock (DWORD MemoryHandle); StdCall;
void* __PhysicalMemoryCommit (void* BaseAddress); StdCall;
Boolean __PhysicalMemoryDeallocate (void* BaseAddress); StdCall;
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.