Linux memory addressing

  

Q1. What is a physical address? What is a virtual address? What is a linear address?

A:

1) Define the memory space provided by the physical memory module on the motherboard as the physical memory space, where the actual address of each memory unit is the physical address;

2) Define the memory space seen by the application programmer as a virtual address space (or address space), where the address is called a virtual address (or virtual address), generally in the form of <;segment: offset” To describe, such as A815: CF2D;

3) Linear address space refers to a continuous, non-segmented address space ranging from 0 to 4 GB, a linear address is an absolute address of the linear address space .


Q2. How does the MMU convert a virtual address to a physical address in protected mode?

A: In protected mode, the memory management unit (MMU) consists of one or a group of chips. Its function is that the virtual address is mapped to a physical address, that is, address translation; the MMU is a hardware circuit. It consists of two parts, a segmentation component and a paging component, called the segmentation mechanism and the paging mechanism. The segmentation mechanism converts a virtual address into a linear address. The paging mechanism converts a linear address into a physical address.


Q3. Why use a two-level page table for a 32-bit linear address space?

A: A page table is a data structure that maps a linear address to a physical address. A 4 GB linear space can be divided into 1 M 4 KB pages, and each page table entry takes 4 bytes. The page table of 1M page table items needs to occupy 4MB space, and the requirement is continuous, so the two-level page table is used to implement; the two-level page table is to page the page table again, and the first level is called the page directory. It stores information about the page table; the 4MB page table is paged again and can be divided into 1K pages of 4KB size.


Q4. What is the role of the page cache? Why does Linux mainly use paging mechanism to implement virtual storage management? Why does it use a three-level paging mode instead of two levels?

A:

1) The page cache automatically retains the 32-page page entries recently used by the processor, so it can cover 128KB of memory;

2) Linux mainly The paging mechanism is used to implement virtual memory management for the following reasons:

A. The Linux segmentation mechanism makes all processes use the same segment registers, which makes memory management simple;

B. One of the design goals of Linux is to be able to be ported to most popular processing platforms, but many RISC processors support very limited segmentation; to ensure portability, Linux uses a three-level paging mode because many The processors all use a 64-bit structure; Linux defines three types of page tables: page directory (PGD), intermediate directory (PMD), and page table (PT).

Copyright © Windows knowledge All Rights Reserved