What happens when you run out of ram with mlockall set?

I am working on a C ++ application that requires a large amount of memory to run in batch. (> 20 GB)

Some of my clients work with memory limitations, where sometimes the OS starts a swap, and the total operating time doubles or worsens.

I read that I can use mlockall so that the process is not replaced. What happens when the memory requirements of a process approach or exceed the available physical memory in this way?

I think the answer may be OS specific, so please list the OS in your answer.

+3
source share
3 answers

, , , - , , , malloc , . .

mlockall ( ), , , - malloc .

+2

Linux. , "ulimit -l" ( ), malloc .

script:

#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv){
  int r = 0;
  int count = 0;
  char *buf;

  printf("Locking...\n");
  r = mlockall(MCL_FUTURE);
  if(r){
    printf("Error: %d\n", r);
    exit(1);
  }

  while(1){
    buf = malloc(1000);
    if(!buf){
      printf("Failed to allocate after %d iterations\n", count);
      exit(0);
    }
    count++;
  }

  return 0;
}

( , C)?

, " ". , , , , . script, root, ulimit 10000, , script. 10057 , malloc ; , mlockall.

0

, , . , .

20 ? . , . .

20 , , , L2. .

20 ? - MySQL? ? python, 4 500 , ++.

0

Source: https://habr.com/ru/post/1713703/


All Articles