在 64 位 Linux 操作系统上运行的 32 位进程的内存限制
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5079519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Memory limit to a 32-bit process running on a 64-bit Linux OS
提问by leonidp
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()
在我开始获取NULL
指针之前我可以分配和使用多少内存)?
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 上尝试了它并达到了大约 3 GB 的限制。我能在 64 位 Linux 上获得更多吗?
回答by ennuikiller
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 位。如果您进行数学计算,您会发现即使您在 128 位操作系统上运行,32 位地址也最多只能访问 4GB。
回答by dogbane
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 Wikipediafor more information.
有关更多信息,请参阅维基百科。
回答by mark4o
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 的地址空间。Red Hat 在 RHEL 3 和 4 中支持这个内核,但他们在 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/<pid>/maps
,看看如何地址空间在过程中使用; 您可以使用的数量malloc()
将受到最大未使用地址范围的限制。
回答by user3333852
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 的内存。