Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I was double checking my notes for 'Virtual Memory' and the definition in my text book is:

Process of allocating a section of secondary storage to act as part of the main memory

Where as Wikipedia says:

Virtual memory is a computer system technique which gives an application program the impression that it has contiguous working memory (an address space)

and (Wikipedia also says)

Note that "virtual memory" is more than just "using disk space to extend physical memory size"

Can anyone offer any clarification as to which is correct?

share|improve this question
    
I believe the note from Wikipedia involves some qualifications on what is used in terms of things being contiguous. –  JB King Sep 17 '09 at 19:25
    
This question would probably get a better answer on SO. –  Captain Segfault Sep 17 '09 at 20:00
1  
Don't confuse what virtual memory is with how it's used. Wikipedia's 1st sentence is defining what it is. Your book is talking about how it's typically used. Once people talk about "pages" they're talking about a specific implementation of virtual memory. –  Tony Lee Sep 17 '09 at 23:30
    
Check this video This has the basics for the need of a VMM layer. Explains the basic architecture. youtube.com/user/learnwithtechies#p/u/10/Fx_I6-dL__0 –  user59368 Dec 16 '10 at 8:51
    
Your text book is just plain wrong. There are many machines with virtual memory and no secondary storage at all. Similarly, there once were many machines that could use secondary storage as part of main memory but didn't support virtual memory. "Virtual memory" is something that is not memory but is accessed like memory. Your textbook is defining swapping or paging. –  David Schwartz Nov 30 '11 at 0:10
show 1 more comment

6 Answers

up vote 18 down vote accepted
Note that "virtual memory" is more than just "using disk space to extend physical memory size"

Virtual memory is a layer of abstraction provided to each process. The computer has, say, 2GB of physical RAM, addressed from 0 to 2G. A process might see an address space of 4GB, which it has entirely to itself. The mapping from virtual addresses to physical addresses is handled by a memory management unit, which is managed by the operating system. Typically this is done in 4KB "pages".

This gives several features:

  1. A process can not see memory in other processes (unless the OS wants it to!)
  2. Memory at a given virtual address may not be located at the same physical address
  3. Memory at a virtual address can be "paged out" to disk, and then "paged in" when it is accessed again.

Your textbook defines virtual memory (incorrectly) as just #3.

