Science  People  Locations  Timeline
Index: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Home > Virtual memory


 

Virtual memory is a computer design feature that permits software to use more memory than the computer physically possesses. In technical terms, it allows software to run in a memory address space whose size and addressing are not necessarily tied to the computer's physical memory. While conceivably virtual memory can be implemented solely by operating system software, in practice its implementation almost universally uses a combination of hardware and operating system software.

1 History

The technique was invented at the University of Manchester for the Atlas Computer, completed in 1962. It might be worth a note though that Fritz-Rudolf Güntsch, one of Germany's pioneering computer scientists and later the developer of the Telefunken TR 440 mainframe, claims to have invented the concept in his doctoral dissertation Logischer Entwurf eines digitalen Rechengerätes mit mehreren asynchron laufenden Trommeln und automatischem Schnellspeicherbetrieb (Logic Concept of a Digital Computing Device with Multiple Asynchronous Drum Storage and Automatic Fast Memory Mode) in 1957.

Prior to widespread adoption of virtual memory, memory overlay s were frequently used to accommodate programs whose total program size exceeded the available memory on the computer.

2 Explanation

Simply put, when a memory location is read or written to, hardware within the computer translates the memory address generated by the software (the virtual memory address) into a, usually distinct, real memory address (the physical memory address) within the computer's memory. This is accomplished by preserving the low order bits of the binary representation of the input address while treating the high order bits as a key to one or more address translation tables. For this reason a range of consecutive addresses in the virtual address space whose size is a power of two will be translated in a corresponding range of consecutive physical addresses. The memory referenced by such a range is called a page. The page size is typically in the range of 512 to 8192 bytes (with 4K being very common), though page sizes of 4 megabytes or larger may be used for special purposes. Using the same or a related mechanism, contiguous regions of virtual memory larger than a page are often mappable to contiguous physical memory for purposes other than virtualization, such as setting access and cache control bits.

The translation is implemented by an MMU. This may be either a module of the CPU or an auxiliary, closely coupled chip. The MMU may have the ability to monitor page references according to the type of reference (for read, write or execution) and the privilege mode of the CPU at the time the reference was generated. In addition, the MMU may detect that a reference is to a page that is marked as unavailable. The MMU responds to such conditions by raising an exception with the CPU which then jumps to a routine in the operating system which handles these occurrences. Typically this routine invokes a process called a page swap. Once the page swap completes, the program is restarted and continues on as if nothing had happened.

The page swap process involves a series of steps. First it selects a page in memory, for example, a page that has not been recently accessed and, preferably, has not been modified since it was last read from disk or the swap file. (See page replacement algorithmsIn a computer operating system which utilises paging for memory management, page replacement algorithms are used to decide what pages to swap out when a page needs to be swapped in. That happens when a page fault occurs. The Theoretically Optimal Page Rep for details.) If the page has been modified, the process writes the modified page to the swap file. The next step in the process is to read in the memory page information from the swap file. The particular information is that data corresponding to the virtual address the original program was trying to access when the exception occurred. When the page has been read in, the tables for translating virtual addresses to physical addresses are updated to reflect the revised contents of the physical memory. The page swap process then exits, returning to the point in the program that caused the exception. The effect of this is to swap sections of information between the main memory and the swap file, which usually resides on much slower magnetic disk. The swap file on some operating systems is on a dedicated partition of a disk.

To minimize the performance penalty of address translation, most modern CPUs include an on-chip MMU, and maintain a table of recently used physical-to-virtual translations, called a Translation Lookaside BufferTranslation Lookaside Buffer is a buffer (or cache) in a CPU that contains parts of the Page table which references between virtual and real addresses. This buffer has a certain number of entries and is used for speed improvement. The buffer is typically, or TLB. Addresses with entries in the TLB require no additional time to translate. The operating system however also manages these mappings, and stores the mappings in a data structure known as a page tableA page table is an integral part of a virtual memory system in an operating system it provides the means for holding mappings between virtual addresses and physical addresses. Virtual memory In a virtual memory system, the address space does not match phy, which can indicate whether page swapping is necessary. However, the TLB can only maintain a fixed number of mappings between virtual and physical addresses. When there is no such mapping in the TLB, an exception can be raised. On this exception, the operating system replaces one of the entries in the TLB with an entry from the page table, and the instruction is restarted.

The hardware that supports virtual memory almost always supports memory protection mechanisms as well. This allows the operating system to protect its own code and the page tables used for virtual memory from corruption by an erroneous application program and to protect application programs from each other and (to some extent) from themselves.

One additional advantage of virtual memory is that it allows a computer to multiplex its CPU and memory between multiple programs without the need to perform expensive copying of the programs' memory images. If the combination of virtual memory system and operating system supports swapping, then the computer may be able to run simultaneous programs whose total size exceeds the available physical memory. Since most programs have a small subset (active set) of pages that they reference over significant periods of their execution, the performance penalty is less than that which might be expected. If too many programs are run at once, or if a single program continuously accesses widely scattered memory locations, then page swapping becomes excessively frequent and overall system performance will become unacceptably slow. This is often called thrashing (since the disk is being excessively overworked - thrashed) or paging storm, which corresponds to accessing the swap medium being three orders of magnitude slower compared to main memory access.

Note that virtual memory is not a requirement for precompilation of software, even if the software is to be executed on a multiprogramming system. Precompiled software loaded by the operating system has the opportunity to carry out address relocation at load time. This suffers by comparison with virtual memory in that a copy of program relocated at load time cannot run at a distinct address once it has started execution.

It is possible to avoid the overhead of address relocation using a process called rebasingRebasing is the process of creating a shared library image in such a way that it is guaranteed to use virtual memory without conflicting with any other shared libraries loadable in the system. This technique is used extensively on Win32 platforms to avoid, which uses metadata in the executable image header to guarantee to the run-time loader that the image will only run within a certain virtual address space. This technique is used on the system libraries on Win32 platforms, for example.

In embedded systemAn embedded system is a special-purpose computer system usually built into a smaller device. An embedded system is required to meet very different requirements than a general-purpose personal computer. Examples of embedded systems automatic teller machines, swapping is typically not supported—virtual memory is primarily a convenience to cope with software errors.



Read more »

Non User