Implementation of a VMM

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
Warrior

Implementation of a VMM

Post 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
User avatar
Kevin McGuire
Member
Member
Posts: 843
Joined: Tue Nov 09, 2004 12:00 am
Location: United States
Contact:

Re:Implementation of a VMM

Post 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)
User avatar
kataklinger
Member
Member
Posts: 381
Joined: Fri Nov 04, 2005 12:00 am
Location: Serbia

Re:Implementation of a VMM

Post 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...)
Warrior

Re:Implementation of a VMM

Post by Warrior »

Thanks! I implemented a makeshift one into my OS before this but your suggestions are helpful. :)
Post Reply