I know virtual memory is a paging file that computer uses to store a part of RAM on hard disk for a running process. But how different is Virtual address space? is it the RAM or hard disk or both?
23 Answers
The virtual address space is what an individual program sees when it executes. Depending on how the program has been configured this address space will be as large as the maximum the operating system supports.
The operating system kernel is then responsible for mapping addresses in the vas to physical memory, be that RAM, or system page files.
With this design, the programs themselves remain unaware of resources and real addresses, and can operate as if they had all system memory to themselves, or at least the maximum memory a single process can use.
In a nutshell a program works with VAS, and the operating system handles mapping VAS to real storage so that this is invisible to the running program. The running program sees only its VAS.
Virtual Address Space is a limitation on the size of memory a program can address.
This is constrained at the outer bound by the style of pointers - a pure 32bit pointer can in theory address 4GB of virtual space. The real bound is dependent on operating system design as it uses a significant part of the address space alongside the user space.
Under Win32, the default setting is to allow virtual address space of 2GB as user space.
A 64bit pointer can address far more, in practice typically 48bits are allowed and there's lots of details on this superuser answer.
In theory, someone could build a physical computer with enough RAM that that 2GB of user space could be directly mapped to physical memory (probably needing at least 3GB of physical) so you would have 32bit processes where the virtual memory wasn't very virtual.
1Virtual address space is what the process sees. For example, your email sits in an inbox that is, say, 25GB in size. That is your virtual address space.
Virtual address space is to distinguish the fact that not every virtual address space corresponds to a physical address space. Lets say you have 20 email users with 25GB of inbox space. But you only have 100GB of disk space on your server. Well, you can take old emails and archive them and only keep the recent ones on your server because people usually only check the most recent email.
Archiving email from the server to, say, a tape drive is akin to the computer paging parts of RAM to disk. When someone goes to look at old email, you just "page" the old email from the tape back onto your server. The email user will never know the difference.
In the same way, each process on your machine has X virtual address space, even though you may have less than X * number of processes of physical memory.
Virtual memory is exactly that. Virtual address space. But virtual memory is just the virtual address space that you are using.
7