- Mmap
In
computing , mmap is aPOSIX -compliantUnix system call that maps files or devices into memory. It is a method ofmemory-mapped file I/O. It naturally implementsdemand paging , because initially file contents are "not" entirely read from disk and don't use physical RAM at all. The actual reads from disk are performed in "lazy" manner, after a specific location is accessed.In
Linux andMac OS X , mmap can create several types of mappings.Anonymous mappings are mappings of physical RAM to
virtual memory . This is similar tomalloc , and is used in some malloc implementations for certain allocations.File-backed mappings are mappings of files to virtual memory. Access to those areas of memory causes the file to be changed. 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 (the segment of the file mapped in is copied to RAM and periodically flushed to disk). mmaping files can significantly reduce memory overhead for applications accessing the same file. If the file is mmaped the applications can then share the memory area the file encompasses, instead of loading the file for each application that wants access to it.
Memory shared by mmap is kept visible across a fork.
mmap is sometimes used for
Interprocess Communication (IPC). On modernoperating system s mmap is typically preferred to theSystem V IPCShared Memory facility.The main differences between System V shared memory (shem) and memory mapped I/O (mmap) are:
* In SystemV Shared memory resource is persistent: unless explicitly removed by a process, it is kept in memory and remains available until the system is shut down.
* mmap'ed shared memory is not persistent between application executions.See also
*
Virtual memory for a general context of possessing more addresses than physical memory
**Swapping orPaging for implementation of virtual memory used in contemporary systems
***Page cache , a disk caching mechanism utilized by mmap
***Demand paging a scheme implemented by mmapReferences and further reading
*
*cite web | url=http://s.kartikeyan.googlepages.com/mmap.html|title=MMAP Kernel/Device Drivers side |author=
S.Kartikeyan *Differences:
** [http://www.freebsd.org/cgi/man.cgi?query=mmap FreeBSD]
** [http://linux.about.com/library/cmd/blcmdl2_mmap.htm Linux]
** [http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/mmap.2.html Mac OS X]
** [http://docs.sun.com/app/docs/doc/816-5167/mmap-2?a=view Solaris]
** [http://devrsrc1.external.hp.com/STKS/cgi-bin/man2html?debug=0&manpage=/usr/share/man/man2.Z/mmap.2 HP-UX]
Wikimedia Foundation. 2010.