When a process is created by the user a virtual space address is created which is is the size 4g for a 32 bit os (0 to 2^32-1)? The process thinks its has the whole memory to use but the virtual addresses are converted to physical addresses and stored in the page table of the process. I am confused that what virtual memory is then? Is it same as virtual address space?

- 195,001
- 40
- 254
- 396

- 19
- 3
-
No confusion here, though some refer the disk-swapped RAM as "virtual memory" too. – Eugene Sh. Jun 29 '21 at 14:46
-
1Probably not what you are asking, but the term "virtual memory" is sloppily used. It can mean two things: either a virtual addressing set up by configuring the MMU, or the use of a swap file in desktop OS to store parts of the current RAM on the hard drive. – Lundin Jun 29 '21 at 14:47
-
The virtual address space includes mapped and unmapped regions. Only the mapped regions count as virtual memory (but might not be memory at all - for example if hardware registers are mapped to virtual address space). – Ian Abbott Jun 29 '21 at 14:51
-
@IanAbbott So when a process gets created only the block (block size= page frame size) which gets loaded in the main memory is the virtual memory? The other blocks which are not in use are still in the hdd or secondary storage and are still not mapped to physiscal memory? – enthusiasticcoder Jun 29 '21 at 14:56
-
@Lundin Ya you are right its confusing differnt books use different terms. – enthusiasticcoder Jun 29 '21 at 14:57
1 Answers
What is the difference between virtual address space and virtual memory?
The virtual address space is literally space (in the same way that a backyard shed is storage space).
Virtual memory is something you can put in the virtual space (in the same way that gardening tools are something that you could put in a backyard shed).
You could also leave part of the virtual address space empty/unused; or put something that does not behave like memory (e.g. a memory mapped device) in the virtual address space (in the same way that you could leave part of a backyard shed empty, or put things that aren't garden tools in the shed).
For a more complete example; let's say you have a 32-bit system and virtual address spaces are 4 GiB or 4096 MiB. This 4096 MiB of space may be split 3072 MiB of "user-space" that the process could use, and 1024 MiB of "kernel space" that is reserved for the kernel itself. In this case it might end up like:
1024 MiB of space used by the process for virtual memory
2048 MiB of space that isn't used by the process (and isn't virtual memory)
128 MiB of space used by the kernel for virtual memory
32 MiB of space used by the kernel for memory mapped devices (that isn't virtual memory)
864 MiB of space that is not used by the kernel (and isn't virtual memory)
In that case; you'd have a total of "1024 + 128 = 1152 MiB" of virtual memory (and "2048 + 32 + 864 = 2944 MiB" of space that isn't virtual memory).

- 35,656
- 2
- 39
- 66
-
Hey i didnt get it actually. In book i read that virtual adress space is the space given to each process by the operating system. – enthusiasticcoder Jun 29 '21 at 17:34
-
@enthusiasticcoder: If a process is given 4 GiB of (virtual address) space, it might use 1 GiB for virtual memory (and have 3 GiB of unused space that isn't virtual memory). – Brendan Jun 29 '21 at 17:38
-
@Brenden The stack and heap will grow based on the process need? is this right? – enthusiasticcoder Jun 29 '21 at 18:34
-
The heap will grow (when you run out of virtual memory it'll ask the OS for more). The stack is likely to be a fixed amount of virtual memory, where the amount of virtual memory used for the stack is constant but how much the stack actually uses varies. – Brendan Jun 30 '21 at 01:42
-