Ask Leo! by Leo A. Notenboom

What is Virtual Memory?

Search First! Then browse: Categories | Full Archive | By Date | Newsletter

Home » General Computing

Summary: Virtual memory is conceptually somewhere between RAM and hard disk space; it's disk space used to maximize the amount of RAM available to programs.

What is Virtual Memory?

There's memory and then there's disk space. There's memory that's on disk, not to be confused with memory that looks like a disk. Disk that looks like memory? Isn't the disk a kind of memory? Or is it something else?

It very confusing, but we can clear a few things up. Disks and memory are fairly easy. Virtual memory is one way they overlap, and with a little explanation we can make that a little less confusing too.

First let's review the basics: Memory versus Disk Space.

When a computer geek like me (or a computer salesman not like me) talks about computer memory, or RAM (for Random Access Memory), we're talking about a bunch of silicon chips in your computer that hold things like the operating system, the programs you're actually running right now, the document currently shown in your word processor, or the email you're typing up. Computers these days typically have somewhere between 128 megabytes (128 million bytes) and 4 gigabytes (4 billion bytes). What's important is that when you turn the computer off or if it crashes - *poof* - anything stored in RAM is gone. That's why when you're editing a document it's a good idea to save to disk often.

When we talk about disks, we're talking about the hard disk drives in your machine. Quite literally, a hard disk drive is typically made of several metal disks coated with a magnetic material not unlike a video or audio tape, or the strip on the back of a credit card. The disk spins at a fairly high rate of speed, and special "heads" can read, or record, a pattern of bits (1's and 0's) on the magnetic surface. The operating system assembles those bits into bytes, and the bytes into the files you might save, receive, or create. Disks do not lose what's on them when you turn off the power. Typical disk sizes these days start in the 20 to 40 gigabyte range and go as high as 250 gigabytes. It won't be long before we see the next step, the terabyte (one trillion bytes), on a single disk.

Compared to memory disks are much slower. Too slow in fact for your computer to work from directly. So the typical sequence of events is to load your program or document into memory from disk, have it run or be worked on in memory, and then either remove it from memory if it hasn't changed, or save any updates back to the disk.

Virtual Memory is simply the operating system using some amount of disk space as if it were real memory.

Exactly how virtual memory is implemented is complex and well beyond what I'd want to present here. But in an over-simplified nutshell it works like this:

  • You run programs that need memory. The operating system takes care of tracking which program is using what portions of memory, and allocating each program the amount of memory it needs.

  • Those programs will need more memory as they do their jobs. 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 that another program's needs are less "important". Some of that program's memory will be freed, first by writing the contents to disk (the memory is "swapped out"), and then allocated to the program making the request.

  • Later when the program whose memory was swapped out needs it back, that memory can be "swapped in" by reading it back from disk. This might cause memory from another program to be swapped out to make room.

Also remember that the operating system itself is also just a program. So it too will have need for memory. It can allocate memery to itself and its memory may get swapped out to disk as other needs arise.

As I said, disks are slower than memory, so if the operating system is doing a lot of swapping between the two it's going to slow your computer down. If that's happening frequently or if your computer seems to be "thrashing" or constantly swapping in and out from disk, then it might be time to add some memory to your machine. It can be one of the most cost effective ways to increase your system's speed.

Related:

Article C1925 - April 14, 2004

Helpful? Get new articles weekly by email in my FREE newsletter!

Your Name:
Your Email:


Why Subscribe?

Recent Comments
45 Comments

Leo,

If I increase my RAM, will I then be able to increase my virtual memory? I am trying to save a large movie file to a CD, evertime I get just about to the end of the movie the message increasing virtual memory comes up, my CD will finish, however just the music portion of my movie finishes and some of the pictures at the end are lost.

Thanks,

LT

Posted by: LT at August 21, 2006 12:54 PM

how is paging related to virtual memory

Posted by: viswanathan at April 9, 2007 10:19 AM

my ques.
pls give me some detail of virtual memory?
give the ans img.

