💻

[Lecture 32] Understanding Virtual Memory Concepts

Apr 11, 2025

Virtual Memory Lecture Notes

Introduction to Virtual Memory

  • Virtual memory is a fundamental concept in computer science.
  • Provides an abstraction of memory to programmers, allowing them to assume a large, infinite memory.
  • Solves multiple problems: managing memory capacity issues and providing access protection and isolation.
  • It hides physical memory constraints from programmers, making programming easier.

Programmer's View on Memory

  • Programmers see memory as a large space they can use without worrying about physical limitations.
  • Physical memory is much smaller, and virtual memory management hides this disparity.

Virtual Memory System

  • Consists of virtual addresses mapped to physical addresses.
  • The system maps using software and hardware, providing a seamless experience for programmers.
  • Allows programs to use large addresses even when physical memory is small.

Benefits of Virtual Memory

  • Automatic Memory Management: Programmers don't need to deal with physical addresses directly.
  • Isolation: Processes have independent virtual address spaces.
  • Flexibility: Data can be located anywhere in physical memory.
  • Security: Protects memory access between different processes.

Challenges in Virtual Memory

  • Page Table Size: Page tables can be large, especially with 64-bit addressing.
  • Performance: Address translation can introduce delays due to additional memory access requirements.

Address Translation

  • Virtual addresses are translated to physical addresses using a page table.
  • A page table entry includes a valid bit, a physical page number, and other metadata.
  • Multi-level page tables are used to manage size and efficiency.

Translation Lookaside Buffer (TLB)

  • A cache that stores recent translations to speed up the process.
  • Reduces the need for repeated memory accesses for translation.

Page Faults

  • Occur when a page is not found in physical memory, requiring it to be fetched from disk.
  • Page faults trigger an exception and are handled by the operating system.

Page Replacement Algorithms

  • Used when physical memory is full.
  • Clock algorithm is a common method for approximating least recently used (LRU) page replacement.

Memory Protection

  • Ensures isolation and security between different processes.
  • Access control bits in page tables prevent unauthorized memory access.

Security Concerns: Row Hammer

  • A vulnerability that can be exploited to flip bits in memory, potentially bypassing memory protection.
  • Demonstrates the importance of hardware reliability for security.

Modern Virtual Memory Systems

  • Examples from processors such as Intel's Skylake show complex virtual memory management mechanisms.
  • Use of multiple levels of TLBs, page table walkers, and page walk caches.

Conclusion

  • Virtual memory provides significant benefits in abstraction and protection but comes with complexity and performance challenges.
  • Future systems need to address these challenges to scale effectively.