Hardware Reference
In-Depth Information
Address
0xFFFFFFFF
Stack
Data
Code
0
Figure 6-33. The address space of a single UNIX process.
is permitted to have programs larger than the machine's physical memory. UNIX
systems that do not have paging generally swap entire processes between memory
and disk to allow an arbitrarily large number of processes to be timeshared.
For Berkeley UNIX , the above description (demand-paged virtual memory) is
basically the entire story. However, System V (and also Linux) include several fea-
tures that allow users to manage their virtual memory in more sophisticated ways.
Most important of these is the ability of a process to map a (portion of a) file onto
part of its address space. For example, if a 12-KB file is mapped at virtual address
144K, a read to the word at address 144 KB reads the first word of the file. In this
way file I/O can be done without making system calls. Since some files may
exceed the size of the virtual address space, it is also possible to map in only a por-
tion of a file instead of the whole file. The mapping is done by first opening the
file and getting back a file descriptor, fd , which is used to identify the file to be
mapped. Then the process makes a call
paddr = mmap(virtual address, length, protection, flags, fd, file offset)
which maps length bytes starting at file offset in the file onto the virtual address
space starting at virtual address . Alternatively, the flags parameter can be set to
ask the system to choose a virtual address, which it then returns as paddr . The
mapped region must be an integral number of pages and aligned at a page bound-
ary. The protection parameter can specify any combination of read, write, or ex-
ecute permission. The mapping can be removed later with unmap .
Multiple processes can map onto the same file at the same time. Two options
are provided for sharing. In the first one, all the pages are shared, so writes done
by one process are visible to all the others. This option provides a high-bandwidth
communication path between processes. The other option shares the pages as long
as no process modifies them. However, as soon as any process attempts to write on
a page, it gets a protection fault, which causes the operating system to give it a pri-
vate copy of the page to write on. This scheme, known as copy on write , is used
when each of multiple processes needs the illusion it is the only one mapped onto a
file. In this model the sharing is an optimization, not part of the semantics.
 
 
Search WWH ::




Custom Search