diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index 642afbd4c669..c879bc4ac0d5 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -911,11 +911,9 @@ vm_map_insert(vm_map_t map, vm_object_t object, vm_ooffset_t offset, #endif if (cow & (MAP_PREFAULT|MAP_PREFAULT_PARTIAL)) { - mtx_lock(&Giant); - pmap_object_init_pt(map->pmap, start, + vm_map_pmap_enter(map, start, object, OFF_TO_IDX(offset), end - start, cow & MAP_PREFAULT_PARTIAL); - mtx_unlock(&Giant); } return (KERN_SUCCESS); @@ -1271,6 +1269,23 @@ vm_map_submap( return (result); } +/* + * vm_map_pmap_enter: + * + * Preload the mappings for the given object into the specified + * map. This eliminates the soft faults on process startup and + * immediately after an mmap(2). + */ +void +vm_map_pmap_enter(vm_map_t map, vm_offset_t addr, + vm_object_t object, vm_pindex_t pindex, vm_size_t size, int flags) +{ + + mtx_lock(&Giant); + pmap_object_init_pt(map->pmap, addr, object, pindex, size, flags); + mtx_unlock(&Giant); +} + /* * vm_map_protect: * @@ -1491,16 +1506,13 @@ vm_map_madvise( vm_object_madvise(current->object.vm_object, pindex, count, behav); if (behav == MADV_WILLNEED) { - mtx_lock(&Giant); - pmap_object_init_pt( - map->pmap, + vm_map_pmap_enter(map, useStart, current->object.vm_object, pindex, (count << PAGE_SHIFT), MAP_PREFAULT_MADVISE ); - mtx_unlock(&Giant); } } vm_map_unlock_read(map); diff --git a/sys/vm/vm_map.h b/sys/vm/vm_map.h index 6c89f2503f5e..62d012410c45 100644 --- a/sys/vm/vm_map.h +++ b/sys/vm/vm_map.h @@ -310,6 +310,8 @@ int vm_map_lookup (vm_map_t *, vm_offset_t, vm_prot_t, vm_map_entry_t *, vm_obje void vm_map_lookup_done (vm_map_t, vm_map_entry_t); boolean_t vm_map_lookup_entry (vm_map_t, vm_offset_t, vm_map_entry_t *); int vm_map_clean (vm_map_t, vm_offset_t, vm_offset_t, boolean_t, boolean_t); +void vm_map_pmap_enter(vm_map_t map, vm_offset_t addr, + vm_object_t object, vm_pindex_t pindex, vm_size_t size, int flags); int vm_map_protect (vm_map_t, vm_offset_t, vm_offset_t, vm_prot_t, boolean_t); int vm_map_remove (vm_map_t, vm_offset_t, vm_offset_t); void vm_map_startup (void);