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

我们两清 提交于 2019-11-30 02:31:55
Zimbabao

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.

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