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
#include
#include
#include
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;
}
$ ./foo & sleep 1; ps -o vsz= -o rss= $! ; wait
[1] 75193
0x800e00000(1099511627776) A z
1073750140 2076
[1]+ Done ./foo
$ printf "0x%8x\n" $(( 1073750140 * 1024 ))
0x1000081f000
The process gets a contiguous 1TB of anonymous demand-paged zero-filled
memory, and a virtual size of 1TB + 0x81f000 bytes. The resident
set size is a modest 2MB.
--
Viktor.