Even without any swapping, you particularly need to be aware of virtual memory if you write a device driver for a device which does DMA (direct memory access). Your driver code runs on the CPU, which means its memory accesses are through the MMU (virtual). The device probably does not go through the MMU, so it sees raw physical addresses. So as a driver writer you need to ensure:

  1. Any raw memory addresses you pass to the hardware are physical, not virtual.
  2. Any large (multi page) blocks of memory you send are physically contiguous. An 8K array might be virtually contiguous (through the MMU) but two physically separate pages. If you tell the device to write 8K of data to the physical address corresponding to the start of that array, it will write the first 4K where you expect, but the second 4K will corrupt some memory somewhere. :-(
share|improve this answer
add comment

All are correct.

Also, most of the people above have either a limited understanding (including e-t172, who mistakenly thinks everyone is wrong but him), or an overcomplicated explanation of things that are kind of beside the point of what you really need to know. So, I'll try to start slowly, and then put this all together for you. It's like this:

Virtual memory, as commonly used, refers to "paging". As the name suggests, paging is like a human notepad.

When you're working out simple sums, or learning simple information, you do it all in your head: you just load up all the information, process it, and get the answer. This is like a computer loading files from the hard drive -- it loads up the programs or pictures or other information it needs to work into its "real memory" (or "physical memory") and works on them with it's "brain" (its processor).

However, when you're learning complex information, or working with complex sums, you might not be able to fit all that in your head at once. You get confused, start to slow down, fail to keep it all in there at once, and have to forget something to remember something else.

The human solution is to use a notepad. We note down on pages all the things we can't remember at once, but refer to them while doing the sums. We might not be able to remember a huge list of sales figures for the month, but we can look at the pages, get the information a bit at a time, and process each bit. This is like the computer "paging" its memory -- writing pages full of information, and putting it into "virtual memory" for later reference, and realising it needs a page, and loading that page back from virtual memory into real memory. On linux and unix, the place where these pages are stored is literally called a "pagefile", and the pages of data in memory are literally called "pages". Different systems have different names for these things, but the general concept is much the same.

So really, paging is very simple. All of the pages of information don't fit in memory, so some pages are put on disk, and loaded again later.

Now, where it gets more complicated is that, modern systems feature memory mapping and memory protection, which is all usually handled by the same hardware system in the computer: the memory management unit, or MMU.

In a (modern) multitasking computer, which can run many programs at once, and features memory protection, each program is usually seperated from other programs running on the same system. This way, one program cannot alter another program simply by accessing its memory -- the MMU physically separates one program's address space from that of others. In other words, user's programs don't see other user's programs or even other programs. They don't see "real memory" -- they see their own "virtual memory".

Now, this memory isolation concept and the pagefile concept are two conceptually different things, which is probably why you're confused. However, the key is that they both work using the MMU -- the memory management unit, which splits memory into pages, and maps pages to a virtual address space.

So, when a program asks for the memory at a certain "memory address", what really happens is that the memory pages for that program and their corresponding addresses (the program's "address space") are looked up, and the page that corresponds to that memory block is found. That page can either be loaded somewhere in real memory, in which case the program is given access, or, it can be paged out to a disk. If it is paged out, then it triggers a "page fault" -- the disk is accessed, and the page gets loaded into memory. So the program works even when there isn't enough memory, but it runs SLOWLY, if it's having to use disk for what would normally be a very fast memory access.

Now, if there isn't enough space to load that page into memory, then you have a problem. In that case, some OTHER page that's already in memory has to be "swapped" to disk, so the first program's page can be loaded. Or, they might equally be pages from the same program. You see this sometimes in graphics programs, for instance, on heavily loaded systems, when part of the picture is loaded slowly and drawn quickly, then the next part is loaded equally slowly and drawn quickly, and when you go back to work with the first part, it's slow AGAIN. That's because they're being loaded in to be worked on, then swapped out again, so something else can be worked on. Obviously, this is a very slow way to work, and what you really need is more REAL memory.

share|improve this answer
    
I 100% disagree with this answer. If "virtual memory" referred to paging, then a system that doesn't page (say, one with no swap or page files enabled) could not support virtual memory. But that's obviously insane. –  David Schwartz Aug 28 '11 at 22:09
add comment

I don't know where the third reference is leading to, but the first two explinations sorta work together to explain virtual memory from what I have always understood it to be.

share|improve this answer
add comment

The first two are different ways of saying the same thing.

The third is correct in saying that it's 'more than just "using disk space...", but at heart virtual memory is using disk space to extend physical memory as the data that was held in physical memory has to be copied somewhere and that somewhere is the hard drive. There is quite complicated software that manages this process to make sure that the most frequently or recently used data is kept in the physical memory as disk access is a lot slower than memory access.

share|improve this answer
add comment

Well if we understand the word virtual I think we can understand how it relates to memory.

"Virtual" as defined on Dictionary.com: "temporarily simulated or extended by computer software: a virtual disk in RAM; virtual memory on a hard disk."

In the case of Virtual Memory, the system is simulating system memory by using slower memory resources (i.e. hard drive, thumb drive etc..) When additional memory is required the system will swap out data in system memory which is not needed to the hard drive or resource you have setup. This frees up system memory so that your application can continue the task it was doing.

The swapping is a continuos process and thus if you upgrade your memory you should see a performance improvement as the system should not require swapping to slower memory as offten.

share|improve this answer
add comment

Virtual Memory is a block of your hard Drive that the system uses as a paging file in addition to the physical RAM.

It gets tricky, and sometimes slow, because Windows does NOT defrag this part of your hard drive.

Best 2 tips I can offer: 1) Virt Mem should be set both min and max at approx 1.5X your physical Memory. ex. 2GB RAM = 3070MB Virt. 2) When defragging, turn off your paging file. Defrag 2x, and reset back to the original number. This gives a clean slice of drive and will increase the speed of the paging file.

share|improve this answer
    
That's not completely true - modern memory managers virtualize ALL the system memory. This is what allows for process separation - each process can only touch its own memory. The memory manager is responsible for mapping these virtual pages to the real storage, and optionally to a fixed disk. –  Nighthawk Sep 17 '09 at 19:31
1  
"Windows does NOT defrag this part of your hard drive." simply nuke pagefile.sys, reboot, defrag the disk and re-enable paging, voilá, a fresh and contigeous pagefile! however, Sysinternals' PageDefrag does a better job as it will also place the pagefile at the beginning of the drive/partition for better performance. –  Molly7244 Sep 17 '09 at 19:34
    
If this answer were correct, then a Windows system with no page files configured couldn't provide any virtual memory support. But this is obviously wrong. Such a system could still, for example, map files into process address space in excess of physical RAM, which is an example of virtual memory. –  David Schwartz Aug 28 '11 at 22:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.