1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-17 15:27:36 +00:00

o Introduce and use vm_map_trylock() to replace several direct uses

of lockmgr().
 o Add missing synchronization to vmspace_swap_count(): Obtain a read lock
   on the vm_map before traversing it.
This commit is contained in:
Alan Cox 2002-04-28 06:07:54 +00:00
parent 67a2a28fe4
commit d974f03c69
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=95610
5 changed files with 14 additions and 8 deletions

View File

@ -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;
/*

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;