Virtual memory is a technique that gives every process its own large, private address space, even when the computer has limited RAM. The operating system keeps the most active parts of each program in physical memory and stores the rest on disk. To the program, memory simply looks big and continuous.
This guide explains how virtual memory works, its benefits and drawbacks, how it differs from physical memory and how to manage it on Windows and Linux.

How virtual memory works
- Each process uses virtual addresses, starting from zero in its own address space.
- The OS divides that space into pages, usually 4 KB each.
- A page table maps each virtual page to a frame in RAM, or marks it as not present.
- The CPU’s memory management unit (MMU) translates addresses on every access, helped by a cache called the TLB.
- If a process touches a page that is not in RAM, a page fault occurs. The OS then loads the page from disk, possibly evicting another one.
This approach is called demand paging, because pages load only when needed. For a deeper look, read our guide to paging.
Where pages live on disk
Pages that are not in RAM sit in one of two places:
- Swap space or the page file: for data the program created, such as heap memory. Linux uses a swap partition or swap file. Windows uses
pagefile.sys. - The original file: for program code and memory-mapped files, which the OS can simply reread.
Benefits of virtual memory
- Bigger programs: a program can use more memory than the physical RAM.
- More processes: many programs can run together, because each keeps only its active pages in RAM.
- Isolation: each process has its own address space, so it cannot see others’ memory. This is a key security feature.
- Sharing: processes can share libraries and memory regions when it is safe.
- Simpler programming: developers do not need to know where data physically sits.
Drawbacks
- Slower when RAM runs out: disk, even an SSD, is far slower than RAM. When the system constantly swaps pages in and out, it thrashes and becomes sluggish.
- Overhead: page tables use memory, and address translation needs hardware support.
- SSD wear: heavy swapping adds writes to SSDs, although modern drives handle this well.
Virtual memory vs physical memory
| Aspect | Virtual memory | Physical memory (RAM) |
|---|---|---|
| What it is | An address space the OS gives each process | Real memory chips |
| Size | Can exceed installed RAM | Fixed by hardware |
| Speed | Depends on whether pages are in RAM | Fast |
| Managed by | OS and MMU | Hardware and OS |
How to manage virtual memory
On Windows
Windows manages the page file automatically, and that is usually best. To change it:
- Open Settings > System > About, then select Advanced system settings.
- Under Performance, select Settings, then the Advanced tab.
- Under Virtual memory, select Change and set a custom size, or keep “Automatically manage”.
On Linux
Check memory and swap use with:
free -h
swapon --show
cat /proc/sys/vm/swappinessThe vm.swappiness setting, from 0 to 200 on recent kernels, controls how eagerly Linux swaps. Many servers lower it, for example to 10, to keep more data in RAM. Some systems also use zram, which compresses pages in memory instead of writing them to disk. To add swap, see how to create a swap partition on Linux.
Signs you need more RAM
- Constant disk activity when switching between apps.
- High swap use in
free -hor Task Manager. - Many page faults that need disk reads.
In those cases, adding RAM helps far more than enlarging swap.
Related guides
Sources
Running Linux servers in production? Our Linux server hardening & security audit checks configuration, patching, SSH and logging. You can also use our free Linux server hardening checklist, or contact us.
