Virtual memory is a perfect interaction between hardware exceptions, hardware address translation, main memory, disk files, and kernel software, providing a large, consistent, and private address space for each process.
The virtual memory provides three important capabilities:
1) It regards main memory as a cache of address space stored on disk, storing only active areas in main memory and transmitting data back and forth between disk and main memory as needed, in this way it uses main memory efficiently.
2) It simplifies memory management by providing a consistent address space for each process.
3) It protects the address space of each process from being destroyed by other processes.
Why do programmers need to understand virtual storage?
The virtual memory is central. The virtual memory is powerful. Virtual storage is dangerous.
Physical and virtual addressing
The main memory of a computer system is organized into an array of cells consisting of m contiguous byte sizes. Each byte has a unique physical address (physical ADDRESS,PA). The most natural way for a CPU to access memory is to use a physical address. We refer to this approach as physical addressing (physical addressing).
The early PC uses physical addressing. Modern processors use a form of addressing called virtual addressing.
When using virtual addressing, the CPU accesses main memory by generating a virtual address, which is then converted to the appropriate physical address before being sent to the memory. The task of translating a virtual address into a physical address is called address translation. Like exception handling, address translation requires close collaboration between the CPU hardware and the operating system. The special hardware called the Memory management unit on the CPU chip uses the query table stored in main memory to dynamically translate the virtual address, and the contents of the table are managed by the operating system.
Address space
An address space is an ordered collection of non-negative integer addresses: {0,1,2, ...} If the integer in the address space is contiguous, then we say it is a linear address space. To simplify the discussion, we always assume that a linear address space is used. In a system with virtual memory, the CPU generates a virtual address from an address space with a n=2^n address, which is called the virtual address space: {0,1,2,...,n-1}, the size of an address space is described by the number of bits required to represent the maximum address. For example, a virtual address space that contains an n=2^n address is called an N-bit address space. Modern systems typically support 32-bit or 64-bit virtual address space.
A system also has a physical address space that corresponds to M-bytes of physical memory in the system: {0,1,2,...,M-1},M does not require a power of 2, but to simplify the discussion, we assume m=2^m.
The concept of address space is important because it clearly distinguishes between data Objects (bytes) and their properties (addresses). Once this distinction is realized, we can promote it, allowing each data object to have multiple independent addresses, each of which is selected from a different address space. This is the basic idea of virtual memory. Each byte in main memory has a virtual address selected from the virtual address space and a physical address selected from the Physical address space.
Virtual memory as a tool for caching
Conceptually, the virtual memory is organized into an array of cells that are taken down by n contiguous bytes stored on disk. Each byte has a unique virtual address, and this unique virtual address is used as an index to the array. The contents of the array on disk are cached in main memory. As with other caches in the memory hierarchy, the data on the disk is partitioned into blocks that act as transmission units between the disk and main memory. The VM system handles this problem by splitting the virtual memory into a fixed-size block called a virtual page. The size of each virtual page is p=2^p bytes. Similarly, physical memory is split into physical pages, and the size is also p-bytes (physical pages are also called page frames).
The organizational structure of the DRAM cache
To facilitate a clear understanding of the different cache concepts in the storage hierarchy, we will use the term SRAM cache to represent the L1, L2, and L3 caches between the CPU and main memory, and to represent the cache of the virtual memory system with the term DRAM cache, which caches the virtual pages in main memory.
In-depth understanding of computer systems (virtual memory)