Search code examples
linux-kernelmmap

Does Linux immediately allocate memory for process after mmap()?


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()?


Solution

  • 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.