What are memory mappings?

A memory mapping is a set of page table entries describing the properties
of a consecutive virtual address range.  Each memory mapping has a
start address and length, permissions (such as whether the program can
read, write, or execute from that memory), and associated resources (such
as physical pages, swap pages, file contents, and so on).
Creating new memory mappings allocates virtual memory, but not physical
memory (except for a small amount of physical memory needed to store the
page table itself).  Physical pages are attached to memory mappings later,
in response to page faults.  Physical memory is allocated on-demand by the
page fault handler as necessary to resolve page faults.
A page table can be thought of as a description of a set of memory
mappings.  Each memory mapping can be anonymous, file backed, device backed,
shared, or copy on write.
The mmap() system call adds a new memory mapping to the current process's
page tables.  The munmap() system call discards an existing mapping.
Memory mappings cannot overlap.  The mmap() call returns an error if asked
to create overlapping memory mappings.
Virtual address ranges for which there is no current memory mapping are said
to be "unmapped", and attempts to access them generate a page fault which
cannot be handled.  The page fault handler sends a Segmentation
Violation signal (SIGSEGV) to the program on any access to unmapped
addresses.  This is generally the result of following a "wild pointer".
Note that by default, Linux intentionally leaves the first few kilobytes
(or even megabytes) of each process's virtual address space unmapped, so
that attempts to dereference null pointers generate an unhandled page
fault resulting in an immediate SIGSEGV, killing the process.

Leave a Reply

Your email address will not be published. Required fields are marked *