TECHNOLOGY 

Published on
KembaraXtra-Computer Science -Virtual Memory
Core Concept
  • Virtual Memory: An abstraction that provides each process with its own large, private address space, isolated from other processes.
Why Use Virtual Memory?
  • Isolation: Prevents processes from accessing or corrupting memory belonging to other processes or the kernel.
  • Abstraction: Simplifies memory management for developers, eliminating fragmentation concerns caused by other processes.
  • Large Address Space: Gives each process the illusion of a large contiguous memory block, even if the physical memory is smaller.
Virtual vs. Physical Addresses
  • Physical Address: Actual hardware memory address. Hidden from user-mode processes.
  • Virtual Address: Address seen by the process. Translated to a physical address by the OS.
Virtual Address Space
  • Each process gets its own virtual address space (e.g., 2GB).
  • Same virtual addresses in different processes map to different physical addresses.
  • Mechanisms exist for processes to intentionally share memory.
  • The entire virtual address space isn't necessarily backed by physical memory initially. Only parts are mapped to physical memory as needed.
Kernel Address Space
  • Separate from user-mode address space.
  • Shared by all code running in kernel mode.
  • Kernel code can access any part of the kernel address space.
Address Space Division (32-bit Systems)
  • 32-bit systems have a 4GB (2^32 bytes) virtual address space.
  • This 4GB is split between kernel and user mode. Common splits:
    • 2GB User / 2GB Kernel
    • 3GB User / 1GB Kernel
Paging
  • Scenario: The total virtual memory requested by processes and the kernel exceeds the available physical RAM.
  • Solution: The OS moves inactive "pages" (blocks) of memory from RAM to secondary storage (e.g., hard drive or SSD).
  • When Needed: If a process tries to access a paged-out memory location, the OS must swap it back into RAM.
  • Tradeoff: Paging allows more virtual memory than physical RAM but introduces a performance penalty due to slower secondary storage access.
64-bit Systems
  • Potential: Huge address spaces (2^64 bytes).
  • Reality: Current implementations use fewer bits (e.g., 48-bit addresses, yielding 256TB of virtual address space).
  • Still vastly larger than 32-bit address spaces.



Picture
0 Comments