How is a process virtual address space size determined when a process starts on Unix systems? What happens between VAS, PAS, through VMM when the process data segment or stack must grow?
Looking at the picture below it appears VAS is larger than physical address space, which I’m assuming allows for paging to disk.
I ask because in an earlier question I had answered here, brk() and sbrk() syscalls are used to increase the size of the process data segment. Then somehow the stack can grow in size. My assumption is the VAS for the process is already large and the VMM through some syscalls maps pages to the VAS.
Ref link
How is a process virtual address space size determined when a process starts on Unix systems?
The simple answer is that the virtual address space size is determined by the instruction set architecture and the operating system.
In a 32 bit machine (that supports virtual memory) the virtual address space size is up to 2^32.
In a 64 bit machine, the virtual address space size is up to 2^64.
In practice, operating system implementation details and hard limitations mean that not all of the theoretically available virtual space will actually be available.
Part of the virtual address space is reserved for use by the OS kernel. When running in kernel mode, the OS needs to be able to address all of pages of the user process. For example, a user process can issue a write
syscall for a buffer anywhere in its virtual address space. The kernel the needs to be able to address the buffer to copy the data. At the same time, the kernel needs a virtual address space for its own code and data structures and buffers. This is implemented by reserving part of the virtual address space for the operating system. For example, on current generation 64 bit Linux systems, addresses from 0x80000000
to 0xffffffff
are reserved for the kernel.
It is theoretically possible to provide the full 32 or 64 bits of virtual address space to a process, but will make the OS more complicated, and potentially increase syscall context switch overheads. Linux doesn't support this.
What happens between VAS, PAS, through VMM when the process data segment or stack must grow?
The short answer is that the virtual memory system adds more entries into the page table to map more of the processes virtual address space to physical RAM pages.
(I assume that you have already studied how virtual memory page tables work. If not, read this: https://en.wikipedia.org/wiki/Page_table)