2
votes

I'm a a total noob in this field, so please bear with my question and answer it :)

I was reading about process address space, virtual memory and paging. I understood the mechanism of pages being swapped in and out of RAM. It is documented that every process is given a virtual address space of 4GB, out of which a portion is for user space (specific to each process - 1 or 2 GB) and the rest is kernel space (which is common across all processes).Since the vritual address space for each process is stored in secondary storage, does it mean that every time I launch a process, it reserves 4 GB in my hard disk ? I don`t see my hard disk space being reduced by 4GB each time I start a process... or is it something like the virtual space is not reserved as a block but rather starts small and can grow upto 4GB. Please shed some light, and also do post some links on the topic if you know any.. anything that would help me understand this complex topic.

4

4 Answers

2
votes

Virtual address memory management doesn’t use secondary storage. It just divides your program and main memory into some partition size. Main memory partitions are called frames and program partitions are called pages. Each partition in main memory and frame are of the same size.

whenever a program is used, the kernel checks if all pages of this programs can be fit into main memory. if so, it will keep all pages in main memory. other wise it will keep only pages that are necessary at first. when other pages are required later it removes one of the frames from main memory and then transfers the requested page to where the frame was removed.

For mapping of address from pages to frames the kernel uses a page map table, which tells exactly in which frame in main memory this particular page is located.

Check the below references: https://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Memory/virtual.html https://www.bottomupcs.com/virtual_addresses.xhtml

1
votes

It is offtopic here and one could elaborate hundreds of pages text about (see the cs books on this topic).

But in short you are wrong: virtual memory is NOT stored in secondary storage. It can be there, but usually it is not. The OS is handling it, depending on its information it keeps the data in normal memory (e.g. when then process is active), or it is on hdd (e.g. when the memory is short and the process is inactive).

The virtualisation means, that for the process it is transparent, it does not know where the data is stored, it is always accessed via the same pointer. The system can change the underlying storage depending on the circumstances (it is then swapping data in or out).

0
votes

Virtual address space is not "stored" anywhere. Only pages of memory allocated for the process may be stored in memory/on disk.

The allocation of memory depends of operating system. I.e. in Windows Allocation and managment can be done by program using corresponding memory functions, like VirtualAlloc to map memory to address space and VirtualProtect function to specify what attributes given memory block allocated in your program's address space should have.

-1
votes

Well, that's a good question for a total noob in this field.What actually happens is that the process that is executing is made to think that it has all the memory,while it only has a few memory that will expand as it grows.This memory is called virtual memory.

I hope this answer is helpful.