Slashdot Mirror


Ask Slashdot: How do Software MMU's Work?

Rob_D_Clark asks: "How does a program (like VMware) implement memory management on top of Linux (or Unix in general)? For example: in VMware, the guest OS is going to expect to have a 32-bit address space, into which the memory you allocate to the guest OS is mapped. Also, the guest OS is going to expect hardware registers for different devices, etc., to be mapped in at certain addresses. How does a program trap reads/writes to these addresses and deal with them appropriately?"

2 of 92 comments (clear)

  1. Virtual Memory by MasterD · · Score: 5

    It all has to do with virtual memory. (not the misnomer use as swap) Basically, there is a mapping between _real_ memory addresses and the addresses programs use to access data.

    In a kernel, this is done (usually) using a mix of hardware and software. If a program tries to access a piece of memory, the hardware looks at the Transition Lookaside Buffer (TLB) to translate the address. If the address exists in the buffer, it does the transition and all is good. If it does not exist, a trap is called to the kernel. It is the kernel's responsibility to look at the virtual memory tables, allocate the memory, copy it if it was copy on write, and most importantly update the TLB so next time it does not have to set up the translation.

    So in VM case, this is sorta conjecture. The VM can allocate a slew of memory on the host OS. (As far as the client OS is concerned, this is physical RAM. Then it can make a TLB and all memory accesses will go through it first. This way it can stop Windows from pissing all over OS/2 running on the VM. But Linux will stop the VM from pissing on anything else on the host OS.

    As far as kernel traps, the user level program's data needs to be copied over to kernel space for the kernel to access it.

    I hope this begins to answer your question.

  2. technical references by rgrimm · · Score: 5
    The basic technology behin VMware (I suppose -- all three authors are cofounders of VMware) is described in research papers at http://www-flash.stanford.edu:80/Disco/ , if you want to find out the details.

    Robert