--- sys/i386/include/param.h	2006-07-26 18:42:11.000000000 +0200
+++ param.h	2006-07-26 20:10:16.000000000 +0200
@@ -118,6 +118,14 @@
 #endif
 
 /*
+ * Intel Xeon and Pentium4 want 128-byte aligned syncronizing primitives
+ * in order to minimize bus cache traffic.
+ */
+#ifndef	SYNC_ALIGN
+#define	SYNC_ALIGN	(128 - 1)
+#endif
+
+/*
  * Mach derived conversion macros
  */
 #define trunc_page(x)		((x) & ~PAGE_MASK)
--- sys/sys/param.h	2006-07-26 18:41:51.000000000 +0200
+++ param.h	2006-07-26 20:13:13.000000000 +0200
@@ -150,6 +150,13 @@
 #define	MJUM16BYTES	(16 * 1024)	/* jumbo cluster 16k */
 
 /*
+ * Default UMA cache-alignment for syncronizing primtives.
+ */
+#ifndef	SYNC_ALIGN
+#define	SYNC_ALIGN	(16 - 1)
+#endif
+
+/*
  * Some macros for units conversion
  */
 
--- sys/kern/subr_sleepqueue.c	2006-07-26 18:36:13.000000000 +0200
+++ subr_sleepqueue.c	2006-07-28 18:41:26.000000000 +0200
@@ -69,7 +69,6 @@
 #include <sys/lock.h>
 #include <sys/kernel.h>
 #include <sys/ktr.h>
-#include <sys/malloc.h>
 #include <sys/mutex.h>
 #include <sys/proc.h>
 #include <sys/sched.h>
@@ -77,6 +76,8 @@
 #include <sys/sleepqueue.h>
 #include <sys/sysctl.h>
 
+#include <vm/uma.h>
+
 /*
  * Constants for the hash table of sleep queue chains.  These constants are
  * the same ones that 4BSD (and possibly earlier versions of BSD) used.
@@ -137,8 +138,7 @@
     0, "maxmimum depth achieved of a single chain");
 #endif
 static struct sleepqueue_chain sleepq_chains[SC_TABLESIZE];
-
-static MALLOC_DEFINE(M_SLEEPQUEUE, "sleep queues", "sleep queues");
+static uma_zone_t sleepqueue_zone;
 
 /*
  * Prototypes for non-exported routines.
@@ -147,6 +147,8 @@
 static void	sleepq_switch(void *wchan);
 static void	sleepq_timeout(void *arg);
 static void	sleepq_resume_thread(struct sleepqueue *sq, struct thread *td, int pri);
+static int	sleepq_init(void *mem, int size, int flags);
+static void	sleepq_fini(void *mem, int size);
 
 /*
  * Early initialization of sleep queues that is called from the sleepinit()
@@ -177,33 +179,27 @@
 		    NULL);
 #endif
 	}
+	sleepqueue_zone = uma_zcreate("SLEEPQUEUE", sizeof(struct sleepqueue),
+	    NULL, NULL, sleepq_init, sleepq_fini, SYNC_ALIGN, 0);
 	thread0.td_sleepqueue = sleepq_alloc();
 }
 
 /*
- * Malloc and initialize a new sleep queue for a new thread.
+ * Alloc an UMA slab for a new sleep queue in a new thread.
  */
 struct sleepqueue *
 sleepq_alloc(void)
 {
-	struct sleepqueue *sq;
-
-	sq = malloc(sizeof(struct sleepqueue), M_SLEEPQUEUE, M_WAITOK | M_ZERO);
-	TAILQ_INIT(&sq->sq_blocked);
-	LIST_INIT(&sq->sq_free);
-	return (sq);
+	return(uma_zalloc(sleepqueue_zone, M_WAITOK));
 }
 
 /*
- * Free a sleep queue when a thread is destroyed.
+ * Free the UMA slab when a thread is destroyed.
  */
 void
 sleepq_free(struct sleepqueue *sq)
 {
-
-	MPASS(sq != NULL);
-	MPASS(TAILQ_EMPTY(&sq->sq_blocked));
-	free(sq, M_SLEEPQUEUE);
+	uma_zfree(sleepqueue_zone, sq);
 }
 
 /*
@@ -514,6 +510,34 @@
 }
 
 /*
+ * Initialize a sleepqueue in its UMA slab.
+ */
+static int
+sleepq_init(void *mem, int size, int flags)
+{
+	struct sleepqueue *sq;
+
+	bzero(mem, size);
+	sq = mem;
+	TAILQ_INIT(&sq->sq_blocked);
+	LIST_INIT(&sq->sq_free);
+
+	return(0);
+}
+
+/*
+ * Free a sleepqueue in its UMA slab.
+ */
+static void
+sleepq_fini(void *mem, int size)
+{
+	struct sleepqueue *sq;
+
+	sq = mem;
+	MPASS(TAILQ_EMPTY(&sq->sq_blocked));
+}
+	
+/*
  * Block the current thread until it is awakened from its sleep queue.
  */
 void
