- Published on
KembaraXtra-Computer Science -Virtual Memory
Core Concept
Core Concept
- Virtual Memory: An abstraction that provides each process with its own large, private address space, isolated from other processes.
- 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.
- 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.
- 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.
- 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.
- 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
- 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.
- 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.
0 Comments