Linux – Is the maximum memory space available to an application equal to (physical memory + swap space)?

Is the maximum memory space available to an application equal to (physical memory + swap space)?… here is a solution to the problem.

Is the maximum memory space available to an application equal to (physical memory + swap space)?

From here< a href="https://www.centos.org/docs/5/html/5.1/Deployment_Guide/s1-swap-what-is.html" rel="noreferrer noopener nofollow">post , I know that swap space is related to physical memory. So suppose both physical memory and swap space are 4 GB. While the memory space for a 64-bit application is theoretically close to 2^64 (of course, the kernel takes up some space), from what I understand it, the actual memory that an application can use is only 8 GB.

So my question is: for an application running on Unix/Linux, is the maximum memory space it can use equal to (physical memory + swap space)?

Solution

This is a complex issue.

First, the theoretical virtual memory space for 64-bit systems is 2^64. But in reality, neither the OS nor the CPU supports such a large virtual memory space or physical RAM.

Current x86-64 CPUs (aka AMD64 and Intel’s current 64-bit chips) actually use 48-bit address lines (AMD64) and 42-bit address lines (Intel), theoretically allowing 256 TB of physical RAM.

And Linux allows 128TB of virtual memory space per process on x86-64, which can theoretically support 64TB of physical RAM.

For your question, ideally, the maximum virtual memory space that a Linux process can use is the above Linux limit on virtual memory space. Even if your system runs out of swap space and only 100MB of free RAM remains, your processes can utilize the entire memory space.

However, your system may have some restrictions on virtual memory space requests (malloc, calling the brk/sbrk system call). For example, Linux has a vm.overcommit_memory and vm.overcommit_ratio option to determine whether malloc in a process will be rejected. See also http://www.win.tue.nl/~aeb/linux/lk/lk-9.html

However, virtual memory space is not really RAM + swap. Considering the real RAM + swap space, you’re right: a process will never use more real RAM + swap space than your system. But in most cases, there will be many processes in your system, so the RAM + swap that your processes can use will be reduced. If all physical RAM + swap will run out, the OOM killer will select some processes to kill.

Related Problems and Solutions