In a system with fixed memory (non-virtual), the address space of a process occupies and is limited to a portion of the system's main memory.
In SunOS 5.0 through 5.8 virtual memory, the actual address space of a process occupies a file in the swap partition of disk storage (the file is called the backing store). Pages of main memory buffer the active (or recently active) portions of the process address space to provide code for the CPU(s) to execute and data for the program to process.
A page of address space is loaded when an address that is not currently in memory is accessed by a CPU, causing a page fault. Since execution cannot continue until the page fault is resolved, by reading the referenced address segment into memory, the process sleeps until the page has been read.
The most obvious difference between the two memory systems for the application developer is that virtual memory lets applications occupy much larger address spaces. Less obvious advantages of virtual memory are much simpler and more efficient file I/O and very efficient sharing of memory between processes.
Since backing store files (the process address space) exist only in swap storage, they are not included in the UNIX named file space. (This makes backing store files inaccessible to other processes.) However, a simple extension allows the logical insertion of all, or part, of one or more, named files in the backing store and treats the result as a single address space. This is called mapping.
With mapping, any part of any readable or writable file can be logically included in a process's address space. Like any other portion of the process's address space, no page of the file is actually loaded into memory until a page fault forces this action. Pages of memory are written to the file only if their contents have been modified. So, reading from and writing to files is completely automatic and very efficient.
More than one process can map a single named file. This provides very efficient memory sharing between processes. All or part of other files can also be shared between processes.
Not all named file system objects can be mapped. Devices that cannot be treated as storage, such as terminal and network device files, are examples of objects that cannot be mapped.
A process address space is defined by all of the files (or portions of files) mapped into the address space. Each mapping is sized and aligned to the page boundaries of the system on which the process is executing. No memory is associated with processes themselves.
A process page maps to only one object at a time, although an object address can be the subject of many process mappings. The notion of a "page" is not a property of the mapped object. Mapping an object provides only the potential for a process to read or write the object's contents.
Mapping makes the object's contents directly addressable by a process. Applications can access the storage resources they use directly rather than indirectly through read and write. Potential advantages include efficiency (elimination of unnecessary data copying) and reduced complexity (single-step updates rather than the read, modify buffer, write cycle). The ability to access an object and have it retain its identity over the course of the access is unique to this access method, and facilitates the sharing of common code and data.
Because the file system name space includes any directory trees that are connected from other systems by NFS, any networked file can also be mapped into a process's address space.
Whether to share memory or to share data contained in the file, when multiple processes map a file simultaneously there can be problems with simultaneous access to data elements. Such processes can cooperate through any of the synchronization mechanisms provided in SunOS 5.0 through 5.8. Because they are very light weight, the most efficient synchronization mechanisms in SunOS 5.0 through 5.8 are those provides in the threads library. See mutex(3THR), condition(3THR), rwlock(3THR), and semaphore(3THR) in the manual pages for details on their use.