How much virtual memory can a 32-bit process have on 64-bit Linux
(i.e. how much memory can I allocate and use with malloc()
before I start getting a NULL
pointer)?
I tried it on my 32-bit Linux and reached about 3 GB limit. Will I be able to get more on 64-bit Linux?
Memory in 32 and 64-Bit Architectures In terms of Random Access Memory, 32-bit architectures can address 4GB of memory, maximum. A 64-bit architecture, in turn, has a theoretical limit of addressing 16 million TB of memory.
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.
Most 32-bit Linux systems only support 4 GB of RAM, unless the PAE kernel is enabled, which allows a 64 GB max.
While 64-bit apps couldn't work on 32-bit OS, 32-bit apps could work on 64-bit OS but they need some 32-bit libraries to run. Since Ubuntu 11.04 (Natty) and Debian 7.0 (Wheezy) there has been support for multiarch, when 32-bit and 64-bit libraries could live on the same OS.
In the standard 32-bit x86 smp kernel, each process can use 3GB of the 4GB address space and 1GB is used by the kernel (shared in the address space of each process).
With the 4G/4G split "hugemem" 32-bit x86 kernel, each process can use (almost) the entire 4GB of address space and the kernel has a separate 4GB of address space. This kernel was supported by Red Hat in RHEL 3 and 4, but they dropped it in RHEL 5 because the patch was not accepted into the mainline kernel and most people use 64-bit kernels now anyway.
With the 64-bit x86_64 kernel, a 32-bit process can use the entire 4GB address space, except for a couple pages (8KB) at the end of the 4GB address space which are managed by the kernel. The kernel itself uses a part of the address space that is beyond the 4GB accessible to 32-bit code, so it does not reduce the user address space. A 64-bit process can use much more address space (128TB in RHEL 6).
Note that some of the address space will be used by the program code, libraries, and stack space, so you won't be able to malloc()
your entire address space. The size of these things varies by program. Take a look at /proc/<pid>/maps
to see how the address space is being used in your process; the amount you can malloc()
will be limited by the largest unused address range.
As stated above, 32bit process on 32bit kernel would be able to allocate about more or less 3GB of memory. 32bit process on 64bit kernel will be able to allocate around 4GB of memory.
A 32-bit process will only be able to access 4GB of virtual memory regardless of the OS. This is due to the process only being able to map 32-bits for memory addresses. If you do the math you'll see that 32-bit addresses can only access a maximum of 4GB evenif your running on a 128-bit os.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With