Virtual Memory in Minix 3.1.4

(compilation of posts in the minix3 Google groups)

A completely new module, VM, has been added in the 3.1.4 version of Minix3, which implements virtual memory with Paging.

However, it is only a basic virtual memory manager: it allows virtual allocation for stack and shared memory (IPC), which is required when using X11 (window system) or other memory hungry programs like GCC or BSD make;

On the other hand, there is no demand-load of pages, no file-mapping, hence no dynamic loading or shared libraries, and no swap.

How fork() and exec() work in PM and VM:

They do different jobs in different servers. in pm, fork() has to setup a slot in the data structure and do some initialization, e.g. setup pid, gid. etc. While in vm, the job is more specific, it inherits the memory from the parent process in a word, technically speaking, copying the page tables. (map proc copy).

Page table and paging

pagetable.h file (which is included in the exec.c of vm) is in servers/vm/i386, since it's platform-specific.

Paging is implemented in the VM server. Virtual memory for processes is mapped into physical memory on a per-page basis with help of the MMU's page tables.

malloc and brk

malloc() is a library call that is executed inside a process itself, doing some local bookkeeping to mark certain memory regions as "in use". Only when there is not enough unallocated memory on the process' heap, malloc() will call brk() or sbrk() to increase the process' data segment size.

But brk() is a very primitive memory allocation utility. When you invoke brk() system call, it will first send a message to PM server (server/pm/break.c:do_brk), it then send the message to VM server(vm_brk()), then later, the VM gets the call from PM server, it does the real job.(servers/vm/break.c:do_brk()->real_brk()).

More references:

A Look at MINIX (version 3.1.4)