Does Linux use self-map for page directory and page tables?

こ雲淡風輕ζ 提交于 2019-11-30 12:22:50

问题


I'm just asking this question because I'm curious how the Linux kernel works. According to http://i-web.i.u-tokyo.ac.jp/edu/training/ss/lecture/new-documents/Lectures/02-VirtualMemory/VirtualMemory.ppt Windows uses special entries in its page directory and page tables named self-map in order to be able to manipulate page directory/tables content from kernel virtual address space. If anyone is familiar with Linux memory management, please tell me if Linux kernel handle this problem in a similar or different way. Thanks.


回答1:


Yes, in Linux also page tables are mapped to address space. But paging data structures in some of the architectures may use physical addresses. So it not fixed in Linux. But you can access the table easily.

Here is the kernel code to access page table

struct mm_struct *mm = current->mm;
pgd = pgd_offset(mm, address);
pmd = pmd_offset(pgd, address);
pte = *pte_offset_map(pmd, address);

To understand more about linux memory management see this

Cr3 register on IA32 stores the page table base pointer (pgd pointer), which stores physical address. This is true even for Windows (as it is a feature of the x86 processor, not of the OS).

Read this article to understand IA32 paging.

Edit2: Task struct contains a mm_struct instance related to Memory management of that task (so a process), this mm_struct have a pgd_t * pgd. load_cr3 loads a physical address of page directory table in cr3 register but it takes virtual address of pgt. So mm_struct contains virtual address of pgt.

Since page tables are in kernel space and kernel virtual memory is mapped directly to ram its just easy macro.



来源:https://stackoverflow.com/questions/5272408/does-linux-use-self-map-for-page-directory-and-page-tables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!