The third week of CST 334 gave us an overview of how memory is virtualized.
Much like CPU virtualization, memory is also, with help from the hardware, virtualized by the OS. User mode processes never work with physical memory directly, even though they operate as if this is the case. When a user mode process executes an instruction that involves a memory address, the CPU’s memory management unit (MMU) translates that virtual address into a physical one before accessing RAM. In order for the CPU to do this, the OS must maintain a pair of registers, called the base and bound registers. Each memory segment supported by the CPU has its own base and bound registers.
The base register defines the start of a segment in physical memory, and the bound register defines the size of the segment. Thus, if a user mode process accesses offset 100 of the heap segment, the CPU would check if 100 is less than the bound register, and if it is, add 100 to the heap segment’s base register to generate the physical memory address. The CPU traps into a previously registered handler in the OS if the offset infringes the bound register.
This mechanism is what allows processes to operate using overlapping, or identical virtual address spaces. During a context switch the OS changes the base and bound registers to point to the process’s physical memory location. The process continues to use its virtual memory addresses like normal, however, behind the scenes its memory accesses are being redirected by the OS to its own space in physical memory.
No comments:
Post a Comment