Concept of memory management unit, virtual address, memory mapping

Source: Internet
Author: User

First, the MMU

The MMU is the abbreviation of the Memory management unit and is the device used to manage the virtual memory system. The MMU is usually a part of the CPU, and itself has a small amount of storage space from the virtual address to the physical address of the matching table. This table is called the TLB (conversion side buffer). All data requests are sent to the MMU, and the MMU determines whether the data is in RAM or in a mass storage device. If the data is not in storage space, the MMU will cause a page fault interruption.

The two main functions of the MMU are:

1. Convert the virtual address into a physical address.

2. Control memory access allowed. When the MMU shuts down, the virtual address is output directly to the physical address bus.

Second, virtual address

At any time, there is a collection of addresses on the computer that a program can produce, which we call the address range. The size of this range is determined by the number of bits of the CPU, for example: A 32-bit CPU whose address range is 0~0xffffffff (4GB), and for a 64-bit CPU, its address range is 0~0xffffffffffffffff. This range is the range of addresses that the program can generate, which is called the virtual address space, where an address is called a virtual address.

Third, address mapping

Most systems that use virtual storage are using a technique called paging. The virtual address space is divided into units called pages (page), and the corresponding physical address space is partitioned, in the form of a page box (frame). The page and page boxes must be the same size.

The size of a physical page is 4KB, and the information theCPU uses to convert the virtual address into a physical address is stored in a structure called a page directory and a page table. Each item in the page table describes the conversion between parts of the memory mapped to the physical address, and the page table is organized by virtual address, in addition to the transformation that describes the virtual page to the physical page, which also provides access to the page and storage properties.

Page table (also called the page directory), a page table size of 4K bytes , placed in a physical page. Consists of 1024 4-byte page table entries. The size of the page table entry is 4 bytes (32bit), so there are 1024 page table entries in a page table. The contents of each item in the page table (4 bytes per item, 32bit) high 20bit is used to place the physical address of a physical page, and low 12bit puts some flags.

The process of translating a logical address in a user program into a physical address that is directly addressed by the machine at run time is called address mapping.

The CPU translates the virtual address into a physical address:

A virtual address, a size of 4 bytes (32bit), contains information about the physical address found, divided into 3 parts:

22nd to 31st this 10-bit (up to 10-bit) is the index in the page directory.

12th to 21st these 10 bits are the indexes in the page table.

No. 0 to 11th this 12-bit (low 12-bit) is the in-page offset.

For a virtual address to be converted to a physical address:

The CPU first finds the physical page where the page directory resides, based on the values in CR3.

Then, based on the 22nd to 31st bits of the virtual address, the 10-bit (highest 10bit) value is indexed, the corresponding page directory entry (pde,page directory entry) is found, and the page directory entry has the physical address of the page table that corresponds to the virtual address.

With the physical address of the page table, based on the 10-bit value of the 12th to 21st bit of the virtual address as the index, the corresponding page table entry (pte,page table entry) in the page table is found, and the page table entry has the physical address of the physical page corresponding to the virtual address.

Finally, the minimum 12 bits of the virtual address, that is, the page offset, plus the physical address of the physical page, the virtual address of the corresponding physical address.

Address Map Classification

Address mapping can also become an address relocation or address transformation, which can be divided into the following two classes:

Static relocation When the user program is loaded into memory, the conversion of the logical address to the physical address is implemented once, and it is not converted (usually done by the software when loading the memory). Dynamic relocation When the program is running to access the data and then the address transformation (that is, when the execution of each instruction to complete the address map.) In general, to improve efficiency, this work is done by the hardware address mapping mechanism. Hardware support, software hardware combined to complete. A pair of register support is generally required on the hardware).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.