diff --git a/sys/vm/vm_fault.c b/sys/vm/vm_fault.c index 1558f629e756..757f573e715a 100644 --- a/sys/vm/vm_fault.c +++ b/sys/vm/vm_fault.c @@ -663,9 +663,7 @@ RetryFault:; /* * grab the lock if we need to */ - (fs.lookup_still_valid || - lockmgr(&fs.map->lock, LK_EXCLUSIVE|LK_NOWAIT, (void *)0, curthread) == 0) - ) { + (fs.lookup_still_valid || vm_map_trylock(fs.map))) { fs.lookup_still_valid = 1; /* diff --git a/sys/vm/vm_glue.c b/sys/vm/vm_glue.c index 2adbb4ad8325..66eaa6bbf79f 100644 --- a/sys/vm/vm_glue.c +++ b/sys/vm/vm_glue.c @@ -560,9 +560,7 @@ int action; * data structures there is a * possible deadlock. */ - if (lockmgr(&vm->vm_map.lock, - LK_EXCLUSIVE | LK_NOWAIT, - NULL, curthread)) { + if (!vm_map_trylock(&vm->vm_map)) { vmspace_free(vm); PROC_UNLOCK(p); goto nextproc; diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index 73cf6b0557a2..9b91c1a01e3d 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -336,6 +336,7 @@ vmspace_swap_count(struct vmspace *vmspace) vm_map_entry_t cur; int count = 0; + vm_map_lock_read(map); for (cur = map->header.next; cur != &map->header; cur = cur->next) { vm_object_t object; @@ -351,6 +352,7 @@ vmspace_swap_count(struct vmspace *vmspace) } } } + vm_map_unlock_read(map); return (count); } @@ -397,6 +399,14 @@ vm_map_unlock_read(vm_map_t map) lockmgr(&(map)->lock, LK_RELEASE, NULL, curthread); } +int +vm_map_trylock(vm_map_t map) +{ + + return (lockmgr(&map->lock, LK_EXCLUSIVE | LK_NOWAIT, NULL, + curthread) == 0); +} + static __inline__ int _vm_map_lock_upgrade(vm_map_t map, struct thread *td) { int error; diff --git a/sys/vm/vm_map.h b/sys/vm/vm_map.h index fbc44c940a27..8de264f11db6 100644 --- a/sys/vm/vm_map.h +++ b/sys/vm/vm_map.h @@ -241,6 +241,7 @@ void vm_map_lock(vm_map_t map); void vm_map_unlock(vm_map_t map); void vm_map_lock_read(vm_map_t map); void vm_map_unlock_read(vm_map_t map); +int vm_map_trylock(vm_map_t map); int vm_map_lock_upgrade(vm_map_t map); void vm_map_lock_downgrade(vm_map_t map); void vm_map_set_recursive(vm_map_t map); diff --git a/sys/vm/vm_pageout.c b/sys/vm/vm_pageout.c index 23e94f2e7917..5708d8de89a9 100644 --- a/sys/vm/vm_pageout.c +++ b/sys/vm/vm_pageout.c @@ -547,9 +547,8 @@ vm_pageout_map_deactivate_pages(map, desired) int nothingwired; GIANT_REQUIRED; - if (lockmgr(&map->lock, LK_EXCLUSIVE | LK_NOWAIT, (void *)0, curthread)) { + if (!vm_map_trylock(map)) return; - } bigobj = NULL; nothingwired = TRUE;