Virtual memory is organized into "pages." A page is the unit that the OS moves around and protects,
typically a few Kbytes in size. You can look at the pagesize on your system by typing
/usr/ucb/pagesize. When a memory image travels between disk and physical memory we say it
is being paged in (if going to memory) or paged out (going to disk).
Potentially, all the memory associated with a process will need to be used by the system. If the process
is unlikely to run soon (perhaps it is low-priority or is sleeping), all of the physical memory resources
allocated to it can be taken away and backed up on disk. The process is then said to be "swapped out."
There is a special "swap area" on disk that holds memory that has been paged or swapped. The swap
area will usually be several times bigger than the physical memory on the machine. Only user
processes ever page and swap. The SunOS kernel is always memory-resident.
A process can only operate on pages that are in memory. When a process makes a reference to a page
that isn't in memory, the MMU generates a page fault. The kernel responds to the event and decides
whether the reference was valid or invalid. If invalid, the kernel signals "segmentation violation" to
the process. If valid, the kernel retrieves the page from the disk. Once the page gets back into memory,
the process becomes unblocked and can start running again—without ever knowing it had been held
up for a page-in event.
SunOS has a unified view of the disk filesystem and main memory. The OS uses an identical
underlying data structure (the vnode, or "virtual node") to manipulate each. All virtual memory
operations are organized around the single philosophy of mapping a file region to a memory region.
This has improved performance and allowed considerable code reuse. You may also hear people talk
about the "hat layer"—this is the "hardware address translation" software that drives the MMU. It is
very hardware-dependent and has to be rewritten for each new computer architecture.
Virtual memory is an indispensable technique in operating system technology now, and it allows a
quart of processes to run in a pint pot of memory. The light relief section at the end of this chapter has
an additional description of virtual memory, written as a fable. It's a classic.
Programming Challenge