1

I am very much confused about the allocation of virtual memory to a process.

How does the OS determine the amount of "virtual memory" which should be assigned to a process? Does it depend on the process size?

Does it depend on the size of the RAM ("main memory")? If yes, then suppose the size of the RAM is 4GB, and the resident OS takes 1GB for its execution: how much virtual memory will be assigned to a process?

2 Answers 2

1

The virtual memory is usually the sum of the resident memory and everything that is not mapped into physical memory, e.g. swap, open files etc. The operating system doesn't determine the size of the memory -- a process allocates memory explicitly to do what it wants to do. Other memory (e.g. for mapped files) is allocated implicitly, but there, too, the amount of memory is determined by the size of the resource.

0

The amount of virtual memory available is determined by the bitness of the operating system. For instance, in a 32-bit operating system, each process typically has access to a 4 GB virtual address space. This means that, theoretically, each process can address up to 4 GB of virtual memory.

However, the available physical RAM (installed memory) is a separate factor. In a 32-bit system, the total physical memory that can be addressed is limited to 4 GB as well. This includes both RAM and memory-mapped devices

So, even if you have, for example, 1 GB of physical RAM installed in a 32-bit operating system, each process can still theoretically address up to 4 GB of virtual memory. They only see the 4 virtual gigs that the OS is showing to them.

Now, you may be wondering, what if a process wants to access more physical addresses than the available ones that weren't occupied by other earlier active processes ?! In that situation, the operating system can move bytes of memory to secondary storage to make room in RAM for newly requested memory, a process known as paging. Typically, the least used memory gets paged first so that actively used memory can remain in RAM. When the paged memory is needed, the OS must load it back into RAM. Paging allows for greater virtual memory usage, at the cost of a performance hit incurred while bytes are moved to and from secondary storage. Keep in mind that secondary storage is significantly slower than RAM.

Not the answer you're looking for? Browse other questions tagged or ask your own question.