The programs we use need much more memory than we might expect. Physical RAM, however, is limited. The operating system has a clever technique for this situation:
virtual memory
.
In this post, we will work through virtual memory, how pages are loaded and replaced, and the often confusing concept of copy-on-write, explaining each step simply enough for a child to follow.
is an operating system technique that creates an address space larger than physical memory. A program can behave as though it has an enormous amount of memory, while only part of its data is actually in memory and the rest is stored on disk.
Imagine living in a small room, keeping a separate storage unit, and bringing out only the belongings you need.
Virtual memory is used by the kernel as well as user programs.
The operating system itself must request and release memory, so the kernel has its own memory allocators, such as slab and buddy allocators.
Think of the kernel as a small program inside the operating system. It needs memory too!
We have explored the core concepts of virtual memory and how operating systems use memory efficiently through demand paging, page replacement, and copy-on-write.
In the next post, we will look at mass-storage structure and disk scheduling.