CS FundamentalsHardAccenture · Capgemini pattern

Memory-mapped files (via mmap) let a process treat a file's contents as part of its address space. Compared to read()/write() calls, what is the main advantage for random access to a large file?

  1. A. The OS can page in only the parts of the file actually touched (via demand paging), and repeated access avoids a system call and an extra buffer copy on every read
  2. B. mmap works only for files smaller than one page
  3. C. mmap removes the need for any page table entries
  4. D. mmap always loads the entire file into memory immediately, so it is simpler for the OS

Correct answer: A. The OS can page in only the parts of the file actually touched (via demand paging), and repeated access avoids a system call and an extra buffer copy on every read

mmap maps file pages into the address space lazily; accessing an unmapped region faults it in via the normal demand-paging machinery, and subsequent reads/writes are just memory accesses — no per-access system call or copy between a kernel buffer and user buffer, which read()/write() otherwise pay for on every call.

More Operating Systems questions

Exams that ask this topic