Phase 1.04
Cache & Virtual Memory
Optimization logic: Multi-level caches and logical address mapping.
Cache Memory (In Detail)
Cache reduces the speed gap between the fast CPU and slow RAM using the Locality of Reference.
- L1 Cache: Smallest, fastest, integrated into CPU core.
- L2 Cache: Larger, slightly slower, often per core.
- L3 Cache: Shared among all CPU cores.
- L4 Cache: Rare, found in high-end specialized processors.
Virtual Memory
A management technique where the OS uses secondary storage (HDD/SSD) to simulate more RAM.
How it Works:
- Paging: Memory is divided into fixed-size "Pages" (logical) and "Frames" (physical).
- Page Table: Maps virtual addresses used by programs to physical addresses in RAM.
- Address Translation: The MMU (Memory Management Unit) hardware handles the address conversion.
- Page Fault: Occurs when requested data isn't in RAM. The OS fetches it from the Swap Space on the disk.
Advantages & Disadvantages
- Pros: Run larger programs, multitasking, better CPU utilization.
- Cons: Slower performance (disk access is slow), Thrashing (excessive swapping).
Technical Terms Breakdown
Locality of Reference
Temporal (recently used data) and Spatial (nearby data) access patterns.
Swap Space/Page File
The reserved area on the disk used to extend physical RAM.
MMU
The hardware component responsible for mapping virtual to physical addresses.
Thrashing
A state where the system spends more time swapping pages than executing instructions.