简体   繁体   English

Linux如何在x86-64中支持超过512GB的虚拟地址范围?

[英]How does Linux support more than 512GB of virtual address range in x86-64?

The user virtual address space for x86-64 with Linux is 47 bit long. Linux的x86-64用户虚拟地址空间为47位。 Which essentially means that Linux can map a process with around ~128 TB virtual address range. 这实际上意味着Linux可以映射具有大约~128 TB虚拟地址范围的进程。

However, what confuses me that x86-64 architecture supports ISA defined 4-level hierarchical page table (arranged as radix-tree) for each process. 然而,让我感到困惑的是x86-64架构支持每个进程的ISA定义的4级分层页表(排列为基数树)。 The root of the page table can only map up to 512 GB of contiguous virtual address space. 页表的根目录最多只能映射512 GB的连续虚拟地址空间。 So how Linux can support more than 512GB of virtual address range? 那么Linux如何支持512GB以上的虚拟地址范围呢? Does it uses multiple page tables for each process? 它是否为每个进程使用多个页表? If yes, then for a process what should the CR3 (x86-64's register to contain the address of the base of the page table) contain for any given process? 如果是,那么对于一个进程,CR3(x86-64的寄存器包含页表基址的地址)应包含哪个给定进程? Am I missing something? 我错过了什么吗?

The root of the page table can only map up to 512 GB of contiguous virtual address space. 页表的根目录最多只能映射512 GB的连续虚拟地址空间。 So how Linux can support more than 512GB of virtual address range? 那么Linux如何支持512GB以上的虚拟地址范围呢? Does it uses multiple page tables for each process? 它是否为每个进程使用多个页表? If yes, then for a process what should the CR3 (x86-64's register to contain the address of the base of the page table) contain for any given process? 如果是,那么对于一个进程,CR3(x86-64的寄存器包含页表基址的地址)应包含哪个给定进程? Am I missing something? 我错过了什么吗?

I don't know what do you mean by "root of the page table", but paging on x86-64 looks like this: 我不知道“页面表的根目录”是什么意思,但x86-64上的分页看起来像这样:

  • Page tables - the lowest level of paging structures. 页表 - 分页结构的最低级别。 Each has 512 8-byte entries (PTE) describing one 4 KiB page, so PT describes 512 * 4 KiB = 2 MiB of memory (it can also work as 2 MiB page, but let's leave it for now). 每个都有512个8字节条目(PTE)描述一个4 KiB页面,因此PT描述512 * 4 KiB = 2 MiB的内存(它也可以作为2 MiB页面使用,但现在让我们离开它)。
  • Page directories - table, similar to PT, containing 512 8-byte entries (PDE) pointing to PTs; 页面目录 - 表,类似于PT,包含指向PT的512个8字节条目(PDE); so, PD describes 512 * 2 MiB = 1 GiB of memory (it can also work as 1 GiB page, similary to PT). 因此,PD描述512 * 2 MiB = 1 GiB的内存(它也可以作为1 GiB页面,类似于PT)。
  • Page directory page table - similar to PD, but contains 512 8-byte entries (PDPTE) pointing to PDs; 页目录页表 - 类似于PD,但包含指向PD的512个8字节条目(PDPTE); so, PDPTE describes 512 * 1 Gib = 512 GiB of memory. 所以,PDPTE描述了512 * 1 Gib = 512 GiB的内存。
  • PML4, the highest level of paging structures, is table containing 512 8-byte entries (PML4E) pointing to PDPTs; PML4是最高级别的分页结构,是包含512个8字节条目(PML4E)的表,指向PDPT; so, PML4 describes 512 * 512 GiB = 256 TiB of memory. 所以,PML4描述了512 * 512 GiB = 256 TiB的内存。

I don't know exact memory map of Linux, but probably the higher half (from -128 TiB to 0 - from 0xFFFF800000000000 to 0xFFFFFFFFFFFFFFFF ) is reserved for kernel, lower half (from 0 to 128 TiB - from 0x0000000000000000 to 0x00007FFFFFFFFFFF ) is for userspace applications. 我不知道Linux的确切内存映射,但可能更高的一半(从-128 TiB到0 - 从0xFFFF8000000000000xFFFFFFFFFFFFFFFF )保留给内核,下半部分(从0到128 TiB - 从0x00000000000000000x00007FFFFFFFFFFF )是用户空间应用程序 So, Linux supports 512 times the 512 GiB of virtual address range you are asking; 因此,Linux支持512倍于您要求的512 GiB虚拟地址范围; even Torvalds wouldn't say "we won't support PML4". 甚至托瓦兹也不会说“我们不会支持PML4”。 I don't know what confuses you - is it the fact you missed the part saying that page table maps 2 MiB and you've taken it as it maps one page - 4 KiB - but if there is anything I could clarify, ask about it. 我不知道是什么让你感到困惑 - 是你错过了这个部分,说页面表映射2 MiB并且你已经把它当作一个页面映射 - 4 KiB - 但是如果有什么我可以澄清,请询问它。

Typically process address spaces aren't shared, which means, the involved page tables aren't shared between distinct processes either. 通常,不共享进程地址空间,这意味着所涉及的页表也不在不同进程之间共享。 And that means at all 4 table levels. 这意味着在所有4个表级别。

Of course, the common (kernel) part is always present in all address spaces, so, in fact, there's some sharing, but the memory there is only accessible to the kernel itself. 当然,公共(内核)部分总是存在于所有地址空间中,因此,事实上,存在一些共享,但内存只能由内核访问。

Other than that, indeed, every process has its own page tables pretty much and there isn't any problem with using all 2 48 addresses in any one of them. 实际上,除此之外,每个进程都有自己的页表,并且在任何一个进程中使用所有2 48个地址都没有任何问题。 At least, there's no special limitation on the part of the CPU, although there can be on the part of the OS. 至少,CPU的部分没有特别的限制,尽管操作系统可以有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM