Memory Mapped Files

From COMP15212 Wiki
Depends on File AccessMemory

A method of file access, memory mapping a file (or device) is a way of making the file appear in a process’ virtual address space. This is not necessarily as comprehensive as the more traditional file access methods – note that all the opened files need to fit in the process’ space and, sometimes, files are large (though with the advent of 64-bit address spaces on larger machines this will probably be less of a problem … at least for a few years). On the other hand it can be convenient to use and will typically be significantly faster than making sets of system calls.

Memory mapping a file on a virtual memory system does not mean the whole file is read into RAM! Usually a “lazy” approach will be used where only the appropriate pages will be fetched, on demand. This is basically the same demand paging mechanism used in virtual memory.

Memory mapped files

There is a worked example of this process in the download mmap. This contains quite a few obscure calls; the important point is the text from the file appears in an ordinary array.


Also refer to: Operating System Concepts, 10th Edition: Chapter 13.5, pages 555-560


Articles on User
"Everything is a File" • Application Binary Interface (ABI) • Arrays • Boot • Buffer Overflow • Containers • Daemons • Disk Partition • Dynamic Memory Allocation • Emulator traps • Environment Variables • Errors • Exceptions • File Attributes • File Locking • File Permissions • Introduction to Operating Systems • Journalling File System • Links • Locks • Man(ual pages in Unix) • Memory Mapped Files • Monitoring • Network File System (NFS) • PATH • Pipes • Pointers • Relocatable Code • Reset • SETUID • Shell • Sockets • Spooling and Buffering • Streams • Structures • Superuser • System Calls • Unix Signals • User • Using Peripherals