为什么 32 位处理器只能寻址 4GiB 内存,即使是大字长?

Why 32-bit processor can only address 4GiB of memory, even with large word size?

直到现在我都认为 32 位处理器可以使用 4 GiB 内存,因为 232 是 4 GiB,但这种方法意味着处理器有 word大小 = 1 字节。因此,具有 32 位程序计数器的进程可以寻址 232 个不同的内存字,因此我们有 4 GiB。

但是如果处理器的字长大于 1 个字节,我相信现在大多数处理器都是这种情况(我的理解是那个字size 等于数据总线的宽度,所以 64 位数据总线的处理器必须有一个 word size = 8 bytes).

现在具有 32 位程序计数器的同一处理器可以寻址 2^32 个不同的内存字,但在这种情况下 字大小为 8 个字节 因此它可以寻址更多的内存,这与4 GiB 的东西,所以我的论点有什么问题?

CPU(至少 x86 系列 32 位)必须能够访问 4GB space 中的 any byte/word/dword。因此,一条指令的编码方式是目标字大小和内存地址(通常)属于不同的位域。所以CPU访问的是byte还是dword都无所谓,但是编码后的内存地址一定要一样。

请注意,32 位 OS 和 x86 CPU 在技术上能够使用 PAE 模式访问超过 4GB 地址 space。但它不受当前 Windows OS 系列(服务器版本除外)的支持。某些版本的 WinXP,以及 Linux 和其他 32 位 OS 可以在 x86 CPU.

上寻址 64GB 内存

此外,通常 OS 保留虚拟地址的一部分 space(用于 OS 内核、显存等),因此用户程序可以使用,比如说,不超过每个进程中 4GB 的 3 GB RAM OS 可以寻址。

你的前提不正确。 32 位架构可以寻址超过 4GB 的内存,就像 most (if not all) 8-bit microcontrollers can use more than 256 bytes of memory. Indeed a 32-bit program counter can address 232 different memory locations, but word-addressable memory is only used in architectures for very special purposes like DSPs or antique architectures in the past 一样。通用计算的现代架构都使用字节寻址内存

Why byte-addressable memory and not 4-byte-addressable memory?


即使在 32 位字节可寻址架构中,也有许多方法可以访问超过 4GB 的内存。例如,64 位 JVM 可以使用 compressed Oops. See the Trick behind JVM's compressed Oops

使用 32 位指针寻址 32GB 内存

32 位 x86 CPU 也可以使用 PAE. It basically adds a another level of indirection in the TLB with a few more bits in the address. That allows the whole system to access more than 4GB of memory. However the pointers in applications are still 32-bit long so each process is still limited to 4GB at most. The analog on ARM is LPAE.

寻址 64GB(或更高版本)的内存

每个进程的4GB地址space经常被分割成用户和内核space(before Meltdown),因此更加限制了用户内存。有几种方法可以解决这个问题

  • 产生多个进程,在 Adob​​e Premiere CS4 中使用
  • 将需要的内存部分映射到当前地址 space,就像 Windows
  • 上的 Address Windowing Extensions
  • ...