prefaulting MAP_ANONYMOUS pages

Kris Kennaway kris at FreeBSD.org
Fri Dec 28 16:35:15 PST 2007


I am trying to optimize a malloc-based benchmark that is mmapping 
anonymous memory (via mmap) and then eventually taking a page fault on 
every page that was allocated.  This is pretty inefficient for two reasons:

1) Lots of page faults, which drop performance by a factor of 10 
compared to the case where everything is faulted in.

2) Lack of concurrency when faulting from multiple threads on the same 
object (it is basically serialized, so no benefits from multiple CPUs)

I think a better way to go might be to do prefetching to reduce the 
number of page faults.  We do this for other types of mappings, but 
apparently not for anonymous mmapped memory.  I am still trying to get 
my head around the code here, but it looks like vm_fault_prefault is 
going to return without doing anything because of

                 while ((m = vm_page_lookup(lobject, pindex)) == NULL &&
...

                 /*
                  * give-up when a page is not in memory
                  */

Also vm_fault_additional_pages() isn't getting called because TRYPAGER 
returns false for default objects.

Is there a way to achieve this that I am overlooking?  If not can 
someone give me some advice about what is needed?

Kris


More information about the freebsd-hackers mailing list