Memory Mapped Files: Difference between revisions

From COMP15212 Wiki
pc>Yuron
No edit summary
 
gravatar W81054ch [userbureaucratinterface-adminsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPmludGVyZmFjZS1hZG1pbjxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
m (1 revision imported)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{#set: Priority=2 | Summary=Gaining access to files by <i>making them appear</i> as arrays in the address space.}}<!--
{{#set: Priority=2 | Summary=Gaining access to files by <i>making them appear</i> as arrays in the address space.}}<!--
-->{{#invoke:Dependencies|add|File Access,3|Memory,2}}
-->{{#invoke:Dependencies|add|File Access,3|Memory,2}}
A method of [[File_Access|file access]], [https://en.wikipedia.org/wiki/memory-mapped_file memory mapping] a file (or
A method of [[File_Access|file access]], [https://en.wikipedia.org/wiki/memory-mapped_file memory mapping] a file (or device) is a way of making the file <strong>appear</strong> in a process’ virtual address space.  This is not necessarily as comprehensive as the more traditional [[File_Access|file access methods]] – note that all the opened files need to fit in the process’ space and, sometimes, files are <em>large</em> (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.
device) is a way of making the file <strong>appear</strong> in a process’ virtual
address space.  This is not necessarily as comprehensive as the more
traditional [[File_Access|file access methods]] – note that all the
opened files need to fit in the process’ space and, sometimes, files
are <em>large</em> (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
Memory mapping a file on a virtual memory system does not mean the whole file is read into RAM!  Usually a “lazy” approach
whole file is read into RAM!  Usually a “lazy” approach
will be used where only the appropriate [[Paging|pages]] will be fetched, on demand.  This is basically the same demand paging
will be used where only the appropriate [[Paging|pages]] will be
fetched, on demand.  This is basically the same demand paging
mechanism used in virtual memory.
mechanism used in virtual memory.


[[Image:mmap.png|link=|alt=Memory mapped files]]
[[Image:mmap.png|link=|alt=Memory mapped files]]


There is a worked example of this process in the download <code>mmap</code>.
There is a worked example of this process in the download <code>mmap</code>. This contains quite a few obscure calls; the <em>important point</em> is the text from the file appears in an ordinary array.
This contains quite a few obscure calls; the <em>important point</em> is the
text from the file appears in an ordinary array.
----
----
 
{{BookChapter|13.5|555-560}}
{{PageGraph}}
{{PageGraph}}
{{Category|Memory}}
{{Category|Memory}}
{{Category|User}}
{{Category|User}}

Latest revision as of 10:03, 5 August 2019

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