Questions: Memory-Mapped Files and I/O

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A process calls mmap() to map a large file and then reads the first byte of the mapped region for the first time. What happens?

AThe kernel immediately reads the entire file into physical memory before returning from mmap()
BA page fault occurs, the kernel reads the corresponding file page into a physical frame, updates the page table, and returns control to the process
CThe operating system copies the data into a user-space buffer, just like read() would
DNothing happens until the process calls msync() to load the data
Question 2 Multiple Choice

Two processes memory-map the same file with MAP_SHARED. Process A writes to the mapped region. When does Process B see the change?

ANever — each process gets its own private copy of the file data when it calls mmap()
BOnly after Process A calls msync() and Process B calls munmap() and remaps the file
CImmediately, because both processes share the same physical pages in the page cache
DAfter the kernel's writeback daemon flushes the changes to disk and Process B re-reads from disk
Question 3 True / False

Memory-mapped file I/O can achieve zero-copy reads because the process accesses file data directly in the page cache, avoiding an extra copy into a separate user-space buffer.

TTrue
FFalse
Question 4 True / False

Memory-mapped I/O is typically faster than read()/write() and should be preferred for most file access patterns.

TTrue
FFalse
Question 5 Short Answer

Explain how the kernel handles a page fault when a process accesses an address in a memory-mapped file region that hasn't been loaded yet, and why this mechanism is preferable to loading the entire file up front.

Think about your answer, then reveal below.