The difference between logical address/virtual address/Linear address in Linux kernel

Source: Internet
Author: User

This blog post self-informed answer: Linux linear address, logical address and virtual address of the relationship?

In order to prevent ambiguity, the following terms are used in English. Some of the terms are not explained, otherwise the answer will be too long.

The following is an example of a code snippet

Under the Intel platform, the logical address is selector:offset this form, selector is the value of the CS register, andoffset is the value of the EIP register . If you use selector to go to the GDT (global descriptor) to get segment base address (segment base) and then add offset (intra-segment offset), this gets the linear address. We call this process the segment memory management .

If the linear address is cut into four paragraphs, using the first three paragraphs as the index to the PGD, PMD, page table table, and eventually get a page table entries (page tables Entry), the value is a page of physical memory start address, add it The contents of the fourth paragraph after linear address segmentation (also called the offset within the page) are given the final physical address. We call this process .

> The question is, why didn't you mention virtual address, what is this? In fact, the term is not mentioned in the Intel IA-32 manual, but this concept is really used in the kernel, such as the two macro definitions of __va and __PA. Seemingly mysterious virtual address the essence of the program is the use of a pointer value, the essence of the pointer is the value of the EIP register, said straightforward point, virtual address is the value of the EIP register. You will find that we said above, logical address is composed of selector and offset, offset is also the value of the EIP register, so the conclusion is: Logical address offset is the virtual address , two of which is a thing.

Now that we understand the relationship between logical address and virtual address, let's look at what linear address and virtual address are. In the section memory management mentioned above, the Linux kernel will set the segment base address (segment base) to 0, so there is linear address = 0+offset, and because the virtual address is offset, so the calculated Linear address in equals to virtual address, note that the value is equal to the difference between the segment base , only the base of the paragraph is 0.

Many information on the Internet that the logical address is the alias of the virtual address, in fact, they are not a thing. There is a lot of data on the linear address as the alias of the virtual address, in fact, they are not a thing, but Linux under the x86 to make them equal, although the values are equal but essentially different .

---------------------------------I'm a split line-------------------------------------------

According to Intel's design, segment type memory management is divided into three types: code snippet (above), data segment, System segment (TSS, etc.), it is too troublesome. We can only rely on page-type memory management to complete all the functions required by the Linux kernel, no need for segment mapping, but the fragment mapping this thing is not off, it can only be a point of means. The Linux kernel then sets the segment base address to 0 for all types of segments, and the length of the segment is set to ( The specific numerical value does not expand to say, relates to the paragraph descriptor structure, is troublesome, here understands as address bus the maximum addressable limit to be possible) , then all the segments are coincident, that is, does not fragment, moreover because the segment limit length is the address bus address limit, therefore this also corresponds to all segments with the entire linear space coincident. The virtual address is originally an offset within the segment, and now the segment is the entire linear space, so the virtual address becomes the offset in the entire linear space, which is the same as the concept of a linear address, so the kernel developer has already treated the virtual address and the linear address as a thing. In order to avoid confusion in the book understand the Linux Kernel, except for the phrase  virtual address in the beginning and glossary, the linear address is all used elsewhere.

After reading this answer, you will find that we go around a circle, although the concept of logical address is clear, but the virtual address and linear address can still be distinguished, because the distinction is not useful, the kernel of these two concepts are universal. However, know the difference is not at some point to confuse themselves, especially some books and tutorials in the two words do not say why the mixed use, it is very painful. Well, the final conclusion is that the two concepts are clearly more distinct, but if you do not differentiate the virtual address directly as the alias of a linear address, you will not have any effect on understanding the kernel.


This article is from the "Linux Kernel Developer" blog, so be sure to keep this source http://mirage1993.blog.51cto.com/2709744/1921773

The difference between logical address/virtual address/Linear address in Linux kernel

Related Article

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.