内存限制为在64位Linux操作系统上运行的32位进程

时间:2022-09-01 10:05:08

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)?

32位进程在64位Linux上可以有多少虚拟内存(例如,在开始获取空指针之前,我可以分配和使用malloc()多少内存)?

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?

我在32位的Linux上尝试过,达到了大约3gb的限制。我能在64位Linux上获得更多吗?

4 个解决方案

#1


23  

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).

在标准的32位x86 smp内核中,每个进程可以使用4GB地址空间的3GB,内核使用1GB(在每个进程的地址空间*享)。

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.

使用4G/4G分离的“hugemem”32位x86内核,每个进程(几乎)都可以使用整个4GB的地址空间,内核有单独的4GB的地址空间。这个内核在RHEL 3和4中得到了Red Hat的支持,但是他们在RHEL 5中放弃了它,因为补丁没有被主流内核接受,而且现在大多数人都使用64位内核。

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).

使用64位的x86_64内核,32位进程可以使用整个4GB地址空间,除了在由内核管理的4GB地址空间末尾的几个页面(8KB)。内核本身使用的地址空间的一部分超出了4GB可访问的32位代码,因此它不会减少用户地址空间。64位进程可以使用更多的地址空间(RHEL 6中的128TB)。

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.

注意,一些地址空间将被程序代码、库和堆栈空间使用,因此您将无法使用malloc()您的整个地址空间。这些东西的大小因程序而异。查看/proc/ /maps,了解如何在进程中使用地址空间;您可以malloc()的数量将受到最大未使用地址范围的限制。

#2


2  

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.

如上所述,32位内核上的32位进程可以分配大约3GB的内存。64位内核上的32位进程将能够分配大约4GB的内存。

#3


1  

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.

一个32位的进程只能够访问4GB的虚拟内存,而不考虑操作系统。这是因为进程只能为内存地址映射32位。如果您进行计算,您将看到32位地址只能访问最大4GB,即使您在128位操作系统上运行。

#4


0  

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.)

在64位linux,最大的一个进程的内存空间是2 ^ 48字节。(理论上,更多的是可能的,但是目前的芯片不允许整个虚拟地址空间使用2 ^ 64字节)。

See Wikipedia for more information.

更多信息请参见*。

#1


23  

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).

在标准的32位x86 smp内核中,每个进程可以使用4GB地址空间的3GB,内核使用1GB(在每个进程的地址空间*享)。

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.

使用4G/4G分离的“hugemem”32位x86内核,每个进程(几乎)都可以使用整个4GB的地址空间,内核有单独的4GB的地址空间。这个内核在RHEL 3和4中得到了Red Hat的支持,但是他们在RHEL 5中放弃了它,因为补丁没有被主流内核接受,而且现在大多数人都使用64位内核。

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).

使用64位的x86_64内核,32位进程可以使用整个4GB地址空间,除了在由内核管理的4GB地址空间末尾的几个页面(8KB)。内核本身使用的地址空间的一部分超出了4GB可访问的32位代码,因此它不会减少用户地址空间。64位进程可以使用更多的地址空间(RHEL 6中的128TB)。

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.

注意,一些地址空间将被程序代码、库和堆栈空间使用,因此您将无法使用malloc()您的整个地址空间。这些东西的大小因程序而异。查看/proc/ /maps,了解如何在进程中使用地址空间;您可以malloc()的数量将受到最大未使用地址范围的限制。

#2


2  

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.

如上所述,32位内核上的32位进程可以分配大约3GB的内存。64位内核上的32位进程将能够分配大约4GB的内存。

#3


1  

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.

一个32位的进程只能够访问4GB的虚拟内存,而不考虑操作系统。这是因为进程只能为内存地址映射32位。如果您进行计算,您将看到32位地址只能访问最大4GB,即使您在128位操作系统上运行。

#4


0  

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.)

在64位linux,最大的一个进程的内存空间是2 ^ 48字节。(理论上,更多的是可能的,但是目前的芯片不允许整个虚拟地址空间使用2 ^ 64字节)。

See Wikipedia for more information.

更多信息请参见*。