Systems and Networking · 18 min · free with an account

Virtual Memory

Lesson preview · about 30%

Every pointer you see is virtual, and the kernel decides what it means.

Core idea

Allocation reserves addresses; the kernel supplies frames on first touch.

Start with the idea

The MMU maps pages of your address space onto physical frames, so allocating memory usually just reserves address range. Touching a page for the first time causes a page fault the kernel resolves by finding a frame — which is why a large allocation can be instant and the first write to it slow. It also explains mmap, copy-on-write after fork, and why RSS is smaller than virtual size.

A process uses virtual addresses. The operating system and hardware map regions of that address space to physical memory or backing storage as needed, with page tables mediating access. Reserving an address range is not the same as filling every page with committed physical memory. Many systems map pages lazily, so the first access can trigger a page fault that the kernel resolves. But allocation behavior varies by allocator, operating system, and mapping flags; do not promise that every large allocation is instant.

This model explains several useful observations.

Keep learning, for free

The rest of this lesson is waiting for you.

Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.

No payment details. Your account opens the complete Academy.

← All lessons in Rust Interview Prep