Reputation: 13583
I've read the following 2 articles explaining the difference between virtual memory
and physical memory
. One thing that I found confusing is that the term virtual memory
seems to mean different things in these 2 articles.
What Is the Difference Between Virtual Memory & Physical Memory? says Virtual memory is used when the RAM is filled.
While Wikipedia says virtual memory is used to tell programs where the physical memory is.
Is one of the articles wrong? Or does virtual memory
have different meaning in different context?
Upvotes: 0
Views: 41
Reputation: 21627
Both articles are rather confusing. Part of the problem is they conflate (as do many hardware manuals) the concept of logical memory translation with virtual memory. That was not much of problem in ye olde days when using one meant the other the always present but that is increasingly no longer the case.
If you have a pure physical memory system, every address is a physical address with no translation.
In a logical memory translation system, logical pages are mapped to physical pages using a page table. Each process sees a linear range of possible addresses but the mappings to physical addresses may or may not be the same.
In a pure logical memory system, the page table entries (and thus the corresponding logical page) have two possible states:
In a virtual memory system, the operating system uses secondary storage (disk) for the process memory. In the user address space range, every valid address maps to secondary storage. That secondary storage might be in different locations, including the page file, executable file, and shared libraries.
A virtual memory system relies on the existence of logical memory translation. In a virtual memory system, the page tables have three states:
If you try to access memory (ignoring protection) in the first case, your program simply accesses the mapped page.
In the second case, your program causes an exception and probably dies.
In the third case, an access to the page triggers a page fault. The operating system has to load the page from disk into memory. Then it has to remap the page table entry to the location where the page was mapped.
In the virtual memory system you then have two sets of memory that have to be managed. The virtual memory management is the data structures that define the process address space on disk. The second set is the data structures (ie page tables) that define that part of the process that resides in memory.
In the the days of 32-bit processors (4GB address spaces) where 8MB of memory took up a cabinet the size of a refrigerator, virtual memory had to be used because there simply was not enough physical memory to do very much.
These days, a desktop computer commonly has 32GB of memory. There is less of a need for storing processes on disk. However, nearly every operating system in use is still based upon the back-to-disk virtual memory.
I expect that virtual memory will go away entirely in the near future and that the Windoze and Eunchs systems of the world are already facing obsolescence. New operating systems will be created to deal with diskless computer systems.
Upvotes: 1
Reputation: 471
I think saying that virtual memory is used when the RAM is filled is wrong.
The concept of virtual memory addresses the problem of using more memory than you physically got, very simply spoken.
The MMU (memory management unit) maps virtual memory addresses into physical addresses. Check out MMU wikipedia for more information.
Virtual memory allows to use the disk space for additional memory space, but it does not have to be.
When you access more memory than is available the operating system can swap memory pages, thus allowing you to use additional memory. Here is memory swapping for some further information.
So in conclusion virtual memory can reside in either RAM or on the disk, but when data is needed, it is loaded into RAM if it isn't there already.
Edit: The concept of virtual memory addresses much more than available memory of course. Things like restricting access and other stuff.
Upvotes: 0