Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux mmap() with MAP_POPULATE, man page seems to give wrong info

It looks to me like MAP_POPULATE is not just for private mappings, in contradiction to what the man page says:

MAP_POPULATE (since Linux 2.5.46) Populate (prefault) page tables for a mapping. For a file mapping, this causes read-ahead on the file. Later accesses to the mapping will not be blocked by page faults. MAP_POPULATE is only supported for private mappings since Linux 2.6.23.

Based on my cursory inspection of the Linux kernel source for mmap.c, it looks like MAP_POPULATE has absolutely no relationship with MAP_PRIVATE whatsoever in versions going back as far as 2.6.34.

Here is an excerpt of the latest code from mmap.c as of the 3.14 kernel implementation:

...
1364         addr = mmap_region(file, addr, len, vm_flags, pgoff);
1365         if (!IS_ERR_VALUE(addr) &&
1366             ((vm_flags & VM_LOCKED) ||
1367              (flags & (MAP_POPULATE | MAP_NONBLOCK)) == MAP_POPULATE))
1368                 *populate = len;
1369         return addr;
...

Am I wrong in my observation?

like image 554
Michael Goldshteyn Avatar asked May 06 '14 18:05

Michael Goldshteyn


1 Answers

The wording has been updated since you asked the question:

Before: MAP_POPULATE is only supported for private mappings since Linux 2.6.23.
After:  MAP_POPULATE is supported for private mappings only since Linux 2.6.23.

In other words, you can use MAP_POPULATE for private mappings, but you need at least Linux 2.6.23.

Hope this clarifies it!

like image 121
Jo Liss Avatar answered Sep 28 '22 01:09

Jo Liss