13.4 Memory Management
13.4.1 Physical memory (RAM) and swap space
Physical Memory
All computers have physical or system memory microchips. This is most often referred to as random access memory (RAM). This memory is controlled directly by the processor in conjunction with the Memory Management Unit (MMU). RAM is the working storage area of the computer where programs (sequence of instructions) and data related to the programs are stored while the program is running. When a program is running, it is copied off the hard disk into RAM and space is allocated in RAM for the program to do its work.

RAM is empty when the system first starts up. The UNIX operating system kernel is the first thing to load into RAM. Other critical system programs such as init and lpsched are then loaded. As mentioned earlier, the OS kernel manages all other programs or processes by assigning CPU time and RAM space to them. As mentioned earlier, the OS kernel manages all other programs or processes by assigning CPU time and RAM space to them.

Virtual Memory
Many processes are held simultaneously in RAM, so it is possible to use it up. If a new process needs to be placed in RAM, the pageout process selects pages of a process that are not currently in use and sends them temporarily out to swap space on the disk. The selection of pages is made based on a "not recently used" algorithm. Swap space is a raw slice or disk file that is set aside during system installation for this purpose. Processes remain in RAM while they are active. The swapping process uses swap space on the disk which is limited. The combination of RAM plus swap space constitutes virtual memory which is the maximum space that processes can use. Virtual memory has a much shorter access time than accessing something on the formatted areas of the disk. Since the kernel manages the swapping process, it cannot be swapped. The Figure shows the kernel swapping programs in an out of swap the space on the hard disk.

Paging
A program on a Sun workstation can address up to 4 GB or Gigabytes of memory. A system is typically equipped with some number of Mbytes of RAM. During its execution, a process is placed in RAM (divided into pages) and is swapped page by page in and out of RAM. This process is called paging. Swapping rarely takes place on systems with very large amounts of RAM.