1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-04 12:52:15 +00:00

Make refinements to r212824. In particular, don't make

vm_map_unlock_nodefer() part of the synchronization interface for maps.

Add comments to vm_map_unlock_and_wait() and vm_map_wakeup() describing
how they should be used.  In particular, describe the deferred deallocations
issue with vm_map_unlock_and_wait().

Redo the implementation of vm_map_unlock_and_wait() so that it passes
along the caller's file and line information, just like the other map
locking primitives.

Reviewed by:	kib
X-MFC after:	r212824
This commit is contained in:
Alan Cox 2010-09-19 17:43:22 +00:00
parent d1817ed7f3
commit 8304adaac6
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=212868
2 changed files with 27 additions and 20 deletions

View File

@ -469,16 +469,6 @@ vm_map_process_deferred(void)
}
}
void
_vm_map_unlock_nodefer(vm_map_t map, const char *file, int line)
{
if (map->system_map)
_mtx_unlock_flags(&map->system_mtx, 0, file, line);
else
_sx_xunlock(&map->lock, file, line);
}
void
_vm_map_unlock(vm_map_t map, const char *file, int line)
{
@ -637,19 +627,37 @@ _vm_map_assert_locked_read(vm_map_t map, const char *file, int line)
#endif
/*
* vm_map_unlock_and_wait:
* _vm_map_unlock_and_wait:
*
* Atomically releases the lock on the specified map and puts the calling
* thread to sleep. The calling thread will remain asleep until either
* vm_map_wakeup() is performed on the map or the specified timeout is
* exceeded.
*
* WARNING! This function does not perform deferred deallocations of
* objects and map entries. Therefore, the calling thread is expected to
* reacquire the map lock after reawakening and later perform an ordinary
* unlock operation, such as vm_map_unlock(), before completing its
* operation on the map.
*/
int
vm_map_unlock_and_wait(vm_map_t map, int timo)
_vm_map_unlock_and_wait(vm_map_t map, int timo, const char *file, int line)
{
mtx_lock(&map_sleep_mtx);
vm_map_unlock_nodefer(map);
return (msleep(&map->root, &map_sleep_mtx, PDROP | PVM, "vmmaps", timo));
if (map->system_map)
_mtx_unlock_flags(&map->system_mtx, 0, file, line);
else
_sx_xunlock(&map->lock, file, line);
return (msleep(&map->root, &map_sleep_mtx, PDROP | PVM, "vmmaps",
timo));
}
/*
* vm_map_wakeup:
*
* Awaken any threads that have slept on the map using
* vm_map_unlock_and_wait().
*/
void
vm_map_wakeup(vm_map_t map)
@ -657,8 +665,8 @@ vm_map_wakeup(vm_map_t map)
/*
* Acquire and release map_sleep_mtx to prevent a wakeup()
* from being performed (and lost) between the vm_map_unlock()
* and the msleep() in vm_map_unlock_and_wait().
* from being performed (and lost) between the map unlock
* and the msleep() in _vm_map_unlock_and_wait().
*/
mtx_lock(&map_sleep_mtx);
mtx_unlock(&map_sleep_mtx);

View File

@ -266,7 +266,7 @@ vmspace_pmap(struct vmspace *vmspace)
void _vm_map_lock(vm_map_t map, const char *file, int line);
void _vm_map_unlock(vm_map_t map, const char *file, int line);
void _vm_map_unlock_nodefer(vm_map_t map, const char *file, int line);
int _vm_map_unlock_and_wait(vm_map_t map, int timo, const char *file, int line);
void _vm_map_lock_read(vm_map_t map, const char *file, int line);
void _vm_map_unlock_read(vm_map_t map, const char *file, int line);
int _vm_map_trylock(vm_map_t map, const char *file, int line);
@ -274,13 +274,12 @@ int _vm_map_trylock_read(vm_map_t map, const char *file, int line);
int _vm_map_lock_upgrade(vm_map_t map, const char *file, int line);
void _vm_map_lock_downgrade(vm_map_t map, const char *file, int line);
int vm_map_locked(vm_map_t map);
int vm_map_unlock_and_wait(vm_map_t map, int timo);
void vm_map_wakeup(vm_map_t map);
#define vm_map_lock(map) _vm_map_lock(map, LOCK_FILE, LOCK_LINE)
#define vm_map_unlock(map) _vm_map_unlock(map, LOCK_FILE, LOCK_LINE)
#define vm_map_unlock_nodefer(map) \
_vm_map_unlock_nodefer(map, LOCK_FILE, LOCK_LINE)
#define vm_map_unlock_and_wait(map, timo) \
_vm_map_unlock_and_wait(map, timo, LOCK_FILE, LOCK_LINE)
#define vm_map_lock_read(map) _vm_map_lock_read(map, LOCK_FILE, LOCK_LINE)
#define vm_map_unlock_read(map) _vm_map_unlock_read(map, LOCK_FILE, LOCK_LINE)
#define vm_map_trylock(map) _vm_map_trylock(map, LOCK_FILE, LOCK_LINE)