-2

So I knew that a 32-bits OS can support 232 different values, which is approximately 4x109.

I would imagine that the internal representation of each value is like this:

0000 0000 0000 0000 0000 0000 0000 0000

.....

1111 1111 1111 1111 1111 1111 1111 1111

So we have approximately 4x109 different patterns here. But Since each address consists of 4 bytes (32/8=4), shouldn't the RAM be 4x4x109?

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
Fred
  • 111
  • 1
  • 6
  • 1
    This is more of a SuperUser question, answered here: https://superuser.com/questions/367490/can-a-32-bit-os-machine-use-up-all-8gb-ram-20gb-page-file – Raymond Chen Jan 28 '19 at 03:09
  • 5
    For most 32 bit processors, addresses are at the byte level, not word level. Some 32 bit processors support more than 4 GB of ram, but each process virtual address space is limited to 4 GB. Windows Server 2008 is one of the few 32 bit versions of Windows that supports more than 4GB. – rcgldr Jan 28 '19 at 03:12
  • 3
    x86 is byte addressable. – Clifford Jan 28 '19 at 03:18
  • 2
    NOT 4 bytes, it's 1 byte. – Bumsik Kim Jan 28 '19 at 03:37
  • 1
    Are you assuming that each 4-byte address points to a 4-byte chunk of memory? In fact, each 4-byte address points to a single byte. – Keith Thompson Jan 28 '19 at 04:59
  • duplicate of [Why 32-bit processor can only address 4GiB of memory, even with large word size?](https://stackoverflow.com/q/33582419/995714), [How does 32bit address 4GB if 2^32bits = 4Billion bits not Bytes?](https://stackoverflow.com/q/25820886/995714) – phuclv Jan 28 '19 at 05:06

4 Answers4

0

Each address addresses one byte, in typical modern systems.

Even if the hardware can only transfer four bytes or eight bytes at a time, each byte within such a unit is given its own address. The processor may only interact with the memory hardware using 28 or 29 or some other number of bits, but it uses the additional bits to distinguish bytes within words.

When a program accesses a particular address, the processor uses the low bits to isolate bytes. When reading, it gets an entire unit from memory and then uses the low bits to isolate the requested byte or bytes. When writing, it uses the low bits to merge the selected byte or bytes into a unit of data, and then it writes the complete unit to memory.

So, with 32 bits in an address, 232 = 4,294,967,296 addresses are available, and 4,294,967,296 things can be addressed. In typical modern hardware, each of those things is one byte. Often, not all of them are available to user programs, as some addresses are reserved for special purposes.

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312
0

x86 is byte addressed, which means that each byte has a unique address. This makes (under normal circumstances) the total amount of addressable memory to be 2^32 bytes (roughly 4 GB). And non addressable memory (memory that you can't have an address for) is utterly unusable.

Out of the whole address space, not all addresses are to main memory. A chunk of it is reserved for IO, so the amount of maximum RAM is even lower than 4 GB.


I will try to address your confusion

So we have approximately 4x109 different patterns here.

correct

But Since each address consists of 4 bytes (32/8=4)

irrelevant

shouldn't the RAM be 4x4x109?

no

The number of bits of the address determines how many different values can be. We already determined that 32 bits give us exactly 2^32 ≈ 4^10 different addresses. We can therefore have ≈4^10 different objects that have unique addresses. Bear with me, let's think a bit outside of the box. If the addresses were addresses of cities, then we could have a maximum of ≈4^10 cities. If the addresses were addresses of streets, we could have a maximum of ≈4^10 streets. If the addresses were addresses of apples, we could have a maximum of ≈4^10 apples. With me? If the addresses were addresses of 64-bit QWORDS then we could have a maximum of ≈4^10 64-bit qwords. If the addresses were addresses of 32-bit DWORDS then we could have a maximum of ≈4^10 32-bit qwords. But in x86 an address is none of the above. In x86 an address is an address of a byte (8 bits) so we can have a maximum of ≈4^10 bytes aka ≈4 GiB.

As you can see the width of the address only gives the number of different objects we can address. In x86 those objects are bytes, so we can have a maximum of 2^32 addressable bytes.


The normal limit of 2^32 bytes can be overcome with Physical Address Extension. This requires both OS and hardware (CPU, chipset and motherboard) support and even when these are met each program can still only work with 32 bit addresses.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
bolov
  • 72,283
  • 15
  • 145
  • 224
  • See what I am confused about is that since it's a 32-bits OS, each address has 32 bits. And one byte consists of 8 bits, so each address has 4 bytes. And we can have approximately 4x10^9 patterns for addresses. So why we say the limit of virtual address space is 4GB? – Fred Jan 28 '19 at 03:45
  • 1
    It takes 4 bytes to store an address, but the addresses store the index of the individual bytes, not the 32-bit words. In other words, what you think is happening is: `Address 0: 0000 0000 0000 0000 0000 0000 0000 0000, Address 1: 1111 1111 1111 1111 1111 1111 1111 1111...`, while what actually happens is `Address 0: 0000 0000, Address 1: 1111 1111, Address 2: 1010 1010`. For example, a 32-bit int takes up 4 bytes, and therefore 4 addresses. The key is that each byte has it's own unique address. – eesiraed Jan 28 '19 at 04:03
-1

[It's likely I misunderstood the question. I might delete this answer later.]

For a system with 32-bit (4-byte -- assuming 8-bit bytes) addresses, there are 232 distinct address values. If the memory space is fully populated with RAM, then you can use a 32-bit address to refer to any of the 232 bytes of memory on the system.

But you can't store all those 232 address values in memory simultaneously. As you say, you would need 4 * 232 bytes to store all those address values.

Fortunately, there's no need to store all those distinct memory address values in memory. You only need to store those address values that you're actually using.

(I'm ignoring issues of virtual vs. physical memory.)

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • So you are saying that when people talk about 4GB, it means that the maximum number of addresses, which is 4x10^9 (0 to 4GB-1)? But I am still confusing that my textbook says "A 32-bit word size limits the virtual address space to 4GB, that is, just over 4 x 10^9 bytes." The word "bytes" in this sentence doesn't make sense to me. – Fred Jan 28 '19 at 03:30
  • Each of the 2^32 possible address values refers to the location of a byte in memory. The statement in your textbook implies that an address value occupies exactly one "word". For example, the 32-bit address value `0x12345679` would refer to the byte immediately following the one referred to by the address value `0x12345678`. – Keith Thompson Jan 28 '19 at 04:07
  • I think you misunderstood the OP's question. It has nothing to do with storing all the possible memory addresses in RAM. The OP thinks that the memory addresses point to 32-bit blocks instead of individual bytes. – eesiraed Jan 28 '19 at 04:24
  • @FeiXiang: I think you're probably right. If the OP confirms this, I'll delete my answer. – Keith Thompson Jan 28 '19 at 04:59
  • BTW I'm not the downvoter, so I don't know if this is the actual reason behind it. – eesiraed Jan 28 '19 at 05:02
-1

For a modern OS, typically there's virtual addresses that are translated into physical addresses.

For a 32-bit OS, the virtual addresses are often (but not necessarily) 32-bit. With byte addressing, this means you can have 1234 processes where each process has 4 GiB of virtual space (or a total of 4936 GiB of virtual space). However, typically each virtual address space is split with "user-space" in one part and "kernel-space" in another part; so it might be more like 2 GiB for each process plus 2 GiB for the kernel (or a total of 2470 GiB for 1234 processes).

However, because virtual addresses are converted into physical addresses the size of a virtual address doesn't need to be the same as the size of a physical address. This means that even if virtual addresses are 32-bit, a physical address can be larger (or smaller) than 32-bit. For example, for most older 80x86 CPUs there's a "Physical Address Extensions" (PAE) feature that extends the physical address size to 36 bits (giving you a physical address space of 16 GiB), and for modern 80x86 CPUs (that are capable of running a 64-bit OS) PAE was enhanced to allow a 32-bit OS to use physical addresses up to (a "current architectural maximum" of) 52-bits, giving a physical address space size up to 4096 TiB for a 32-bit OS (in theory).

Of course the physical address space contains RAM, some ROM, some areas for devices, etc. For example, with 16 GiB of physical address space, 1.5 GiB might be reserved for things that aren't RAM, so the maximum RAM you might be able to have (and the maximum a 32-bit OS could use) might be 14.5 GiB.

Sadly(?) most motherboards don't support the maximum amount of RAM that the CPU is capable of using. For example, a lot of modern CPUs support 48-bit physical addresses (256 TiB of physical address space) but I've never seen a motherboard that's able to support more than 8 TiB of RAM and most modern motherboards don't even support 1 TIB of RAM.

In the same way, various operating systems have their own limits. For example, most 32-bit versions of Windows didn't support PAE (because of device driver compatibility issues initially, and then because everyone adopted 64-bit anyway so nobody cared); so if you had a computer with (e.g.) 8 GiB of RAM the OS can't use most of the RAM (and would probably only be able to use 3 GiB of the RAM because 1 GiB of space is probably reserved/used by ROMs, devices, etc).

Note that for 64-bit operating systems on 80x86; virtual addresses are 48-bit (not 64 bit) and physical addresses are anything from 32-bit (Atom) to 52-bit (and also not 64 bit); and Intel has been thinking of a "5-level paging" extension to allow 57-bit virtual addresses (which still won't be 64-bit).

In general (if you ignore specific CPUs); the size of a general purpose register, the size of a virtual address and the size of a physical address can all be completely different; and for a 32-bit OS (using 32-bit general purpose registers) the virtual address space size can be anything and the physical address space size can be anything; and the maximum amount of RAM you could have in the physical address space can be anything.

Brendan
  • 35,656
  • 2
  • 39
  • 66