Chapter 20. Virtual Memory


Many systems use what is known as "virtual memory." It doesn't mean that you almost remember what happened yesterday but instead refers to how a program will see the environment in which it's running.

Virtual memory means that a user program thinks that the whole machine belongs to it. The entire range of addresses that the CPU could reach (the address space of the processor) looks like it belongs to that program, and there is nobody else to share with. It means that a program does not have to be restricted by the physical parameters of the hardware on which it's running. The hardware and the kernel will take care of the insignificant little details like other users trying to use the system or a distressing lack of physical memory on the machine.

The idea is that a program may use a range of memory addresses so large that the actual physical memory that exists on the machine cannot hold it all at once ” and it doesn't have to. Real memory is treated more like a "cache" of commonly or recently used chunks of memory. The hardware (and supporting kernel code) will detect an attempt to access a data value that is not actually resident in the physical memory on the machine, find the appropriate disk block with that data, load it into the system, and let the user program continue with its access as if nothing had happened. What the user sees as "real memory" bears little or no relationship to the actual amount of memory present. And, as you might expect, the addresses that a user program references also are unrelated to the actual location of the data: The hardware performs translations on these "virtual" addresses and turns them into real physical addresses of real physical memory.

Now, this does require some hardware support at several points. First, the CPU must be able to "freeze" the execution of an instruction that is trying to reference nonexistent memory. This will allow it to be continued or restarted when the address is made valid. The system must also have a way of mapping the addresses that the user needs to arbitrary physical locations. These physical addresses may actually change over time as data is moved out of memory and back in again. Also, memory normally must be organized in some way so that chunks of it can be manipulated easily. Usually, this is done by defining memory in terms of fixed size pages . All these capabilities are standard on most modern CPUs. The Memory Management Unit (MMU) takes care of the translations, signals the processor when a translation fails (there is no place in real physical memory that currently corresponds to the desired location), and usually determines the organization of physical memory (whether or not it is split into pages, and how big those pages are).

Virtual memory processing in the kernel consists of managing the physical memory as a collection of pages, which is used to hold as much of a user process as is possible. When total user requirements exceed the number of available memory pages, then the kernel attempts to store some of the pages out on disk until needed, keeping only the most recently accessed pages in memory.

Memory inside Sun's UNIX kernel is also set up as a range of virtual addresses. As far as the kernel is concerned , memory is considered to be of two types: kernel memory and everything else. In general, kernel memory is allocated and locked down. User memory can be tossed out to disk at any time, so that the pages can be reused for something else more pressing; for example, to satisfy a request for more memory from a higher priority process, to increase the kernel's supply of pages, or even to receive data from an important disk read request.



PANIC. UNIX System Crash Dump Analysis Handbook
PANIC! UNIX System Crash Dump Analysis Handbook (Bk/CD-ROM)
ISBN: 0131493868
EAN: 2147483647
Year: 1994
Pages: 289
Authors: Chris Drake

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net