Virtual Memory Allocator

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
Whatever5k

Virtual Memory Allocator

Post by Whatever5k »

I have built my own physical memory allocator that uses a two bitmaps (for superpage and pages) to allocate and return physical addresses. Paging is also enabled, but now I wonder how I can implement my virtual memory manager (used by the kernel, not by users yet), like *morecore() or sbrk() that allocate memory from the heap - you know what I mean.

Does anybody have an idea how to implement this. If my kernel allocates (virtual) memory by using malloc() for example, three steps are done:

1. Allocate memory in the physical address space using the physical page frame allocator
2. Allocate memory in the virtual address space
3. Map physical addresses to virtual addresses

I've implemented step 1, but I'm wondering how to implement step 2 and 3.
So, has anybody some information/ideas/code/suggestions or anything else about that?

best regards,
A. Blessing
Slasher

Re:Virtual Memory Allocator

Post by Slasher »

hi,
you have paging enabled, that means you have a Page Directory and Page Tables.
All that you have to do is write a memory allocator for Virtual Memory! How I see it working is like this ( I haven't done mine yet so this is off the top of my head!)

the VM allocator works with linked lists of structs decribing the different sections of memory

the app (can be kernel ) calls the VM allocator for some memory
the alloctor checks to see is there is enough space in the apps heap for the request.
if there is enough then just return the next available VM address and update the VM tables
if there isn't then call PHYSICAL_MEMORY_MAP, to get X pages of physical memory,map it into the Page Tables, and return the VM address

also you will need to get your PAGE FAULT Handler to work similarlly too
Post Reply