1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-15 10:17:20 +00:00

Change the all locks list from a STAILQ to a TAILQ. This bloats struct

lock_object by another pointer (though all of lock_object should be
conditional on LOCK_DEBUG anyways) in exchange for an O(1) TAILQ_REMOVE()
in witness_destroy() (called for every mtx_destroy() and sx_destroy())
instead of an O(n) STAILQ_REMOVE.  Since WITNESS is so dog slow as it is,
the speed-up is worth the space cost.

Suggested by:	iedowse
This commit is contained in:
John Baldwin 2002-06-06 20:51:04 +00:00
parent 13866b3fd2
commit 48849938e8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=97963
2 changed files with 7 additions and 7 deletions

View File

@ -241,14 +241,14 @@ static int blessed_count =
/*
* List of all locks in the system.
*/
STAILQ_HEAD(, lock_object) all_locks = STAILQ_HEAD_INITIALIZER(all_locks);
TAILQ_HEAD(, lock_object) all_locks = TAILQ_HEAD_INITIALIZER(all_locks);
static struct mtx all_mtx = {
{ &lock_class_mtx_sleep, /* mtx_object.lo_class */
"All locks list", /* mtx_object.lo_name */
"All locks list", /* mtx_object.lo_type */
LO_INITIALIZED, /* mtx_object.lo_flags */
{ NULL }, /* mtx_object.lo_list */
{ NULL, NULL }, /* mtx_object.lo_list */
NULL }, /* mtx_object.lo_witness */
MTX_UNOWNED, 0, /* mtx_lock, mtx_recurse */
TAILQ_HEAD_INITIALIZER(all_mtx.mtx_blocked),
@ -285,7 +285,7 @@ witness_initialize(void *dummy __unused)
mtx_assert(&Giant, MA_NOTOWNED);
CTR1(KTR_WITNESS, "%s: initializing witness", __func__);
STAILQ_INSERT_HEAD(&all_locks, &all_mtx.mtx_object, lo_list);
TAILQ_INSERT_HEAD(&all_locks, &all_mtx.mtx_object, lo_list);
mtx_init(&w_mtx, "witness lock", NULL, MTX_SPIN | MTX_QUIET |
MTX_NOWITNESS);
for (i = 0; i < WITNESS_COUNT; i++)
@ -313,7 +313,7 @@ witness_initialize(void *dummy __unused)
/* Iterate through all locks and add them to witness. */
mtx_lock(&all_mtx);
STAILQ_FOREACH(lock, &all_locks, lo_list) {
TAILQ_FOREACH(lock, &all_locks, lo_list) {
if (lock->lo_flags & LO_WITNESS)
lock->lo_witness = enroll(lock->lo_type,
lock->lo_class);
@ -352,7 +352,7 @@ witness_init(struct lock_object *lock)
class->lc_name, lock->lo_name);
mtx_lock(&all_mtx);
STAILQ_INSERT_TAIL(&all_locks, lock, lo_list);
TAILQ_INSERT_TAIL(&all_locks, lock, lo_list);
lock->lo_flags |= LO_INITIALIZED;
lock_cur_cnt++;
if (lock_cur_cnt > lock_max_cnt)
@ -388,7 +388,7 @@ witness_destroy(struct lock_object *lock)
mtx_lock(&all_mtx);
lock_cur_cnt--;
STAILQ_REMOVE(&all_locks, lock, lock_object, lo_list);
TAILQ_REMOVE(&all_locks, lock, lo_list);
lock->lo_flags &= ~LO_INITIALIZED;
mtx_unlock(&all_mtx);
}

View File

@ -36,7 +36,7 @@ struct lock_object {
const char *lo_name; /* Individual lock name. */
const char *lo_type; /* General lock type. */
u_int lo_flags;
STAILQ_ENTRY(lock_object) lo_list; /* List of all locks in system. */
TAILQ_ENTRY(lock_object) lo_list; /* List of all locks in system. */
struct witness *lo_witness;
};