I am reading the source code of mmap(), and I found the Linux kernel will make the files map into the vma struct. vma only represents memory areas. So, will the OS immediately allocate physical memory for the process after mmap()?
1 Answer
No, Linux may defer allocation of the physical memory, requested by mmap, until that memory will be accessed.
When application accesses an unmapped memory, page fault exception is triggered; when handle this exception, Linux may map that accessed memory, allowing the application to continue.
2 Comments
Chris Tsui
the “unmapped memory” mentioned above should be area allocated in vma but not mapped in page table. :-)
Tsyvarev
Yes, being listed in
vma gives a chance for unmapped memory to be mapped on page fault. But that page fault is caused by access to any unmapped memory, being it in vma or not. This is what my post talsk about.