Deep understanding of the Linux kernel-memory addressing

Source: Internet
Author: User

1. How to convert a logical address to a linear address:

Logical address = segment Selector (16bit) + offset (32bit)

The segment selector is made up of three parts: index (index number), T1 (table indicator), RPL (Request privilege level requester privilege)

Index number: Refers to the segment descriptor in the GDT (Global descriptor table) or the LDT (Local descriptor table).

Table indicator: Marks point to GDT or LDT

RPL: Divided into User State (3), or kernel state (0)

Segment Descriptor: 64bit, primary field Base (linear address 32bit of the first byte of the segment), Limit (length of segment), DPL (description privilege level), etc.

Address of Segment descriptor = GDT (LDT) address (stored in GDTR, LDTR Register) + Index * 8 (because of a segment descriptor of 8 bytes)

Logical address = base + offset in segment descriptor

Note: 1, rarely use fragmentation in Linux, it is biased to whether paging
2. The main 4 segments are user code segment, user data segment, kernel code snippet, kernel data segment, respectively.
3, and their base value is 0, that is, all the linear address to the segment starting from 0
4, that is, the low cost of the logical address of Linux and the corresponding linear address of the value is always consistent

2. How to convert a linear address to a physical address?

Page: 4,096 bytes, including in-page addresses, data

Page box: physical page, 4096 bytes, without in-page data

Paging: For efficiency, the linear address is divided into fixed-length pages, the continuous linear address of the page is mapped to a contiguous physical address, and the advantage is that the kernel can specify access rights to the page without having to specify all the linear addresses in the page

Linear address = Directory (directory 10bit) + table (page table 10bit) + offset (offset 12bit)

The offset of the offset:12bit is the size of a page, indicating that 4,096 consecutive linear addresses are one page

Extended Paging: Page catalog (10bit) + offset (offset 22bit); The middle page table is removed, and the size of each page is 4MB



Deep understanding of the Linux kernel-memory addressing

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.