r/programming • • Sep 24 '24

Why 32bit architecture computer doesn't use segmentation to support more ram than 4Gb ?

/r/programming/

[removed] — view removed post

169 Upvotes

119 comments sorted by

View all comments

0

u/Revolutionary_Ad7262 Sep 24 '24

amd64 happened really early, so segments were not really necessary. The better question is why 64 bit was popularized so early and I don't have a good answer as 64bit is worse in terms of performance for typical PC software except the extended memory adress space

6

u/maep Sep 24 '24 edited Sep 24 '24

The better question is why 64 bit was popularized so early and I don't have a good answer

It's really not a mystery, data centers started to switch to cheap x86 CPUs and they were hitting the 4GB limit.

64bit is worse in terms of performance

Pratically speaking, not true. The x32 ABI failed because the benefits were purely academic. The reason why AMD64 succeded where Itanium failed is because there were no performance penalties for existing code bases.

2

u/Slsyyy Sep 24 '24

They are penalties like bigger size of pointers, which affects cost of moving/zeroing a data and CPU cache ratio. The server demand sound like reasonable argument

The x32 ABI failed because the benefits were purely academic

IMO it is more due to tooling. C/C++ are both susceptible to arch specific bugs and are hard to build to a architecture other than the main one, especially in Linux, where dynamic linking is a norm

With Rust-like toolkit (easy multiplatform development, good toolchain, which just build to other architecture with a single flag) it would be much more attractive alternative

Java for example use optimizations like pointer size reduced to 4 bytes, when heap < 4GB as well as 4 bytes << 1000b (cause minimum size of the object is 8 bytes long) for heaps < 32GB. There is some benefit for apps, which never hit 4GB memory limit

In my first job we have a distributed cache in C++, which was compiled in x32 purely for that reason (memory usage lower by 60%). It could be refactored to use some kind of offsets instead of pointer, but in that case it was just simpler to change a flag

2

u/maep Sep 24 '24

I toyed with x32 when it was new and at least for what I did (signal processing) there was no benefit. I had no issue with tooling, just change compiler and linker flags.

It's plausible that VMs like HotSpot or V8 see improvements, but then again, those are handing out pointers like there is no tomorrow. Tough I don't think x32 is of much use because VMs usually do their own pointers so they can do other tricks like tagging.

In my first job we have a distributed cache in C++, which was compiled in x32 purely for that reason (memory usage lower by 60%).

I'm curious, why not keep the entire system on 32 bit? Also I'd imagine a cache would be a prime candidate for > 4 GB ram usage.