3 ms·
If you want 32-bit pointers for compression, it seems more like the job of a "32-bit malloc()" like interface. The malloc_32bit() would return a pointer in a 32
by dragontamer 8y ago
If you want 32-bit pointers for compression, it seems more like the job of a "32-bit malloc()" like interface. The malloc_32bit() would return a pointer in a 32-bit 4GB space, and you just add a 64-bit pointer to get the true address.
An add takes 1-clock cycle (latency). An L1 cache lookup takes 4-clock cycles (latency). So an add + L1 lookup would be only 5-cycles of latency. Skylake can do two memory lookups per clock and many adds per clock (I think 3 adds per clock?), so it wouldn't take many resources at all.
The actual memory lookup takes ~100+ Cycles if its outside of the cache.
It seems like this problem can be 100% solved in userland without needing kernel support. For something like following a linked-list chain, I'd expect almost no change in speed due to out-of-order executions and memory latency hiding techniques of the CPU.
----------
64-bit user space should remain the default, if only for ASLR / security reasons. Its actually trivial for CPUs to traverse an entire 32-bit space (4-billion isn't a big number: most computers today are ~3GHz, or 3-billion operations per second...)
So if you want your address space randomization to actually have any security what-so-ever, you better use the 64-bit (erm... really 48-bit) address space.
- kllrnohj 8y agoThis is what, for example, Android's ART does. On 64-bit platforms all the JVM references remained 32-bit. They know the heap base address so they can trivially expand the references out on deref, saving the memory overhead. But in this case you can't do it entirely in userspace because things like mmap exist. You get pointers from syscalls all the time, and those can't really be compressed down since there's not a single fixed base address to add onto them. You'd have to use a different type to represent malloc'd memory that is conforming to 32-bit compressed references, but that gets real messy real fast.
- TrainedMonkey 8y agoSure you can make it work, but how much existing userland code would need to be rewritten?
- Vogtinator 8y agoShould be trivial to implement using ptmalloc/dlmalloc/whatevermalloc and constraining it to 4GiB. Main issue I see is that this requires a new ABI for passing pointers around.
- adrianratnapala 8y ago> new ABI for passing pointers around. Isn't that what x32 actually is? I mean it's not just for passing pointers around. Aaaand that's the point. With x32, people who care about these sizes can use the x32 ABI which is consistent in its own way. While everyone else uses the x64 ABI. Without x32, people who want to have 32-bit pointers need to reintroduce the NEAR/FAR distinction into the source-level-APIs. Ouch. I'm guessing the real rationale for getting rid of x32 is that 32-bit pointers are just not a big enough use case to justify it.
- loeg 8y agoYou've described a slightly different x32 ABI that is in most ways identical. And sure, what you've described has some benefits. However, It doesn't defeat the criticisms that x32 is facing in the linked LKML email: it's implemented in a brittle way; it lacks real users; and toolchains often either lack x32 support or accidentally break it.