简体   繁体   中英

Memory limit to a 32-bit process running on a 64-bit Linux OS

How much virtual memory can a 32-bit process have on 64-bit Linux (ie 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?

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.

On 64-bit linux, the maximum memory space for a single process is 2^48 bytes. (In theory, more is possible, but current chips do not allow the entire virtual address space of 2^64 bytes to be used.)

See Wikipedia for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM