Linux是否对页面目录和页面表使用自映射? [英] Does Linux use self-map for page directory and page tables?

查看:115
本文介绍了Linux是否对页面目录和页面表使用自映射?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是问这个问题,因为我很好奇Linux内核的工作方式.根据 http://i-web.iu-tokyo.ac.jp/edu/training/ss/lecture/new-documents/Lectures/02-VirtualMemory/VirtualMemory.ppt Windows在其页面目录中使用特殊条目和名为self-map的页表,以便能够从内核虚拟地址空间中处理页目录/表的内容.如果有人熟悉Linux内存管理,请告诉我Linux内核是否以类似或不同的方式处理此问题.谢谢.

解决方案

是的,在Linux中,页表也映射到了地址空间.但是某些体系结构中的分页数据结构可能会使用物理地址.因此,它在Linux中未修复.但是您可以轻松访问该表.

这是访问页表的内核代码

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

要了解有关linux内存管理的更多信息,请参阅此

IA32上的

Cr3寄存器存储页表基本指针(pgd指针),该指针存储物理地址.即使对于Windows,这也是 true (因为它是x86处理器的功能,而不是x86处理器的功能操作系统).

阅读本文以了解IA32分页. /p>

Edit2: 任务结构包含 mm_struct 与该任务的内存管理相关的实例(这样的过程),此mm_struct具有一个pgd_t * pgd. load_cr3 加载一个cr3寄存器中页面目录表的物理地址,但它使用pgt的虚拟地址.因此,mm_struct包含pgt的虚拟地址.

因为页表位于内核空间中,并且内核虚拟内存直接映射到ram的简单宏.

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.

解决方案

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.

这篇关于Linux是否对页面目录和页面表使用自映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