Page 1 of 1

Implementation of a VMM

Posted: Fri Aug 05, 2005 7:53 am
by Warrior
Finally a topic on VMM with all these Phys MM ones floating around :).

Anyways, the way I picture a virtual memory manager is built on top a lower level layer to provide information about paging (like thier presence, which page belongs to what table, etc..) and all the virtual mem manager should be is a way to allocate pages, page tables, page dirs, and free them. Then a way to map virtual addresses to physical ones.

When I allocate a page I just create it from my stack of free pages right? If so I wouldn't know when to map a virtual address to a physical one when it is allocated, maybe allow a user to specify a location (virtual) where the page is allocated to?

I'm really in the dark about these design methods.
Got to go but thanks in advance to anyone that can help

Re:Implementation of a VMM

Posted: Sun Jan 15, 2006 11:16 am
by Kevin McGuire
A basic design is to have a MM(Memory Manager). It creates a stack of free pages when initialized.

Code: Select all

mmInitialize(unsigned int offset, unsigned int count);
mmAllocPage(void)
mmFreePage(unsigned int page)
Then write you're VMM(Virtual Memory Manager).

Code: Select all

vmmCreate(unsigned int page);
vmmCreate(mmAllocPage());
vmmAllocPage(unsigned int vpage);
Give it lots of useful functions such as:
1. Allocating a page. It chooses the virtual and physical page.
2. Allocating a page. It chooses the physical page.
3. Allocating a page range.
4. Mapping(Not allocating). A physical to a virtual page.
5. ... and so on.. Those functions become very useful later on.

Also, code the VMM functions to allow you to specify the page directory. This allows you to use the functions to manage multiple virtual maps. Mabye one for each process in you're os.

Code: Select all

vmmAllocPage(unsigned int dir, unsigned int vpage)

Re:Implementation of a VMM

Posted: Sun Jan 15, 2006 4:25 pm
by kataklinger
@kmcguire: And on top of that code you can implement page swaping, memory sharing, COW, deamon memory allocation and loading.. easier. It looks something like this:

Layer #1: Physical MM (allocate and free physical pages and maybe clear it before freeing it)

Layer #2: Virtual Address Space Manager (maping and demaping pages with a lot of possibilites)

Layer #3: Virtual Memory Manager (swaping, COW, sharing...)

Re:Implementation of a VMM

Posted: Sun Jan 15, 2006 5:53 pm
by Warrior
Thanks! I implemented a makeshift one into my OS before this but your suggestions are helpful. :)