How does ARM Linux emulate the dirty, accessed, and file bits of a PTE?
根据pgtable-2-level.h,ARM Linux有两个版本的PTE;另一个是PTE。 Linux PTE和H / W PTE。 Linux PTE存储在1024字节偏移量以下。
在
但是实际上,ARM H / W不支持其PTE中的脏位,访问位和文件位。
我的问题是,它如何检查H / W PTE上页面的脏的,可访问的文件位? 理想情况下,它应该检查Linux PTE上存储在1024字节偏移量以下的那些位?
My question is how does it check the dirty, accessed, file bit of a page on H/W PTE?
TL; DR-通过在初始访问时进行页面错误来模拟它们。
答案在pgtable-2-level.h中给出,
The"dirty" bit is emulated by only granting hardware write permission
iff the page is marked"writable" and"dirty" in the Linux PTE. This
means that a write to a clean page will cause a permission fault, and
the Linux MM layer will mark the page dirty via handle_pte_fault().
For the hardware to notice the permission change, the TLB entry must
be flushed, and ptep_set_access_flags() does that for us.
为了处理这种情况,将页面的初始MMU映射标记为只读。当进程向其写入内容时,将产生页面错误。这是引用的
1 2 3 4 5 6 | if (flags & FAULT_FLAG_WRITE) { if (!pte_write(entry)) return do_wp_page(mm, vma, address, pte, pmd, ptl, entry); entry = pte_mkdirty(entry); /** Here is the dirty emulation. **/ } |
因此,Linux通用代码将检查页面的权限,看它是否是可写的,并调用
所访问的是相同的,只是读写最初都会出错。文件位也完全未映射,并且在发生故障时,请咨询Linux PTE以查看它是否由文件支持,或者是完全未映射的页面错误。
使用新的权限更新硬件表并完成簿记后,用户模式程序将根据故障指令重新启动,除了处理故障的时间间隔外,它不会注意到差异。
ARM Linux使用4k页,而ARM第二级页表的大小为1k(256个条目* 4个字节)。从pgtable-2-level.h注释中,
Therefore, we tweak the implementation slightly - we tell Linux that we have 2048 entries in the first level, each of which is 8 bytes (iow, two hardware pointers to the second level.) The second level contains two hardware PTE tables arranged contiguously, preceded by Linux versions which contain the state information Linux needs. We, therefore, end up with 512 entries in the"PTE" level.
为了使用完整的4K页面,PTE条目的结构如下:
四个1k物品,完整的4k页面。必须对每个进程管理这些页面集合,以便为每个进程提供唯一的内存视图,并共享一些信息以节省实际RAM。函数
请参阅:Tim关于ARM MM的说明
Linux内核中用于ARM的页表条目(PTE)描述符