vmm help

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
ka3r

vmm help

Post by ka3r »

Hi people!

I am working on the Virtual Memory Manager implementation on my OS. My question is.. what's the best virtual memory allocation system available on the net and not too complicated to implement on an OS? (i mean, a kmalloc and kfree function)

Thanks ;D
Whatever5k

Re:vmm help

Post by Whatever5k »

There are quite many malloc/free implementations out there, you may want to have a look at [1].
However, I think you misunderstood the VMM thing a bit. The malloc/free implementations don't bother with virtual memory or anything like that. They just keep track of which parts in memory are used and which not. If they need more memory from the Operating System, they call morecore() which gives them more memory.
So your job is to provide a morecore() function.


1. http://gee.cs.oswego.edu/pub/misc/malloc.c
Ozguxxx

Re:vmm help

Post by Ozguxxx »

Hi, I could not understand how malloc and free does not have anything to do with virtual memory. If malloc keeps track of used memory areas it should clearly keep track of virtual memory right? So it should have something to do with virtual memory. If you ask my ideas, I just supply whole memory after kernel static data, code and bss, page tables to kernel heap, since there are no user processes and no shared areas between kernel processes, I think there is no wrong thing about it. So for now kernel has about 4 Gb of heap memory(in virtual memory). Well the connection between physical memory manager and virtual memory manager is simply the page faults. I think idea is very simple and clear: Virtual memory manager supplies all memory asked for kernel from VIRTUAL ADDRESS SPACE. It does not even tell physical memory manager so it does not even need to know if this memory exists or not. When accesing to this allocated memory kernel might face with a page fault but since this is abstacted from process by page faulting mechanism(which is handled by physical memory manager) we wont have any problems. In very future swapping will also be needed when pmm is out of physical memory but this can be a future consideration. All this is explained very well by Tim Robinson's meromy management tutorial... I think you can find them at http://osdev.neopages.net/docs.php.
Whatever5k

Re:vmm help

Post by Whatever5k »

Alright, I think I mis-explained myself a bit...
Of course malloc/free have to deal with some kind of memory (addresses), that is (you're right) virtual memory. BUT (and that's what I was trying to say ;)), it doesn't bother mapping virtual to physical addresses or anything like this.
Hope that's clearer :)
RicoSanchez

Re:vmm help

Post by RicoSanchez »

I seperate my memory management into 3 parts. Physical memory management (pmm), virtual memory management (vmm) and the malloc/free part. The pmm part just manages physical memory in 4kb chunks. The vmm part manages virtual memory and also takes care about swapping and the likes, also in 4 kb chunks. and the malloc/free part takes care about the application level memory management, and the size of those chunks is defined by the arguments.

In my case, the malloc/free part can use any kind of vmm implementation as long as the vmm implementation uses a specific interface which malloc/free uses. This is also the case between the pmm and vmm. the vmm can use any kind of pmm implementation as long as the pmm implemented some specific functions. This is the same as malloc and free, which are 2 functions which do the same no matter what implementation is used, but can be implemented in any way possible.

The malloc/free part doesn't need to know about swapping memory to the disk, that's the task of the vmm. As long as the vmm contains the function morecore(), the malloc/free implementation depending on it will work no matter what implementation is used for the vmm.


So now the question is, do you want to know how to implement a vmm or do you want to know how to implement a malloc/free?
ka3r

Re:vmm help

Post by ka3r »

Well, I do not need your help no more ;D

I have already written the PMM part (i use a stack of free physical pages) and my problem was to find the best algorithm for finding the first 'n' contiguous pages in the virtual address space. I wrote several algorithms and the best (and the less complicated to implement) is to have a bitmap for the 1048576 virtual pages and a superpage bitmap for the 1024 superpages of 1024 pages.

I tried to alloc 1048576 pages (that is, setting 1048576 bits to 1) under bochs (1.5 million instructions per second, like a 386SX) and it took about 300ms.

...Sorry for my english :-\
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:vmm help

Post by Pype.Clicker »

1 bit per page, 1M of pages ... so you basically require 128K of physical RAM only to remember which page is free or not :-(
And these 128KB will be needed for every program...
why not to use the information that is in the page tables instead ?

Moreover, you can easily use the first entries of a free region to store information about this region's size, etc.

This way, you don't need that much memory (just what you're forced to use for page tables)
ka3r

Re:vmm help

Post by ka3r »

Yes, it uses 131072 bytes.. but this method is used only in the kernel. The apps will use an other allocation system (e.g. Doug Lea's malloc/free).

Searching on every page table of the kernel page directory is _SLOW_! It is very slow on a moderately fragmented virtual address space..

When I finish coding the VMM, try it and say if it is fast enough ;)

New suggestions are welcome.

(If you want to have a simple idea of what I am saying, search on osdev.neopages.net the Cottontail memory manager)
Post Reply