<s>
In	O
computing	O
,	O
mmap(2 )	O
is	O
a	O
POSIX-compliant	O
Unix	B-Application
system	I-Application
call	O
that	O
maps	O
files	O
or	O
devices	O
into	O
memory	O
.	O
</s>
<s>
It	O
is	O
a	O
method	O
of	O
memory-mapped	B-General_Concept
file	I-General_Concept
I/O	O
.	O
</s>
<s>
It	O
implements	O
demand	B-General_Concept
paging	I-General_Concept
because	O
file	O
contents	O
are	O
not	O
immediately	O
read	O
from	O
disk	O
and	O
initially	O
use	O
no	O
physical	O
RAM	O
at	O
all	O
.	O
</s>
<s>
Protection	B-General_Concept
information	O
—	O
for	O
example	O
,	O
marking	O
mapped	O
regions	O
as	O
executable	O
—	O
can	O
be	O
managed	O
using	O
mprotect(2 )	O
,	O
and	O
special	O
treatment	O
can	O
be	O
enforced	O
using	O
madvise(2 )	O
.	O
</s>
<s>
In	O
Linux	B-Application
,	O
macOS	B-Application
and	O
the	O
BSDs	B-Operating_System
,	O
mmap	B-Operating_System
can	O
create	O
several	O
types	O
of	O
mappings	O
.	O
</s>
<s>
Other	O
operating	B-General_Concept
systems	I-General_Concept
may	O
only	O
support	O
a	O
subset	O
of	O
these	O
;	O
for	O
example	O
,	O
shared	O
mappings	O
may	O
not	O
be	O
practical	O
in	O
an	O
operating	B-General_Concept
system	I-General_Concept
without	O
a	O
global	O
VFS	B-Application
or	O
I/O	O
cache	O
.	O
</s>
<s>
The	O
original	O
design	O
of	O
memory-mapped	B-General_Concept
files	I-General_Concept
came	O
from	O
the	O
TOPS-20	B-Operating_System
operating	B-General_Concept
system	I-General_Concept
.	O
</s>
<s>
mmap	B-Operating_System
and	O
associated	O
systems	O
calls	O
were	O
designed	O
as	O
part	O
of	O
the	O
Berkeley	B-Operating_System
Software	I-Operating_System
Distribution	I-Operating_System
(	O
BSD	B-Operating_System
)	O
version	O
of	O
Unix	B-Application
.	O
</s>
<s>
Sun	O
Microsystems	O
had	O
implemented	O
this	O
very	O
API	O
,	O
though	O
,	O
in	O
their	O
SunOS	B-Operating_System
operating	B-General_Concept
system	I-General_Concept
.	O
</s>
<s>
The	O
BSD	B-Operating_System
developers	O
at	O
University	O
of	O
California	O
,	O
Berkeley	O
unsuccessfully	O
requested	O
Sun	O
to	O
donate	O
its	O
implementation	O
;	O
4.3BSD-Reno	O
was	O
instead	O
shipped	O
with	O
an	O
implementation	O
based	O
on	O
the	O
virtual	B-Architecture
memory	I-Architecture
system	O
of	O
Mach	B-Operating_System
.	O
</s>
<s>
File-backed	O
mapping	O
maps	O
an	O
area	O
of	O
the	O
process	O
's	O
virtual	B-Architecture
memory	I-Architecture
to	O
files	O
;	O
that	O
is	O
,	O
reading	O
those	O
areas	O
of	O
memory	O
causes	O
the	O
file	O
to	O
be	O
read	O
.	O
</s>
<s>
Anonymous	O
mapping	O
maps	O
an	O
area	O
of	O
the	O
process	O
's	O
virtual	B-Architecture
memory	I-Architecture
not	O
backed	O
by	O
any	O
file	O
.	O
</s>
<s>
In	O
this	O
respect	O
an	O
anonymous	O
mapping	O
is	O
similar	O
to	O
malloc	B-Language
,	O
and	O
is	O
used	O
in	O
some	O
malloc	B-Language
implementations	O
for	O
certain	O
allocations	O
,	O
particularly	O
large	O
ones	O
.	O
</s>
<s>
Anonymous	O
mappings	O
are	O
not	O
part	O
of	O
the	O
POSIX	O
standard	O
,	O
but	O
are	O
implemented	O
in	O
almost	O
all	O
operating	B-General_Concept
systems	I-General_Concept
by	O
the	O
MAP_ANONYMOUS	O
and	O
MAP_ANON	O
flags	O
.	O
</s>
<s>
If	O
the	O
mapping	O
is	O
shared	O
(	O
the	O
MAP_SHARED	O
flag	O
is	O
set	O
)	O
,	O
then	O
it	O
is	O
preserved	O
when	O
a	O
process	O
is	O
forked	O
(	O
using	O
a	O
fork(2 )	O
system	B-Operating_System
call	I-Operating_System
)	O
.	O
</s>
<s>
If	O
the	O
mapping	O
is	O
shared	O
and	O
backed	O
by	O
a	O
file	O
(	O
not	O
MAP_ANONYMOUS	O
)	O
the	O
underlying	O
file	O
medium	O
is	O
only	O
guaranteed	O
to	O
be	O
written	O
after	O
it	O
is	O
passed	O
to	O
the	O
msync(2 )	O
system	B-Operating_System
call	I-Operating_System
.	O
</s>
<s>
Using	O
mmap	B-Operating_System
on	O
files	O
can	O
significantly	O
reduce	O
memory	O
overhead	O
for	O
applications	O
accessing	O
the	O
same	O
file	O
;	O
they	O
can	O
share	O
the	O
memory	O
area	O
the	O
file	O
encompasses	O
,	O
instead	O
of	O
loading	O
the	O
file	O
for	O
each	O
application	O
that	O
wants	O
access	O
to	O
it	O
.	O
</s>
<s>
This	O
means	O
that	O
mmap(2 )	O
is	O
sometimes	O
used	O
for	O
Interprocess	B-Operating_System
Communication	I-Operating_System
(	O
IPC	O
)	O
.	O
</s>
<s>
On	O
modern	O
operating	B-General_Concept
systems	I-General_Concept
,	O
mmap(2 )	O
is	O
typically	O
preferred	O
to	O
the	O
System	B-Operating_System
V	I-Operating_System
IPC	O
Shared	B-Operating_System
Memory	I-Operating_System
facility	O
.	O
</s>
<s>
The	O
main	O
difference	O
between	O
System	B-Operating_System
V	I-Operating_System
shared	B-Operating_System
memory	I-Operating_System
(	O
shmem	O
)	O
and	O
memory	O
mapped	O
I/O	O
(	O
mmap	B-Operating_System
)	O
is	O
that	O
System	B-Operating_System
V	I-Operating_System
shared	B-Operating_System
memory	I-Operating_System
is	O
persistent	O
:	O
unless	O
explicitly	O
removed	O
by	O
a	O
process	O
,	O
it	O
is	O
kept	O
in	O
memory	O
and	O
remains	O
available	O
until	O
the	O
system	O
is	O
shut	O
down	O
.	O
</s>
<s>
mmap	B-Operating_System
'd	O
memory	O
is	O
not	O
persistent	O
between	O
application	O
executions	O
(	O
unless	O
it	O
is	O
backed	O
by	O
a	O
file	O
)	O
.	O
</s>
