what is the best way for page allocation?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

what is the best way for page allocation?

Post 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
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Re: what is the best way for page allocation?

Post by Alboin »

hckr83 wrote:are there any other methods? I've tried to think of about everything
Perhaps the Wiki?
C8H10N4O2 | #446691 | Trust the nodes.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Post by earlz »

!! >_< I forgot to look at the obvious!!
User avatar
XCHG
Member
Member
Posts: 416
Joined: Sat Nov 25, 2006 3:55 am
Location: Wisconsin
Contact:

Post 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.
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.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Post by earlz »

hmm...moveable memory! that's a really good idea to have implemented at that page manager level!
Post Reply