Virtual Memory: 4 How Does Virtual Memory Work?
How Does Virtual Memory Work?
Introduction to Virtual and Physical Memory
- Virtual memory is the memory space that a program perceives, while physical memory refers to the actual RAM installed in the computer.
- When purchasing a computer with RAM, you are essentially paying for the virtual memory space that programs will utilize.
Address Spaces
- Each program operates within its own virtual address space (VA), which is distinct from the physical address space (PA) used by hardware to access RAM. MIPS architecture utilizes a 32-bit address space for virtual addresses.
- The size of the physical address space depends on how much RAM is installed; more RAM results in a larger PA.
Address Translation Process
- When a program issues a load instruction using a virtual address, the system translates this VA into a corresponding PA through an internal mapping process. For example, loading data from virtual address 1024 involves looking up its mapped physical address.
- If requested data resides in memory, it is retrieved directly; if not, it must be loaded from disk into memory first before accessing it again via updated mappings. This ensures efficient use of available resources.
Handling Data Not in Memory
- If an instruction requests data at a virtual address that isn't currently stored in RAM (e.g., virtual address 786), the system identifies that it's located on disk and initiates loading it into memory. The translation map is then updated accordingly to reflect this change.
- Once loaded into memory, subsequent accesses to this data can occur without needing to reference disk storage again until further updates are necessary due to changes in available physical memory or other factors.
Importance of Mapping Information
- To determine which physical location corresponds to any given virtual address during execution, accurate mapping information is crucial; without it, there would be uncertainty regarding where data resides in RAM when instructions are issued by programs.