Posted by: salil at April 28, 2008 9:55 PM

can we save something on virtual memory

Posted by: dipti at June 19, 2008 7:07 AM

Hey Leo,

I have a question; I recently upgraded my computer's memory to 1.50 Ram of memory from 1Ram. So, said that, I was checking on my Virtual Memory and it was set to 1536 Initial size and to 3072 Maximum size but, down below that it said that the recommended paging size should be set to 2299 so, I did it.
Now my question is; "was it good to change it or should I change it back to what it was..??

Please advice Leo and if you can e-mail me the answer as well, I will totally appreciate it.

Thank you!

Favio.

Posted by: Favio at October 16, 2008 2:01 PM

Hey leo,
is there any effect if your computer has a low virtual memory?

Your computer will slow down, and it's possible that some software may eventually fail.
- Leo
23-Nov-2008

Posted by: jekz at November 23, 2008 5:15 AM

On the HP Pavilion a810n it came with 512mb memory. I bought a 1 gig stick with the same specs. When it comes can I install it with the smaller stick or does the 512 stick have to be removed? Also shoulf the 1 gig stick go into slot 1 and 512 mb go in slot 2?
Thanks

You need to check with HP - what you need to do and what you can do vary depending on the specific computer.
- Leo
29-Jan-2009

Posted by: Penelope at January 27, 2009 3:18 PM

why cant we store the physical addresses directly in the disk. why we create virtual addresses. it may look stupid but i just want to know things more clearly.

Posted by: joshua at February 21, 2009 8:54 AM

I have windows xp and a gig of ram, what are the best settings for my virtual memory? It's set at Initial 1533 MB Max 2304 MB right now is that what it should be set at or what do you recommend?

Posted by: Kelly at April 10, 2009 4:29 PM

Virtual memory is a very confusing subject for most computer users, and this is due in part to Microsoft's hopeless descriptions. Notably the persistent references to virtual memory as the pagefile. That may have been true for Wndows 3.1 but virtual memory is much, much more on modern systems. This belief has been the cause of enormous confusion, even among many computer professionals.

Virtual memory is a system that provides a virtual environment to applications that is independent of the computers physical resources. Each application has a 2GB private and unshared address space. There is also a 2GB space for system use that is common to all applications. This is totally independent of how much RAM is in the system.

Aplications know only the virtual address space, they have no direct access to physical memory. The system maps physical memory to this virtual address space according to both need and availability. Portions of an application will be in the original files, the pagefile, or RAM. This managed by the system and is transparent to applicatons. The system will attempt to keep as much of the recently accessed data and code in RAM as is possible. The remainder will be on disk.

The virtual memory system can function without a pagefle but efficiency will be impaired. Application code is not normally copied to the pagefile as it can be reloaded from the original files if needed. Only modified data will be paged to the pagefile. With no pagefile only program code can be paged, thus unbalancing the system and leading to performance degradation.

Larry Miller
Microsoft MCSA

Posted by: Larry Miller at May 19, 2009 8:29 AM

Post a comment on "What is Virtual Memory?":






(Email Address will not be published.)

Remember Me?

By popular demand...
my tip jar
Cuppa Joe
Buy Leo a Latte!

(you may use HTML tags for style)

RSS feed Subscribe to the RSS Feed specifically for comments on this article.

Before commenting, please...

  • Read the article at the top of this page. If your comment shows you didn't, it'll be deleted and ignored.

  • Comment only on this article. Use the Google search box at the top of the page if you have a question about something else.

  • Don't include personal information in the comment. No email addresses. No phone numbers. No physical addresses.

  • Don't spam. Excessive links to unrelated sites within a comment or across multiple comments will cause all such comments to be removed.

  • Don't ask me to recover lost passwords or hacked accounts. I can't, and those comments will be deleted.

  • I can't respond to every comment. And I can't vouch for the accuracy of others who do.

Please wait. Your comment is being processed ...


Question? Ask Leo!