On Thu, Jul 05, 2018 at 08:13:33PM -0400, Viktor Dukhovni wrote:
On Thu, Jul 05, 2018 at 09:32:31AM -0400, Ben Gamari wrote:
We use a much different memory allocation strategy on FreeBSD which (AFAIK) does not allow one to reserve address space without also committing.
Here's a demo of mapping in a 1TB heap on FreeBSD 11.1, on a machine with "just" 64GB of RAM and 160GB swap. I would expect anon memory mappings to behave similarly on older systems.
$ cat foo.c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/mman.h>
int main(int argc, char **argv) { size_t heaplen = 1ULL << 40; /* 1TB */ unsigned char *heap;
heap = mmap(NULL, heaplen, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0); heap[0] = 'A'; heap[heaplen-1] = 'z'; printf ("%p(%zd) %c %c\n", heap, heaplen, heap[0], heap[heaplen-1]); sleep(2); return 0; }
I also get essentially the same results with posix_memalign(3): #include <stdlib.h> #include <stdio.h> #include <err.h> #include <unistd.h> #include <sys/mman.h> int main(int argc, char **argv) { size_t heaplen = 1ULL << 40; void *p; unsigned char *heap; if (posix_memalign(&p, getpagesize(), heaplen) != 0) err(1, "posix_memalign"); heap = p; heap[0] = 'A'; heap[heaplen-1] = 'z'; printf ("%p(%zd) %c %c\n", heap, heaplen, heap[0], heap[heaplen-1]); sleep(2); return 0; } $ ./foo & sleep 1; ps -o vsz= -o rss= $! ; wait [1] 76003 0x801000000(1099511627776) A z 1073750140 2080 [1]+ Done ./foo -- Viktor.