Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Math behind 4GB limit on 32 bit systems

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 bytes

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

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

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.

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?

like image 694
cadsharp Avatar asked May 31 '13 04:05

cadsharp


People also ask

Why is 4GB limited 32-bit?

4 GB is the theoretical maximum of memory you can use with a 32-bit OS. Practically you cannot use the full 4GB memory (maybe only 3,5 GB) because you also need some adress-space for other hardware components like: CPU, HDD, grafic card, etc.

Is there any hack to access more than 4GB in 32-bit system?

Most modern 32 bit processors have sufficient address lines to address 64GB of RAM. Blocks of 4K bytes are mapped to a process's address space as needed. It is PAE that allows access to more than 4GB of RAM. It is not a hack as often claimed but is quite efficient.

Can you use 4GB of RAM with a 32Bit operating system?

A 32Bit operation system supports up to 4GB of memory, however not all of it may be available for use by applications.

How much RAM can 32-bit programs use?

The 2 GB limit refers to a physical memory barrier for a process running on a 32-bit operating system, which can only use a maximum of 2 GB of memory. The problem mainly affects 32-bit versions of operating systems like Microsoft Windows and Linux, although some variants of the latter can overcome this barrier.


1 Answers

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 - What is a Kilobyte, Megabyte, Gigabyte?

  • For RAM, there is consent, that a Gigabyte is 1024 Megabytes, each consisting of 1024 Kilobytes, each being 1024 Bytes. This stems from the fact, that 1024 is 2^10, but close enough to 1000 to historically allow the Kilo prefix
  • For Storage, vendors have years ago started to use strictly decimal units, a Megabyte being 1000000 bytes (As it makes the capacities look bigger in glossy brochures)

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

2 - The addressable unit

  • For RAM, the addressable unit is the byte, even if it is fetched from physical RAM in chunks of at least 4.
  • For mass Storage, the addressable unit is the sector or block, which most often is 512 bytes, but 4096 Bytes catches up fast.

3 - The number of addressable units is much more complicated, let's start with 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

It's much less of a hassle for storage:

  • 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.
like image 61
Eugen Rieck Avatar answered Sep 21 '22 07:09

Eugen Rieck