Jump to content

Mmap: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
Line 25: Line 25:
== References and further reading ==
== References and further reading ==
*{{cite web | accessdate = 2005-08-23|url=http://mia.ece.uic.edu/~papers/WWW/books/posix4/DOCU_004.HTM|title=Shared Memory|work=Guide to Realtime Programming|author=[[Digital Equipment Corporation]] }}
*{{cite web | accessdate = 2005-08-23|url=http://mia.ece.uic.edu/~papers/WWW/books/posix4/DOCU_004.HTM|title=Shared Memory|work=Guide to Realtime Programming|author=[[Digital Equipment Corporation]] }}

*{{cite web | accessdate = 2007-02-16|url=http://beej.us/guide/bgipc/output/html/multipage/mmap.html|title=Memory Mapped Files|work=Beej's Guide to Unix Interprocess Communication|author=Brian "Beej" Hall }}
*{{cite web | accessdate = 2007-02-16|url=http://beej.us/guide/bgipc/output/html/multipage/mmap.html|title=Memory Mapped Files|work=Beej's Guide to Unix Interprocess Communication|author=Brian "Beej" Hall }}

*[http://opengroup.org/onlinepubs/009695399/functions/mmap.html Description from POSIX standard]
*[http://opengroup.org/onlinepubs/009695399/functions/mmap.html Description from POSIX standard]
*{{man|3|mmap||map pages of memory}}
*{{man|3|mmap||map pages of memory}}

*{{cite web | accessdate = 2008-09-
06|url=http://s.kartikeyan.googlepages.com/mmap.html|title=Linux Kernel MMAP Discussion|author=[S.Kartikeyan] }}

*Differences:
*Differences:
**[http://www.freebsd.org/cgi/man.cgi?query=mmap FreeBSD]
**[http://www.freebsd.org/cgi/man.cgi?query=mmap FreeBSD]

Revision as of 13:33, 6 September 2008

In computing, mmap is a POSIX-compliant Unix system call that maps files or devices into memory. It is a method of memory-mapped file I/O. It naturally implements demand 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 and Mac OS X, mmap can create several types of mappings.

Anonymous mappings are mappings of physical RAM to virtual memory. This is similar to malloc, 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 modern operating systems mmap is typically preferred to the System V IPC Shared 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

References and further reading

  • Digital Equipment Corporation. "Shared Memory". Guide to Realtime Programming. Retrieved 2005-08-23.
  • Brian "Beej" Hall. "Memory Mapped Files". Beej's Guide to Unix Interprocess Communication. Retrieved 2007-02-16.

06. {{cite web}}: Check date values in: |accessdate= (help); line feed character in |accessdate= at position 9 (help)