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.

So I've been reading up on virtual memory and it all seems pretty straight-forward and practical. However, I'm choking on one major concept.

If virtual memory is stored in main memory, then why even use it in the first place? Why not just use main memory?

I'm sure I'm missing something here, just don't understand what yet.

share|improve this question
1  
> If virtual memory is stored in main memory … I think that's the part where you would have to re-read again. –  slhck Sep 21 '11 at 14:34
    
Think of it as Virtual memory address spaces and physical memory address spaces. Each process thinks it has 4GB of "virtual address because the processor isolates the processes from each other. –  surfasb Sep 21 '11 at 21:56

3 Answers 3

up vote 6 down vote accepted

Virtual memory can be stored in RAM, but it can be swapped out to disk when another process needs the physical RAM. This is one of the significant features. Once it is on disk, other processes can use the system RAM to speed their processing. When needed, the memory swapped to disk can be reloaded and something else moved their in its place.

Many of today's computers have more RAM than they need so swapping is minimized (it can hurt performance), but it is good to have the swap option when needed.

share|improve this answer
    
Thanks uSlackr! –  pnongrata Sep 21 '11 at 14:49

Virtual memory allows you to concurrently run 10 x 1 GB applications in a 2 GB computer.

Demand Paging

Instead of loading the program into memory and giving it some memory for data, VM allocates space on disk (the paging file, or equivalent) for the memory needed by the program but uses "demand paging" to only load into real memory the smaller part of the program and data needed at any point. Less used parts (e.g. some rarely used subroutines) might never be loaded into real memory. When real memory is needed for another program, unused parts of real memory are used, if none, oldest clean pages may be dropped, if no clean pages remain, some "dirty pages" of memory are written out to the paging file (if the page is the same as the original loaded from the program binary file, we don't need to save an extra copy). VM keeps track of all this.

Swapping

In the past, a separate and more desperate method of memory management called swapping was also sometimes needed. Nowadays the terms are used almost synonymously.

share|improve this answer
    
For some definitions of "run", anyway. –  grawity Sep 21 '11 at 16:18
    
@RedGrittyBrick What you meant by clean and dirty pages? –  Geek Apr 23 '14 at 6:35
    
@Geek: Clean pages are pages that have not been altered since being allocated or loaded from disk. So there is no need to save their contents to disk before using them for another process. Dirty pages are pages that have been written to by a process, so their contents must be saved before reusing that memory for another process, so that the page can be restored when the original process gets resumed. –  RedGrittyBrick Apr 23 '14 at 8:15
    
@RedGrittyBrick Thanks for the clarification. –  Geek Apr 23 '14 at 10:59

Benefits are:

  1. While compiling code/task the compiler/linker has to decide/assign address of code/text(instructions), data (global variables), stack.

The system with MMU (Memory Management Unit)(i.e., supports virtual memory),

The compiler/linker is free to take any address as it needed. While the code is executing MMU will translates Virtual address to physical address.

The system without MMU: the compiler and linker has to assign address dependent on the system memory. Because it should not use the memory region of other task.

Advantage: the compiler/linker need NOT to bother about the memory map of the system.

  1. Programming of task will be easier, because the memory space actually allocated to the task is very high when compared to the system memory availability, (This acheived by keeping the needed datas/code in the main memory and keeping the rest in secondary storage).
  2. System service function need not to be duplicated. All system service's virtual address of all the tasks could be mapped to same physical address which contains the system service.
  3. In simple terms, the memory allocation need not to be considered while coding a task which would be handled while executing the task by MMU.

Coming to your Question: If virtual memory is stored in main memory, then why even use it in the first place?Why not just use main memory?

Vitural memeory/address is representation of physical address/memory . This representation helps in acheiving easier multitasking implementation, memory management, developing task without system memory details..

share|improve this answer

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.