It’s what your computer uses when it runs out of real memory.
There’s also memory kept on disk, not to be confused with memory made to look like a disk.1
Disks and memory are fairly easy. Virtual memory is one way that they overlap, and we can make that a little less confusing.
Become a Patron of Ask Leo! and go ad-free!
Virtual memory is hard disk space managed by the operating system to temporarily hold the contents of a portion of RAM when there’s not enough memory to do everything the computer is trying to do. Excessive virtual memory use can result in performance issues.
Memory versus disks
First, let’s review the basics.
Computer “memory” means RAM (Random Access Memory). These are a bunch of chips in your computer holding things like the running operating system, the programs running right now, the document currently showing in your word processor, or the email you’re typing up. The emphasis is on current use.
When you turn the computer off or if it crashes, anything stored in “memory” is gone. That’s why when you’re editing a document, it’s a good idea to save to disk often.
“Disks” refer to either to either the hard disk drives (HDDs) or solid state drives (SSDs) in your machine. Disks retain what they contain when power is removed. Computer memory does not.
Disk drives work much slower than memory — too slow for your computer to work from directly. So the normal sequence of events is to:
- Load your program or document into memory from disk.
- Run the program or work on the document in memory.
- Save any changes by writing them back to the disk.
Virtual memory is when the operating system uses some amount of disk space as if it were real memory.
Exactly how this is done is complex and well beyond what I can present here. But in an over-simplified nutshell, it works like this:
- You run programs, and programs use memory. The operating system tracks which program is using what portions of your computer’s memory and allocates each program the amount of memory it needs.
- Programs often need more memory as they do their jobs. For example, opening a large document may cause your word processor to request additional memory from the operating system in order to hold the document.
- If there isn’t enough memory available to satisfy a request, the operating system may decide another program’s needs are “less important” at that moment. It frees some of the memory used by that program, first by writing the current contents to disk (called “swapping out”) and then allocating the now free memory to the program making the request.
- Later, when the program whose memory was swapped out needs it back, it can be “swapped in” by reading it back from disk. This might cause memory from another program to be swapped out to make room.
The operating system itself is also just a program, so it needs memory, too. It can allocate memory to itself. Its memory may get swapped out to disk as other needs arise.
Disks are slower than memory. If the operating system is doing a lot of swapping between the two, it’s referred to as “thrashing”, and it slows your computer down.
If it happens frequently, it might be time to add some memory to your machine. That can be one of the most cost-effective ways to increase your system’s speed.
In an ideal world, your computer would never need virtual memory. In an ideal world, your system would always have enough memory — RAM — to perform whatever you ask it to do.
If not, however, adding RAM is one way to deal with it. Or you could just ask less of your computer.
Want more tips? Subscribe to Confident Computing! Less frustration and more confidence, solutions, answers, and tips in your inbox every week.
Footnotes & References
1: AKA a RAM disk, which isn’t nearly as common as it once was.