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

后端 未结 1 1466

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-V

1条回答
  •  天命终不由人
    2020-12-28 11:53

    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.

    0 讨论(0)
提交回复
热议问题