0

If one allocates memory using anonymous memory mapping using mmap system call on linux:

mmap(NULL, 512*4096, MAP_READ|MAP_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);

I was wondering if the mapped memory was prefaulted or if physical page is actualy allocated only when the program will access the mapped virtual memory?

I ask this because at the time of the mapping I do not know if the program will actualy use all the allocated memory. So if the kernel actualy allocates physical memory for anonymous mapping only when the memory is accessed, I do not have to worry about exhausting physical memory.

Oliv
  • 17,610
  • 1
  • 29
  • 72

1 Answers1

0

I did the test by looking to file '/proc//smaps'. So what is following is an empirical answer that may not be valid for all kernel configuration.

Linux does not prefault anonymous pages: physicall memory allocation only occurs when the virtual memory is written.

Oliv
  • 17,610
  • 1
  • 29
  • 72