Page 1 of 1
what is the best way for page allocation?
Posted: Sat Jun 02, 2007 8:02 am
by earlz
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
Re: what is the best way for page allocation?
Posted: Sat Jun 02, 2007 8:38 am
by Alboin
hckr83 wrote:are there any other methods? I've tried to think of about everything
Perhaps the Wiki?
Posted: Sat Jun 02, 2007 8:59 am
by earlz
!! >_< I forgot to look at the obvious!!
Posted: Sat Jun 02, 2007 12:03 pm
by XCHG
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:
Code: Select all
; typedef STRUCT AllocatedPhysicalMemoryDescriptor{
; void* Base;
; DWORD LengthInBytes;
; DWORD Flags;
; DWORD OwenerProcess;
; DWORD Reserved1;
; DWORD Reserved2;
; DWORD Reserved3;
; DWORD Reserved4;
; } *PAllocatedPhysicalMemoryDescriptor;
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:
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;
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.
Posted: Sat Jun 02, 2007 3:11 pm
by earlz
hmm...moveable memory! that's a really good idea to have implemented at that page manager level!