32 位系统上 4GB 限制背后的数学计算 [英] Math behind 4GB limit on 32 bit systems

查看:31
本文介绍了32 位系统上 4GB 限制背后的数学计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于 32 位内存地址的非常基本的问题.我的理解是 2^32 是 32 位系统上可能的内存地址的最大数量.我感到困惑的是我们如何从这个数字到所谓的 4GB 限制.在我的研究中,我看到了一些人这样做:

I have a very fundamental question relating to 32 bit memory addresses. My understanding is that 2^32 is the maximum number of possible memory addresses on a 32 bit system. Where I am confused is how we go from this number to the alleged 4GB limit. In my research I have seen some people do this:

2^32 = 4,294,967,296 字节

2^32 = 4,294,967,296 bytes

4,294,967,296/(1,024 * 1,024) = ~4 GB

4,294,967,296 / (1,024 * 1,024) = ~4 GB

首先,这个 (1,024 * 1,024) 来自哪里?

First, where does this (1,024 * 1,024) come from?

其次,如果我错了,请纠正我,但是 4,294,967,296 被标记为字节,因为字节是可以在 RAM 中寻址的最小存储空间单位.由于我们仅限于 2^32 个地址,这就是可以寻址的字节数.

Second, correct me if I am wrong, but 4,294,967,296 is labeled as bytes because a byte is the smallest unit of storage space that can be addressed in RAM. Since we're limited to 2^32 addresses, that's the number of bytes that can be addressed.

第三,即使 RAM 中最小的可寻址空间是一个字节,但对于硬盘驱动器来说一定不是这种情况,因为 32 位系统通常有超过 4 GB 的硬盘.有人能简单描述一下硬盘的寻址方案吗?

Third, even though the smallest addressable space in RAM is a byte, this must not be the case with the hard-drive because 32 bit systems usually have hard disk's well in excess of 4 GB. Can someone briefly describe the addressing scheme for hard disks?

推荐答案

这是基本算术的一个例子:每个寻址单元的字节数乘以可寻址单元的数量等于可寻址字节的数量.

This is a case of basic arithmetics: Number of bytes per addressed unit times number of addressable units equals number of addressable bytes.

困难的部分是,从哪里获得这些数字.这是我的看法:

The hard part is, where to get those numbers from. Here is my take on it:

1 - 什么是千字节、兆字节、千兆字节?

1 - What is a Kilobyte, Megabyte, Gigabyte?

  • 对于 RAM,已同意 Gigabyte 为 1024 MB,每个由 1024 KB 组成,每个为 1024 字节.这源于这样一个事实,即 1024 是 2^10,但足够接近 1000,历史上允许使用 Kilo 前缀
  • 对于存储,供应商几年前就开始使用严格的十进制单位,一兆字节为 1000000 字节(因为它使容量在光面小册子中看起来更大)

这导致 1024*1024 字节被称为 MiB,1000*1000 字节被称为 MB

This has led to 1024*1024 Bytes being called a MiB and 1000*1000 Bytes being called a MB

2 - 可寻址单元

  • 对于 RAM,可寻址单位是字节,即使它是以至少 4 个块的形式从物理 RAM 中获取的.
  • 对于大容量存储,可寻址单位是扇区或块,通常为 512 字节,但 4096 字节很快.

3 - 可寻址单元的数量要复杂得多,让我们从 RAM 开始:

3 - The number of addressable units is much more complicated, let's start with RAM:

  • 32 位 CPU(sans MMU!)可以寻址 2^32 字节或 4 GiB
  • 所有现代 32 位 CPU 都包含一个 MMU,可将这 4 GiB 的虚拟地址空间映射到物理地址空间
  • 此物理地址空间的大小可以与 4 GiB 不同,这取决于 MMU 使用的物理地址线多于(或在史前时代少于)32 条物理地址线.当今最常见的实现是 36 个或更多物理位,从而产生 16*4 GiB 或更多(PAE 或物理地址扩展)
  • 这个 MMU 魔法不能在 32 位模式下运行的 CPU 周围工作,即对于每个进程,地址空间不能大于 4 GiB
  • 为了让事情变得更有趣,这个地址空间的一部分用于我所知道的每个现代操作系统的内核功能.这导致所有主流操作系统的每个进程有 2 GiB 或 3 GiB 的最大可用地址空间.
  • 因为这仍然太简单了:操作系统必须支持在一种模式下运行 MMU,在这种模式下它实际上可以使用超过 4 GiB 的物理 RAM.一个显着的例子是 Windows XP 32 位,它不允许这样做.
  • 最后但并非最不重要的一点:物理地址空间的一部分最常用于内存映射硬件.如果这与上述操作系统限制相结合,则会导致 Windows XP 32 位有时只能使用 2.5 到 3.5 GiB 的物理 RAM
  • A 32 Bit CPU (sans the MMU!) can address 2^32 Bytes or 4 GiB
  • All modern 32 Bit CPUs include a MMU, that maps these 4 GiB of virtual address space into a physical address space
  • This physical address space can have a different size than 4 GiB, as a function of the MMU using more (or in prehistoric times less) than 32 physical address lines. Today's most common implementation are 36 or more physical Bits, resulting in 16*4 GiB or more (PAE or physical adress extension)
  • This MMU magic does not work around the CPU running in 32 Bit mode, i.e. for every process, the address space can't be larger than 4 GiB
  • To make things a little more interesting, a part of this address space is used for kernel functionality in every modern OS I know of. This results in 2 GiB or 3 GiB maximum usable address space per process for all mainstream OSes.
  • And as this still is much too simple: Running the MMU in a mode, where it can actually use more than 4 GiB of physical RAM must be supported by the OS. A remarkable example is Windows XP 32 Bit, which does NOT allow that.
  • And last but not least: A part of the physical address space is most often used for memory-mapping hardware. If this is combined with OS limits as above, it results in Windows XP 32 Bit sometimes being able to use only 2.5 to 3.5 GiB of physical RAM

存储的麻烦要少得多:

  • 在我所知道的所有基于 PC 的现代案例中,可寻址单元只是用 32 位或 48 位(LBA 或逻辑块寻址)计数.即使在最基本的版本中,这也足以每个磁盘的 2 TiB 存储空间(2^32 个块,每个块 512 字节).具有 48 位 LBA 和每块 4 KiB 的最大版本导致大约.每个磁盘 10 亿 TiB.
  • in all modern PC-based Cases I know of, the addressable units are simply counted with 32 or 48 Bits (LBA or logical block addressing). Even in it's most basic version this is enough for 2 TiB of storage per disk (2^32 blocks of 512 Bytes each). Maxed-out versions with 48 Bit LBA and 4 KiB per block result in ca. a Gazillion TiB per disk.

这篇关于32 位系统上 4GB 限制背后的数学计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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