Abstract
- An abstraction that maps Virtual Address to Physical Address. In layman’s terms, virtual memory takes program addresses and maps them to RAM addresses. The mapping is known as Page Table which is handled by MMU
Important
The mapping gives us flexibility in how we use the physical Main Memory.
Handles memory fragmentation
Problem: programs may not be able to fit into the main memory. A program needs a block of main memory, but we will have Memory Fragmentation issues as we run and exit programs.
Virtual memory solution: With virtual addressing, the Kernel decouples data placement from the main memory. It is able to break down Address Space into smaller sizes and fit them inside fragmented main memory, thus solving the memory fragmentation issue.
Creates the illusion of more memory
Problem: Usually, for 32-bit Instruction Set Architecture (ISA), each Process (进程) is promised a 32-bit Address Space, which is 4GB. It’s impossible to allocate 4GB of main memory to every process or we just don’t have 4GB of main memory. So, if a process tries to read from certain addresses, a crash may occur. The same idea applies to 64-bit ISA.
Virtual memory solution: With virtual addressing, the kernel controls memory mapping. It can assign virtual address to point to the Flash Memory, using it to store process data outside of main memory in the form of Swap Space. However, accessing this data will result in a Page Fault which is a big performance hit.
Prevent programs writing over each other
Problem: Since all processes are using the same number of bits to find data in the main memory, they can freely read and write to the data and Instruction of other processes.
Virtual memory solution: Virtual memory promises each process its own blank Main Memory. The virtual memory handles the underlying mapping to the corresponding Physical Address. However, this means that data sharing among programs can be slightly tricky, the underlying mapping for each programs need to point to the same Physical Address.
Manipulating memory with C
Virtual Address
- Also known as Logical Address
- The addressing system for Virtual Memory, not bounded to physical Main Memory
Important
The address that the Process (进程) sees and uses to retrieve data or Instruction.