C Process killed during memset of big mmap

I have 16GB of RAM, no swap, FreeBSD 10.1-RELEASE. Then I create a 16GB file with
Code:
dd if=/dev/zero of=data.bin bs=1m count=16k
and run the following code
Code:
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>

int main()
{
   printf("opening\n");
   int fd = open("data.bin", O_RDWR | O_CREAT);
   struct stat sb;
   fstat(fd, &sb);
   printf("mapping %ld bytes\n", sb.st_size);
   void *mem = mmap(0, sb.st_size, PROT_READ | PROT_WRITE, MAP_NOCORE, fd, 0);
   close(fd);
   printf("clearing\n");
   memset(mem, 0, sb.st_size);
   printf("done.\n");
}
But it is killed in about three minutes during the memset execution, with dmesg saying:
Code:
pid 28986 (nomem), uid 1001, was killed: out of swap space
I don't understand why and how to fix this. If any process in the system needs a free page, shouldn't it be blocked till some of the pages used by data.bin cache be flushed? Doesn't it contradict of what memory-mapped files in 64-bit address space were intended to?

Thanks
 
Back
Top