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

查看:23
本文介绍了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 内核是否以类似或不同的方式处理这个问题.谢谢.

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.

推荐答案

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

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 the page table

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

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

To understand more about Linux memory management see this

IA32 上的 Cr3 寄存器存放页表基指针(pgd 指针),存放物理地址.这是即使对于 Windows 也是如此(因为它是 x86 处理器的一个特性,而不是操作系统).

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).

阅读这篇文章以了解 IA32 分页.

Read this article to understand IA32 paging.

任务结构包含一个mm_struct 与内存管理相关的实例任务(所以是一个过程),这个 mm_struct 有一个 pgd_t * pgd.load_cr3 加载cr3 寄存器中页目录表的物理地址,但它采用 pgt 的虚拟地址.所以mm_struct包含了pgt的虚拟地址.

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

由于页表在内核空间中,并且内核虚拟内存直接映射到 ram,所以它只是一个简单的宏.

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

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

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