Page 1 of 1

What physical memory model should I use?

Posted: Sun Jan 01, 2012 8:34 am
by LegendDairy
Hi,
I was redesigning my (physical)memory manager. My previous model was a bitmap but after I tried to track a bug and stepped into my code in GDB, I realized it is an insane amount of instructions. So I went back to the drawing board... I though of a stack model but then I couldn't pop a specific address, and it might return false information if a bug frees twice the same page. So I came up with a hybrid model: I would pop an address then pass it through the bitmap check if it is actually free. If I free a page I push the address and clear the bit. This makes it fast, reliable and only 3,12 % bigger than just a stack implantation and it should be allot faster then the bitmap.

So my question is: What do you think do you like it? Do you want to add something? Or should I use a different idea?

Also I've got a second question about my virtual manager. I've got a problem, every time when I allocate a virtual page, I allocate a physical one and then I map it in a table. The problem occurs when that table is full, then I need a new space that is mapped so that I can access it but I can't allocate one... How can I get around this? I solved this by mapping 4MB in the beginning of the initialization , then I can map my pages in that 4 MB region. But I don't like that solution... Has anyone got another idea?

Re: What physical memory model should I use?

Posted: Sun Jan 01, 2012 8:51 am
by rdos
Legendmythe wrote:Hi,
I was redesigning my (physical)memory manager. My previous model was a bitmap but after I tried to track a bug and stepped into my code in GDB, I realized it is an insane amount of instructions. So I went back to the drawing board... I though of a stack model but then I couldn't pop a specific address, and it might return false information if a bug frees twice the same page. So I came up with a hybrid model: I would pop an address then pass it through the bitmap check if it is actually free. If I free a page I push the address and clear the bit. This makes it fast, reliable and only 3,12 % bigger than just a stack implantation and it should be allot faster then the bitmap.
Sounds ok. Maybe you should also find some method to notify you that the same page is freed twice, so you could fix code that does this error? Then a production release could just assume that this never happens, and disregard the bitmap.

Re: What physical memory model should I use?

Posted: Sun Jan 01, 2012 8:59 am
by bluemoon
Legendmythe wrote:Also I've got a second question about my virtual manager. I've got a problem, every time when I allocate a virtual page, I allocate a physical one and then I map it in a table. The problem occurs when that table is full, then I need a new space that is mapped so that I can access it but I can't allocate one... How can I get around this? I solved this by mapping 4MB in the beginning of the initialization , then I can map my pages in that 4 MB region. But I don't like that solution... Has anyone got another idea?
I don't allocate blocks for page table entry, instead, i mark a bit on the page directory and let it generate page fault.
In the PF handler i check the address if > 0xFFC00000 I allocate a page for it.