--- sys/kern/subr_turnstile.c	2006-07-26 18:36:13.000000000 +0200
+++ subr_turnstile.c	2006-07-28 18:49:07.000000000 +0200
@@ -46,14 +46,14 @@
  * chain.  Each chain contains a spin mutex that protects all of the
  * turnstiles in the chain.
  *
- * Each time a thread is created, a turnstile is malloc'd and attached to
- * that thread.  When a thread blocks on a lock, if it is the first thread
- * to block, it lends its turnstile to the lock.  If the lock already has
- * a turnstile, then it gives its turnstile to the lock's turnstile's free
- * list.  When a thread is woken up, it takes a turnstile from the free list
- * if there are any other waiters.  If it is the only thread blocked on the
- * lock, then it reclaims the turnstile associated with the lock and removes
- * it from the hash table.
+ * Each time a thread is created, a turnstile is allocated in an UMA slab
+ * and is attached that thread. Whan a thread blocks on a lock, if it is
+ * the first thread to block, it lends its turnstile to the lock. If the
+ * lock alredy has a turnstile, then it gives its turnstile to the lock's
+ * turnstile's free list. When a thread is woken up, it takes a turnstile
+ * from the free list if there are any other waiters. If it is the only
+ * thread blocked on the lock, then it reclaims the turnstile associated
+ * with the lock and removes it from the hash table.
  */
 
 #include <sys/cdefs.h>
@@ -67,7 +67,6 @@
 #include <sys/kernel.h>
 #include <sys/ktr.h>
 #include <sys/lock.h>
-#include <sys/malloc.h>
 #include <sys/mutex.h>
 #include <sys/proc.h>
 #include <sys/queue.h>
@@ -75,6 +74,8 @@
 #include <sys/sysctl.h>
 #include <sys/turnstile.h>
 
+#include <vm/uma.h>
+
 #ifdef DDB
 #include <sys/kdb.h>
 #include <ddb/ddb.h>
@@ -141,8 +142,7 @@
 #endif
 static struct mtx td_contested_lock;
 static struct turnstile_chain turnstile_chains[TC_TABLESIZE];
-
-static MALLOC_DEFINE(M_TURNSTILE, "turnstiles", "turnstiles");
+static uma_zone_t turnstile_zone;
 
 /*
  * Prototypes for non-exported routines.
@@ -156,6 +156,8 @@
 		    struct thread *td);
 static struct thread *turnstile_first_waiter(struct turnstile *ts);
 static void	turnstile_setowner(struct turnstile *ts, struct thread *owner);
+static int	turnstile_init(void *mem, int size, int flags);
+static void	turnstile_fini(void *mem, int size);
 
 /*
  * Walks the chain of turnstiles and their owners to propagate the priority
@@ -376,6 +378,8 @@
 static void
 init_turnstile0(void *dummy)
 {
+	turnstile_zone = uma_zcreate("TURNSTILE", sizeof(struct turnstile),
+	    NULL, NULL, turnstile_init, turnstile_fini, SYNC_ALIGN, 0);
 
 	thread0.td_turnstile = turnstile_alloc();
 }
@@ -444,33 +448,53 @@
 }
 
 /*
- * Malloc a turnstile for a new thread, initialize it and return it.
+ * Initialize a turnstile in its UMA slab.
  */
-struct turnstile *
-turnstile_alloc(void)
+static int
+turnstile_init(void *mem, int size, int flags)
 {
 	struct turnstile *ts;
 
-	ts = malloc(sizeof(struct turnstile), M_TURNSTILE, M_WAITOK | M_ZERO);
+	bzero(mem, size);
+	ts = mem;
 	TAILQ_INIT(&ts->ts_blocked[TS_EXCLUSIVE_QUEUE]);
 	TAILQ_INIT(&ts->ts_blocked[TS_SHARED_QUEUE]);
 	TAILQ_INIT(&ts->ts_pending);
 	LIST_INIT(&ts->ts_free);
-	return (ts);
+
+	return(0);
 }
 
 /*
- * Free a turnstile when a thread is destroyed.
+ * Free a turnstile in its UMA slab.
  */
-void
-turnstile_free(struct turnstile *ts)
+static void
+turnstile_fini(void *mem, int size)
 {
+	struct trunstile *ts;
 
-	MPASS(ts != NULL);
+	ts = mem;
 	MPASS(TAILQ_EMPTY(&ts->ts_blocked[TS_EXCLUSIVE_QUEUE]));
 	MPASS(TAILQ_EMPTY(&ts->ts_blocked[TS_SHARED_QUEUE]));
 	MPASS(TAILQ_EMPTY(&ts->ts_pending));
-	free(ts, M_TURNSTILE);
+}
+
+/*
+ * Alloc an UMA slab for a new thread, initialize it and return it.
+ */
+struct turnstile *
+turnstile_alloc(void)
+{
+	return(uma_zalloc(turnstile_zone, M_WAITOK));
+}
+
+/*
+ * Free the allocated UMA slab when a thread is destroyed.
+ */
+void
+turnstile_free(struct turnstile *ts)
+{
+	uma_zfree(turnstile_zone, ts);
 }
 
 /*
