简体   繁体   中英

Direct Mapping in Linux Kernel Virtual Memory

As noted in LDD the kernel virtual memory (top 1GB in IA-32 address space) is partitioned into kernel logical addresses and kernel virtual addresses. Kernel logical addresses are mapped directly which means that you can map virtual addresses to physical addresses by subtracting a certain (0xC0000000) value. For moving btwn mappings a pair of macros are defined: __pa() and __va() .

My questions are: "What are the usecases for these macros?" and: "What is the benefit of direct mapping?"

I have heared that direct mapping allows using larger pages (eg, 4MB) and consequently leads to more efficient translation. Are translations for the directly mapped region performed using page tables?

as we known, in 32 bit older days, 0 ~ 3 GB of the virtual memory address space is belonged to user space;3 GB ~ 4 GB of the virtual memory address space is belonged to kernel space;

in kernel, it usually allocated physical memory from Normal Zone which usually is under 1 GB;

for example, we allocate memory by kmalloc(100, GFP_KERNEL)

GFP_KERNEL means allocate physical memory from Zone Normal;

by that, Kernel can easily add 0xC000000(aka, 3 GB offset) to physical memory address(0 ~ 1 GB), then the physical memory address is directly mapped to kernel virtual memory address(3 ~ 4 GB);

by this way, kernel can access underneath physical memory more quickly which just subtract by 0xC0000000; (the memory access is by virtual address, need map virtual address to physical address)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM