0

I have /proc/sys/vm/overcommit_memory set to 1, which I thought would allow any amount of memory overcommit, up to the range allowed by a 64bit pointer. However, when my memory request becomes large enough, around 86Tb, the mmap call begins to fail. Is this an actual upper limit I'm hitting and if so what is it? Or am I making some mistake in allocating the memory?

The code below reproduces the issue on my laptop, the memory threshold may need to be tweaked on other computers.

#include<iostream>

#include <sys/mman.h>

static constexpr const size_t span = 86ULL * 1024ULL * 1024ULL * 1024ULL * 1024ULL;

int main() {
    fprintf(stderr, "ALLOCATING %ld bytes\n", span);
    if (mmap(0, span, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0) == MAP_FAILED) {
        perror("...");
        exit(-4);
    }
}

Console output

[user@hp]$
[user@hp]$ cat /proc/sys/vm/overcommit_memory
1
[user@hp]$ g++ -std=c++2a -o test test.cpp
[user@hp]$ ./test
ALLOCATING 94557999988736 bytes
...: Cannot allocate memory

This is the output of prlimit:

[user@hp]$ prlimit
RESOURCE   DESCRIPTION                             SOFT      HARD UNITS
AS         address space limit                unlimited unlimited bytes
CORE       max core file size                 unlimited unlimited bytes
CPU        CPU time                           unlimited unlimited seconds
...
  • Run the `prlimit` command line. Does it show any limit for the `AS` resource? – kaylum Feb 11 '22 at 04:04
  • @kaylum I updated the question with the output. `AS` is unlimited. – bad_gravitas Feb 11 '22 at 06:31
  • 1
    I do not know what your problem is, but probably it is connected to this "feature": https://en.wikipedia.org/wiki/64-bit_computing#Limits_of_processors A 48-bit limit would be 256 TB which is on the scale of your problem. – gerum Feb 11 '22 at 09:43

0 Answers0