Using 32-bit pointers on 64-bit Linux cuts memory use by 25 percent
The x32 ABI allows applications to use 32-bit pointers while retaining 64-bit registers, reducing RAM usage significantly without sacrificing speed.
Software engineer Alex Alejandre recently demonstrated that compiling the Janet programming language with the Linux x32 Application Binary Interface (ABI) reduces memory consumption by approximately 21 percent. This optimization leverages 32-bit pointers on 64-bit systems, maintaining comparable execution speeds while shrinking the memory footprint of heap objects. The findings suggest a viable path for more efficient resource usage in scripts, utilities, and daemons running on Linux.
What happened
Alejandre tested the impact of the -mx32 compiler flag on Janet, a dynamic programming language known for its lightweight design. In standard 64-bit mode, Janet uses "nanboxing" to pack values into 8 bytes, which already optimizes memory usage. However, switching to the x32 ABI yielded further reductions because it shrinks object headers and pointers. The tests showed a memory reduction between 8 percent and 32 percent, with an average savings of 21 percent. Performance remained stable, ranging from 13 percent slower to 10 percent faster than the native 64-bit build.
In contrast, using the traditional 32-bit compilation flag (-x32) resulted in a significant performance penalty, cutting speed by half. This highlights the unique advantage of the x32 ABI: it retains the wider general-purpose registers and instruction set of x86-64 while using smaller pointers. Alejandre noted that this approach is particularly effective for pointer-heavy heaps, where the reduction in pointer size directly translates to less memory pressure and better cache utilization.
The experiment also revealed limitations within Janet’s current memory management. Janet heap objects currently use 16 bytes to assist the garbage collector, including flags, padding, and linkage pointers. While the x32 ABI helps, deeper optimizations would require changes to the allocator or garbage collection strategy. Alejandre pointed out that glibc’s malloc adds overhead and rounds allocations to multiples of 16 bytes, which limits some potential savings for specific data structures like structs. However, tables and certain tuples still benefit from the reduced pointer size.
How it works
The x32 ABI is a Linux-specific feature that allows programs to run in 64-bit mode but use 32-bit pointers. Normally, 64-bit systems use 8-byte pointers, which can waste memory when addressing data that does not exceed 4 gigabytes. By switching to 4-byte pointers, applications reduce the size of every data structure that contains a reference. This reduction means more data fits into the CPU cache, which can improve performance despite the smaller address space.
To use this feature, the Linux kernel must be compiled with CONFIG_X86_X32_ABI, which provides the necessary syscall entry points. Compilers then expose this capability via the -mx32 flag. Unlike pure 32-bit mode, x32 keeps the full set of 64-bit registers and instructions, avoiding the performance bottlenecks associated with legacy 32-bit execution. This makes it an attractive option for servers and desktop applications that do not need to address more than 4 GB of memory per process.
Key details
- The
-mx32flag reduced Janet’s RAM usage by an average of 21 percent, with results ranging from 8 to 32 percent. - Execution speed remained comparable to native 64-bit builds, varying from 13 percent slower to 10 percent faster.
- Traditional 32-bit compilation (
-x32) caused a 50 percent drop in performance, making it unsuitable for performance-sensitive tasks. - The x32 ABI requires Linux kernel support via
CONFIG_X86_X32_ABIand is disabled by default on distributions like Debian and Arch Linux. - Memory savings are most pronounced in applications with pointer-heavy heaps, such as those managing many small objects.
- Glibc’s
mallocoverhead and 16-byte alignment requirements limit some potential savings for specific data structures like structs.
Why it matters
For developers building infrastructure, scripts, or long-running daemons, memory efficiency directly impacts cost and scalability. A 21 percent reduction in RAM usage allows more instances to run on the same hardware or reduces the need for over-provisioning. This is particularly relevant for containerized environments where memory limits are strict. The x32 ABI offers a way to achieve these savings without rewriting code or changing algorithms, simply by adjusting compilation flags.
The underutilization of x32 represents a missed opportunity for the Linux ecosystem. While most software compiles cleanly for x32, the lack of pre-built packages means developers must compile dependencies themselves. This barrier discourages adoption, even though the benefits are clear for many workloads. If major distributions enabled x32 support by default, it could lead to widespread efficiency gains across the server landscape, reducing energy consumption and hardware requirements.
What you can do
- Check if your Linux kernel supports x32 by looking for
CONFIG_X86_X32_ABIin your kernel configuration. - Experiment with compiling small utilities or daemons using the
-mx32flag to measure memory and performance impacts. - Investigate whether your distribution provides x32 libraries or if you need to cross-compile dependencies manually.
- Profile pointer-heavy applications to identify candidates that would benefit most from reduced pointer sizes.
- Consider using faster allocators like mimalloc in conjunction with x32 to maximize performance gains.
- Advocate for better x32 support in your preferred Linux distribution by requesting pre-built packages for common tools.



