1. Address types processed by Linux
1. User Virtual Address:
This is the user spaceProgramCommon address. Each process has its own virtual address space.
2. physical address
The physical address is used between the processor and the system memory.
3. Bus address
The bus address is used in the peripheral bus and memory.
4. kernel logic address
The Logical Address of the kernel constitutes the regular address space of the kernel. It maps some or all of the system memory one-to-one.
In most architectures, the logic address of the kernel is different from the physical address, only because there is a fixed offset between them.
What kmalloc allocates is the logical address __get_free_pages?
5. kernel virtual address.
It differs from the kernel logic address in that the kernel virtual address does not correspond to the physical address one by one.
The kernel virtual address space is continuous, but the physical address mapped to it can be discrete. The logic address of the kernel is continuous, and the physical address mapped by other operations is also continuous.
Vmalloc. kmap returns the virtual address of the kernel.
All kernel logical addresses are kernel virtual addresses, but not all kernel virtual addresses are kernel logical addresses.
2. Page
Physical addresses are divided into discrete units. Each unit is called a page. Page size, expressed by the macro page_size
3. page_shift: page frame number
The kernel address, whether virtual or physical, consists of two parts. Generally, N-bit is the page number, and m-bit is the offset in the page.
When we discard the low m offset in the address, we move the n-bit page number to the right. The result is called the page frame number.
It is a common operation to move a bit to convert between the number of page frames and the address. The macro page_shift tells us how many places to shift right to get the page frame number.