What's Virtual Memory? - Computerphile

ComputerphileComputerphile
Education3 min read23 min video
Jun 10, 2022|192,097 views|5,742|332
Save to Pod

Key Moments

TL;DR

Virtual memory uses disk space to expand RAM, translating addresses, and swapping pages. iPads now use it for app data, not just code.

Key Insights

1

Virtual memory is an abstraction combining physical RAM with disk storage to give the appearance of more available memory.

2

It involves address translation, where the CPU's virtual addresses are mapped to physical memory addresses by a Memory Management Unit (MMU).

3

Memory is divided into pages, and the operating system manages which pages are in physical RAM and which are stored on disk (swapped out).

4

Swapping occurs when physical memory is full; less-used pages are moved to storage (like SSDs), freeing up RAM for new data or code.

5

The iPad's new virtual memory support (swapping) extends beyond loading app code (which it already did) to swapping out actual app data.

6

This feature leverages the fast, low-latency storage of modern devices like iPads, making it efficient for demanding tasks and multitasking.

THE CORE CONCEPT OF VIRTUAL MEMORY

Virtual memory is a memory management technique that allows a computer to compensate for physical memory shortages by temporarily transferring data from random-access memory (RAM) to disk storage. This process gives programs the illusion that they have access to a larger, contiguous memory space than is actually available physically. It's essential for running multiple applications simultaneously and handling large datasets that exceed the capacity of RAM.

ADDRESS TRANSLATION AND THE MMU

At its heart, virtual memory relies on address translation. The CPU issues virtual addresses that programs use, but these don't directly correspond to physical memory locations. A specialized hardware component, often the Memory Management Unit (MMU) integrated into the CPU, intercepts these virtual addresses. It consults translation tables, managed by the operating system, to convert them into the correct physical addresses where the data is actually stored in RAM.

PAGING AND THE ROLE OF THE OPERATING SYSTEM

Virtual memory systems typically divide memory into fixed-size blocks called pages. When the MMU cannot find a requested virtual address mapped to physical RAM, it generates a page fault. This signals the operating system, which then takes over. The OS determines if the required page is somewhere else in memory or has been swapped out to disk. This management of memory pages, deciding what resides in RAM and what is stored on disk, is a fundamental OS responsibility.

SWAPPING: MANAGING MEMORY EXHAUSTION

When physical RAM is full and a new page needs to be loaded, the OS must free up space by 'swapping out' an existing page to secondary storage, such as an SSD or hard disk. Algorithms like 'least recently used' (LRU) determine which page to evict. The evicted page's data is copied to a 'swap space' or 'page file' on the disk, and its translation entry is updated or marked as invalid. If the swapped-out page is accessed again, a page fault occurs, and the OS must 'swap in' the data, potentially evicting another page.

IPAD'S EVOLUTION TO VIRTUAL MEMORY WITH SWAPPING

While iPads have long used a form of virtual memory for loading application code and data on demand (meaning parts of an app are only loaded from storage when accessed), the recent addition in iPadOS 16 allows for the swapping of actual app data. Previously, the OS could page in executable code or static data, but now it can dynamically move active application data to and from external storage when RAM runs low.

BENEFITS AND IMPLEMENTATION ON MODERN DEVICES

This expanded virtual memory capability is particularly beneficial for modern iPads, which often feature large amounts of fast, low-latency flash storage (SSDs). For demanding tasks like video editing or running multiple complex applications, the ability to efficiently swap out active data prevents the system from slowing down significantly. It effectively extends the perceived memory capacity, leveraging the speed of modern storage to provide a smoother user experience.

Page Sizes: Traditional vs. Modern

Data extracted from this episode

SystemPage Size
Traditional Computers (e.g., PDP-11)4 Kilobytes
Modern iPads and M1 chips16 Kilobytes

Storage Access Latency Comparison

Data extracted from this episode

Storage TypeAverage Access Time
Hard Diskapprox. 9 milliseconds
Solid State Drive (SSD)approaching zero

Common Questions

Virtual memory is a memory management technique where the operating system uses disk space as an extension of RAM. This gives the illusion of having more memory than physically available, allowing processes to run even if they exceed physical RAM capacity.

Topics

Mentioned in this video

More from Computerphile

View all 82 summaries

Found this useful? Build your knowledge library

Get AI-powered summaries of any YouTube video, podcast, or article in seconds. Save them to your personal pods and access them anytime.

Try Summify free