Virtual Memory
A computer's operating system coordinates a mapping between a 'virtual address space', which is used by a program, and a physical address space, which addresses physical memory locations.
Tables 1 and 2, show that the program's virtual addresses in the range 0x00000000 to 0x00000016 are mapped to the physical address range 0x01AB0000 to 0x01AB0016; whereas the next six continguous memory positions 0x00000020 to 0x00000040 are mapped to the physical address range 0x994D0000 to 0x994D0020. The intent of these tables is to show that the continguous virtual address space is mapped to non-contigous regions of physical memory.
Using virtual memory provides the following key benefits:
- A program cannot interfere with another program's memory because its virtual address space only maps to physical memory allocated to it.
- If a program tries to access a part of its address space that hasn't been mapped to physical memory a 'page fault' will occur.
- The contents of physical memory may be copied out to secondary storage to free up physical memory for executing processes.
- If a program tries to access an address that has been copied to secondary storage, the operating system can copy the data back into remapped physical memory before returning control to the program.
- By utilising secondary storage, programs can use an virtual address space that is much larger that physical memory.
An important aspect of virtual memory is that, whether or not it is used, it is transparent to the program running. From the program's perspective, it just has full access to all of addressable memory - whether the address a program accesses is the same as the physical address is irrelevant to the program.
Table 1. - Virtual Address Space | |
Virtual Address | |
---|---|
0x0000 0000 | |
0x0000 0004 | |
0x0000 0008 | |
0x0000 0012 | |
0x0000 0016 | |
0x0000 0020 | |
0x0000 0024 | |
0x0000 0028 | |
0x0000 0032 | |
0x0000 0036 | |
0x0000 0040 | |
... | |
0xFFFF FFF0 | |
0xFFFF FFF4 | |
0xFFFF FFF8 | |
0xFFFF FFFC |
Table 2. - Physical addresses mapped to | |
Physical Address | Value stored at address |
---|---|
0x01AB 0000 | 0000 1001 1010 0000 0000 0000 0000 0000 |
0x01AB 0004 | 0000 1010 1010 0000 0000 0000 0000 0000 |
0x01AB 0008 | 0000 1001 0010 0000 0000 0000 0001 0000 |
0x01AB 0012 | 0000 1101 0001 0000 0000 0000 0000 0000 |
0x01AB 0016 | 0011 0101 0111 1100 1110 0010 0110 0110 |
0x994D 0000 | 0000 1001 1010 0000 0000 0000 0000 0000 |
0x994D 0004 | 0000 1010 1010 0000 0000 0000 0000 0000 |
0x994D 0008 | 0000 1001 0010 0000 0000 0000 0001 0000 |
0x994D 0012 | 0000 1101 0001 0000 0000 0000 0000 0000 |
0x994D 0016 | 0011 0101 0111 1100 1110 0010 0110 0110 |
0x994D 0020 | 0011 0101 0111 1100 1110 0010 0110 0110 |
... | |
0x039C 0000 | 0000 1001 1010 0000 0000 0000 0000 0000 |
0x039C 0004 | 0000 1010 1010 0000 0000 0000 0000 0000 |
0x039C 0008 | 0000 1001 0010 0000 0000 0000 0001 0000 |
0x039C 000C | 0000 1101 0001 0000 0000 0000 0000 0000 |
References