http://blogs.msdn.com/b/ericlippert/archive/2009/06/08/out-of-memory-does-not-refer-to-physical-memory.aspx
How virtual memory actually works.
Why does that article seem to suggest that everything that gets put into memory also gets put into storage? That's not actually the case, is it?
How Memory Actually Works (From A Hardware Perspective)Generally speaking, there are 4 main categories of memory. First, there is the register memory inside of the CPU. Modern CPU's have several high-speed registers for temporarily storing data. They're expensive, so there's not a whole lot of them. For example, the i386 has 16 32-bit registers.
The next category of memory is cache memory. Cache memory exists to speed up memory access by prefetching data from main memory, so that, when the data is needed, it can be read from the much-faster cache instead. Cache memory is less expensive than register memory, but is still pretty expensive compared to main memory. Modern computers usually don't have more than a few megabytes of cache memory. In addition, modern computers also take advantage of multilevel caches - caches that are made up of different levels with different speeds. The L1 cache is faster (and therefore more expensive) than the L2 cache. Some computers even have a third level, the L3, which is slower and cheaper than L2. Multilevel caches allow for more data to be stored in the cache without significant additional cost, lessening the need to read from main memory.
The third category is main memory. This is what most people think of as computer memory. Nowadays, it comes on rectangular circuit boards that you (or somebody else) sticks into the memory ports on your computer's motherboard. It's pretty cheap, compared to other types of memory, but it's also relatively sluggish. Not only is access time much higher than register and cache memory, accessing main memory also requires using the system bus, which connects all external components (main memory, hard drive, external storage devices, keyboard, mouse, monitor, webcam, speakers, microphone, etc.) to the CPU. Because of that, often the CPU will have to wait until the system bus becomes free in order to access main memory, which equates to more delay between the request being made and the data being transferred. As you can see, reading from main memory isn't ideal. That's why registers and caches are used; to circumvent the long access times for main memory.
Now, with those three categories of memory, it may seem like you're set. But, consider the fact that those three categories only add up to a few gigabytes of memory. A poorly-written Java program could quickly eat all of that up. So what if we need more memory? There's a physical limit on how much main memory a motherboard can hold. Well, we go to another storage device: the hard drive. Unused space on a hard drive can be used for virtual memory. Hard drives are cheap, massive storage devices; modern drives are capable of reaching the terabyte ranges for under $100. The downside? Hard drives give a whole new meaning to the word slow. Not only do you have to deal with the system bus; you also have to factor in the fact that the drive is spinning, and you have to wait until the right locations pass under the drive heads to pull the data. However, when quantity is the main issue, virtual memory is the solution.
So to answer dreadmullet's question: sort of. You're implying that there is a substantial difference between system memory and data on a drive. There really isn't. The only difference is how that data is being used, and the hardware doesn't know the difference, and doesn't care, either. To answer what I think you meant, no, not everything that gets stored in physical memory also gets stored in virtual memory, unless you're on a computer that treats virtual memory as main memory, and main memory as more of a separate cache for the virtual memory.
If you're interested in more details, research mapping schemes (cache <-> main memory, main memory <-> virtual memory), page tables, the translation lookaside buffer, instruction pipelining, and page files.