| Memory Management Unit |
Article Index for Memory |
Website Links For Memory Management |
Information AboutMemory Management Unit |
| CATEGORIES ABOUT MEMORY MANAGEMENT UNIT | |
| virtual memory | |
|
Modern MMUs typically divide the virtual Address Space (the range of addresses used by the processor) into Pages , whose size is 2N, usually a few Kilobyte s. The bottom ''n'' bits of the address (the offset within a page) are left unchanged. The upper address bits are the (virtual) page number. The MMU normally translates virtual page numbers to physical page numbers via an associative cache called a Translation Lookaside Buffer (TLB). When the TLB lacks a translation, a slower mechanism involving hardware-specific data structures or software assistance will be used. The data items found in such data structures are typically called ''page table entries'' (PTEs), and the data structure itself is typically called a '' Page Table ''. The physical page number is combined with the page offset to give the complete physical address. A PTE or TLB entry may also include information about whether the page has been written to (the ''dirty bit''), when it was last used (the ''accessed bit'', for a Least Recently Used Page Replacement Algorithm ), what kind of processes ( User Mode , Supervisor Mode ) may read and write it, and whether it should be Cache d. It is possible that TLB entry or PTE prohibits access to a virtual page, perhaps because no physical memory ( RAM ) has been allocated to that virtual page. In this case the MMU will signal a Page Fault to the CPU. The Operating System will then handle the situation appropriately, perhaps by trying to find a spare page of RAM and set up a new PTE to map it to the requested virtual address. If no RAM is free it may be necessary to choose an existing page, using some replacement algorithm, and save it to disk (this is known as " Paging "). With some MMUs there can also be a shortage of PTEs or TLB entries, in which case the OS will have to free one for the new mapping. In some cases a "page fault" may indicate a software bug. A key benefit of an MMU is can use it to protect against errant programs, by disallowing access to memory that a particular program should not have access to. Typically, an operating system assigns each program its own virtual address space. An MMU also reduces the problem of Fragmentation of memory. After blocks of memory have been allocated and freed, the free memory may become fragmented (discontinuous) so that the largest contiguous block of free memory may be much smaller than the total amount. With virtual memory, a contiguous range of virtual addresses can be mapped to several non-contiguous blocks of physical memory. In early designs memory management was performed by a separate Integrated Circuit such as the MC 68851 used with the Motorola 68020 CPU in the Macintosh II or the Z8015 used with the Zilog Z80 family of processors. Later CPUs such as the Motorola 68030 and the ZILOG Z280 have MMUs on the same IC as the CPU. While this article concentrates on modern MMUs, which almost invariably use Paging , other systems like Segmentation and Base-limit Addressing (of which the former is a development) have been used in MMU and are occasionally still present on modern architectures; perhaps most notably, the X86 ISA provides for segmentation in addition to paging. EXAMPLES Most modern systems divide memory into pages that are 4 KiB to 64 KiB in size, often with the possibility to use huge pages from 2 MiB to 512 MiB in size. Page translations are cached in a TLB . Some systems, mainly older RISC designs, trap into the OS when a page translation is not found in the TLB. Most systems use a hardware-based tree walker. Most systems allow the MMU to be disabled; many will disable the MMU when trapping into OS code. ; (here called PALcode ) walks a 3-level tree-structured page table. Addresses are broken down as follows: 21 bits unused, 10 bits to index the root level of the tree, 10 bits to index the middle level of the tree, 10 bits to index the leaf level of the tree, and 13 bits that pass through to the physical address without modification. Full read/write/execute permission bits are supported. ;. After a TLB miss, the standard PowerPC MMU begins two simultaneous lookups. One lookup attempts to match the address with one of 4 or 8 data BAT registers, or 4 or 8 code BAT registers as appropriate. The BAT registers can map linear chunks of memory as large as 256 MiB , and are normally used by an OS to map large portions of the address space for the OS kernel's own use. If the BAT lookup succeeds, the other lookup will be halted and ignored. The other lookup, not directly supported by all processors in this family, is via a so-called " Inverted Page Table " which acts as a hashed off-chip extension of the TLB. First, the top 4 bits of the address are used to select one of 16 segment registers. 24 bits from the segment register replace those 4 bits, producing a 52-bit address. The use of Segment Register s allows multiple processes to share the same hash table. The 52-bit address is hashed, then used as an index into the off-chip table. There, a group of 8 page table entries will be scanned for one that matches. If none match due to excessive Hash Collision s, the processor will try again with a slightly different Hash Function . If this too fails, the CPU will trap into the OS (with MMU disabled) so that the problem may be resolved. The OS will need to discard an entry from the hash table to make room for a new entry. The OS may generate the new entry from a more-normal tree-like page table or from per-mapping data structures which are likely to be slower and more space-efficient. Support for No-execute control is in the segment registers, leading to 256-MiB granularity. One of the major problems with this design is poor Cache Locality caused by the hash function. Tree-based designs avoid this problem by placing the page table entries for adjacent pages in adjacent locations. An operating system running on the PowerPC may minimize the size of the hash table to reduce this problem. It is also somewhat slow to remove the page table entries of a process; the OS may avoid reusing segment values to delay facing this or it may elect to suffer the waste of memory associated with per-process hash tables. G1 chips do not search for page table entries, but they do generate the hash with the expectation that an OS will search the standard hash table via software. (the OS can write to the TLB) G2, G3, and early G4 chips use hardware to search the hash table. The latest chips allow the OS to choose either method. On chips that make this optional or do not support it at all, the OS may choose to use a tree-based page table exclusively. ;. OSes which implement paging must find some way to emulate the accessed bit if they are to operate efficiently. Typically, the OS will periodically unmap pages so that page-not-present faults can be used to let the OS set an accessed bit. ; support is only provided on a per-segment basis, making it very awkward to use. PaX is one way to emulate per-page non-execute support via the segments, with minor performance loss and the loss of half of the available address space. Minor revisions of the MMU introduced with the Pentium have allowed huge 2 MiB or 4 MiB pages by skipping the bottom level of the tree. Minor revisions of the MMU introduced with the Pentium Pro have allowed 36-bit physical addresses and specification of cachability by looking up a few high bits in a small on-CPU table. ; to fill the high 16 bits. A per-page No-execute bit, called the NX bit, can be used to block execution of individual pages. ; easier. They also reduce overhead for the OS, which would otherwise need to propagate accessed and dirty bits from the page tables to a more physically-oriented data structure. |
|
|