What are the advantages of memory-mapped files?

I think the advantage is really that you reduce the amount of data copying required over traditional methods of reading a file.

If your application can use the data “in place” in a memory-mapped file, it can come in without being copied; if you use a system call (e.g. Linux’s pread() ) then that typically involves the kernel copying the data from its own buffers into user space. This extra copying not only takes time, but decreases the effectiveness of the CPU’s caches by accessing this extra copy of the data.

If the data actually have to be read from the disc (as in physical I/O), then the OS still has to read them in, a page fault probably isn’t any better performance-wise than a system call, but if they don’t (i.e. already in the OS cache), performance should in theory be much better.

On the downside, there’s no asynchronous interface to memory-mapped files – if you attempt to access a page which isn’t mapped in, it generates a page fault then makes the thread wait for the I/O.


The obvious disadvantage to memory mapped files is on a 32-bit OS – you can easily run out of address space.

Leave a Comment