I try using mmap function to allocate a large amount of memory in virtual space. My need is about of 30Gb, but it can't. I tried with 20Gb with the same result. I executed my test on OVH 64 bits machine server with 60Gb RAM.
My test code:
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <errno.h>
int main()
{
void *r = NULL;
printf("%lu\n", sizeof(size_t));
r = mmap(NULL, ((size_t)20)*1024*1024*1024, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
printf("%d %s\n", r == MAP_FAILED, strerror(errno));
return 0;
}
The result of execution:
8
1 Cannot allocate memory
Someone can tell me if it's possible or not to allocate 30Gb of virtual memory with mmap, and why ? Elsewhat how to allocate 30Gb with another way ?
Please, don't ask why i want to do that or it's stupid or another philosophic thoughts. It's my need and i just want to find a way to do it if it's possible.