Mmap

From Free net encyclopedia

Template:Lowercase

In computing, mmap is a POSIX-compliant Unix system call that maps files or devices into memory. It is a kind of memory-mapped I/O.

In Linux, mmap can create several types of mappings.

Anonymous mappings are mappings of physical RAM to virtual RAM. This is similar to malloc, and is used in some malloc implementations for certain allocations.

File backed mappings are mappings of files to virtual RAM. Access to those areas of RAM causes the file to be changed. Usually, the segment of the file mapped in is copied to RAM and periodically flushed to disk. If the mapping is shared, changes to that area in one process will affect other processes with that area mapped in immediately; otherwise, the changes will be asynchronous, and processes will not always have consistent views of that area. mmapping files can significantly reduce memory overhead for applications accessing the same file. If the file is mmapped the applications can then share the memory area the file encompassess, instead of loading the file for each application that wants access to it.

Memory shared by mmap kept visible across a fork.

mmap is sometimes used for Interprocess Communication (IPC). On modern operating systems mmap is typically preferred to the System V IPC shared memory facility.

References and further reading

pl:mmap