In the process address space, there is the stack and the heap. When a function is called, or even when a local variable is declared, it uses the stack; the kernel must assign physical address and create the mapping of virtual to physical address; so, a system call should be involved here, what is going on?
How does stack allocation work in Linux?
The first answer says: "I've found that the stack grows without any system call (according to strace). So, this means that the kernel grows it automatically (this is what the "implicit" means above), i.e. without explicit mmap/mremap from the process." If it is the job of the kernel to "grow" the stack, why is a system call not involved?
When is the heap used for dynamic memory allocation?
For the heap, the first answer says: "A call to malloc does not necessarily result in a call to sbrk or mmap (depending on how Libc implements dynamic memory allocation) to expand the mappings, if a call to malloc can be satisfied by reusing previously freed memory areas." I guess this is the concept of free lists. Is this same concept used for stack allocation?
My basic grievance in both allocations is that physical memory must be allocated, and the mapping from VMA to physical must be created, so a system call should happen. I tried reading the book by Mel Gorman linked in the answer to the first question, but couldn't find anything meaningful to answer my question.
read(2)
), appear pretty much as function calls to the application program, how would that even work? Could there be an alternative explanation? Perhaps that the OS actually doesn't need to be involved in the bookkeeping of every single variable separately, but can do with just larger-scale bookkeeping, e.g. on a page or segment level (or what have you)?