--- /usr/src/sys/kern/subr_lock.c	Wed Apr  4 09:18:51 2007
+++ subr_lock.c	Mon Apr 16 18:57:25 2007
@@ -43,9 +43,9 @@ __FBSDID("$FreeBSD: src/sys/kern/subr_lo
 #include <sys/ktr.h>
 #include <sys/linker_set.h>
 #include <sys/lock.h>
+#include <sys/lock_profile.h>
 #include <sys/sbuf.h>
 #include <sys/sysctl.h>
-#include <sys/lock_profile.h>
 
 #ifdef DDB
 #include <ddb/ddb.h>
@@ -80,6 +80,15 @@ struct lock_prof lprof_buf[LPROF_HASH_SI
 static int allocated_lprof_buf;
 struct mtx lprof_locks[LPROF_LOCK_SIZE];
 
+/*
+ * Functions for handling extra informations (LOCK_PROFILE | WITNESS) in
+ * struct lock_object.
+ */
+#if defined(LOCK_PROFILE) || defined(WITNESS)
+static struct lock_ext	*lock_extra_alloc(void);
+static void		 lock_extra_free(struct lock_ext *lep);
+#endif
+
 
 /* SWAG: sbuf size = avg stat. line size * number of locks */
 #define LPROF_SBUF_SIZE		256 * 400
@@ -114,6 +123,22 @@ nanoseconds(void)
 }
 #endif
 
+#if defined(LOCK_PROFILE) || defined(WITNESS)
+static struct lock_ext *
+lock_extra_alloc(void)
+{
+
+	return (malloc(sizeof(struct lock_ext), M_TEMP, M_WAITOK | M_ZERO));
+}
+
+static void
+lock_extra_free(struct lock_ext *lep)
+{
+
+	free(lep, M_TEMP);
+}
+#endif
+
 static int
 dump_lock_prof_stats(SYSCTL_HANDLER_ARGS)
 {
@@ -211,7 +236,12 @@ lock_init(struct lock_object *lock, stru
 
 	/* Initialize the lock object. */
 	lock->lo_name = name;
-	lock->lo_type = type != NULL ? type : name;
+#if defined(LOCK_PROFILING) || defined(WITNESS)
+	lock->lo_extra = lock_extra_alloc();
+	lock->lo_extra->lox_type = type != NULL ? type : name;
+#else
+	lock->lo_extra = NULL;
+#endif
 	lock->lo_flags |= flags | LO_INITIALIZED;
 	LOCK_LOG_INIT(lock, 0);
 	WITNESS_INIT(lock);
@@ -224,6 +254,7 @@ lock_destroy(struct lock_object *lock)
 	KASSERT(lock_initalized(lock), ("lock %p is not initialized", lock));
 	WITNESS_DESTROY(lock);
 	LOCK_LOG_DESTROY(lock, 0);
+	lock_extra_free(lock->lo_extra);
 	lock->lo_flags &= ~LO_INITIALIZED;
 }
 
@@ -243,8 +274,9 @@ DB_SHOW_COMMAND(lock, db_show_lock)
 	class = LOCK_CLASS(lock);
 	db_printf(" class: %s\n", class->lc_name);
 	db_printf(" name: %s\n", lock->lo_name);
-	if (lock->lo_type && lock->lo_type != lock->lo_name)
-		db_printf(" type: %s\n", lock->lo_type);
+	if (lock->lo_extra != NULL && lock->lo_extra->lox_type != NULL &&
+	    lock->lo_extra->lox_type != lock->lo_name)
+		db_printf(" type: %s\n", lock->lo_extra->lox_type);
 	class->lc_ddb_show(lock);
 }
 #endif
@@ -252,12 +284,12 @@ DB_SHOW_COMMAND(lock, db_show_lock)
 #ifdef LOCK_PROFILING
 void _lock_profile_obtain_lock_success(struct lock_object *lo, int contested, uint64_t waittime, const char *file, int line)
 {
-        struct lock_profile_object *l = &lo->lo_profile_obj;
+        struct lock_profile_object *l = &lo->lo_extra->lox_profile;
 
-	lo->lo_profile_obj.lpo_contest_holding = 0;
+	lo->lo_extra->lox_profile.lpo_contest_holding = 0;
 	
 	if (contested)
-		lo->lo_profile_obj.lpo_contest_locking++;		
+		lo->lo_extra->lox_profile.lpo_contest_locking++;		
 	
 	l->lpo_filename = file;
 	l->lpo_lineno = line;
@@ -270,7 +302,7 @@ void _lock_profile_obtain_lock_success(s
 
 void _lock_profile_release_lock(struct lock_object *lo)
 {
-        struct lock_profile_object *l = &lo->lo_profile_obj;
+        struct lock_profile_object *l = &lo->lo_extra->lox_profile;
 
         if (l->lpo_acqtime && !(lo->lo_flags & LO_NOPROFILE)) {
                 const char *unknown = "(unknown)";
--- /usr/src/sys/kern/subr_witness.c	Mon Apr  2 07:31:33 2007
+++ subr_witness.c	Mon Apr 16 18:22:16 2007
@@ -112,8 +112,9 @@ __FBSDID("$FreeBSD: src/sys/kern/subr_wi
 #endif
 
 /* Easier to stay with the old names. */
-#define	lo_list		lo_witness_data.lod_list
-#define	lo_witness	lo_witness_data.lod_witness
+#define	lo_list		lo_extra->lox_witness_data.lod_list
+#define	lo_type		lo_extra->lox_type
+#define	lo_witness	lo_extra->lox_witness_data.lod_witness
 
 /* Define this to check for blessed mutexes */
 #undef BLESSING
--- /usr/src/sys/sys/_lock.h	Wed Nov 29 19:21:25 2006
+++ _lock.h	Mon Apr 16 18:49:53 2007
@@ -53,17 +53,21 @@ struct lock_profile_object {
         u_int                   lpo_contest_locking;
 };
 
-struct lock_object {
-	const	char *lo_name;		/* Individual lock name. */
-	const	char *lo_type;		/* General lock type. */
-	u_int	lo_flags;
-#ifdef LOCK_PROFILING
-        struct  lock_profile_object lo_profile_obj;
-#endif
+struct lock_ext {
+	const char	*lox_type;	/* General lock type. */
 	union {				/* Data for witness. */
 		STAILQ_ENTRY(lock_object) lod_list;
 		struct	witness *lod_witness;
-	} lo_witness_data;
+	} lox_witness_data;
+#ifdef LOCK_PROFILING
+	struct lock_profile_object lox_profile;
+#endif
+};
+
+struct lock_object {
+	const	char	*lo_name;	/* Individual lock name. */
+	struct lock_ext	*lo_extra;
+	u_int		lo_flags;
 };
 
 #endif /* !_SYS__LOCK_H_ */
--- /usr/src/sys/sys/lock_profile.h	Wed Apr  4 09:18:54 2007
+++ lock_profile.h	Mon Apr 16 18:47:59 2007
@@ -82,7 +82,7 @@ void _lock_profile_release_lock(struct l
 static inline void lock_profile_object_init(struct lock_object *lo, struct lock_class *class, const char *name) {
 	const char *p;
 	u_int hash = 0;
-	struct lock_profile_object *l = &lo->lo_profile_obj;
+	struct lock_profile_object *l = &lo->lo_extra->lox_profile;
 
 	lo->lo_flags = 0;
 	lo->lo_name = name;
@@ -109,7 +109,7 @@ static inline void 
 lock_profile_object_destroy(struct lock_object *lo) 
 {
 #if 0
-	struct lock_profile_object *l = &lo->lo_profile_obj;
+	struct lock_profile_object *l = &lo->lo_extra->lox_profile;
 	if (lo->lo_flags & LO_PROFILE)
 		stack_destroy(l->lpo_stack);
 #endif
@@ -118,7 +118,7 @@ lock_profile_object_destroy(struct lock_
 static inline void lock_profile_obtain_lock_failed(struct lock_object *lo, int *contested,
     uint64_t *waittime) 
 {
-	struct lock_profile_object *l = &lo->lo_profile_obj;
+	struct lock_profile_object *l = &lo->lo_extra->lox_profile;
 
 	if (lock_prof_enable && *contested == 0) {
 		*waittime = nanoseconds();
@@ -131,7 +131,7 @@ static inline void lock_profile_obtain_l
 {
 	
 	/* don't reset the timer when/if recursing */
-	if (lock_prof_enable && lo->lo_profile_obj.lpo_acqtime == 0) {
+	if (lock_prof_enable && lo->lo_extra->lox_profile.lpo_acqtime == 0) {
 #ifdef LOCK_PROFILING_FAST
                if (contested == 0)
                        return;
@@ -141,7 +141,7 @@ static inline void lock_profile_obtain_l
 }
 static inline void lock_profile_release_lock(struct lock_object *lo)
 {
-	struct lock_profile_object *l = &lo->lo_profile_obj;
+	struct lock_profile_object *l = &lo->lo_extra->lox_profile;
 
 	if (l->lpo_acqtime) 
 		_lock_profile_release_lock(lo);
