cvs commit: src/sys/fs/specfs spec_vnops.c

Mike Silbersack silby at silby.com
Wed Sep 3 23:05:52 PDT 2003


On Wed, 27 Aug 2003, Jeff Roberson wrote:

> It uses an 8 bit index to identify individual items in a slab.  This is to
> save space in place of the full pointer that is used in traditional slab
> allocators.  With an 8 bit index your smallest allocation on 4k pages is
> 16 bytes and 32 bytes on 8k.  It'd be 128 bytes on 32k.  You're going to
> have to conditionally compile UMA with 16bit indexes.
>
> Cheers,
> Jeff

You can't just change the index to 16 bits, it'll break.  I've attached a
patch which allows you to play with the freelist type freely... I don't
have any immediate plans to commit it (now that I'm sidetracked onto other
things), but I think it's solid.

Mike "Silby" Silbersack
-------------- next part --------------
diff -u -r /usr/src/sys.old/vm/uma.h /usr/src/sys/vm/uma.h
--- /usr/src/sys.old/vm/uma.h	Mon Aug 11 16:57:15 2003
+++ /usr/src/sys/vm/uma.h	Sat Aug 16 02:19:43 2003
@@ -39,6 +39,7 @@
 #include <sys/malloc.h>		/* For M_* */
 
 /* User visable parameters */
+#define UMA_MAX_OFFPAGE_ITEMS   (30)
 #define UMA_SMALLEST_UNIT       (PAGE_SIZE / 256) /* Smallest item allocated */
 
 /* Types and type defs */
diff -u -r /usr/src/sys.old/vm/uma_core.c /usr/src/sys/vm/uma_core.c
--- /usr/src/sys.old/vm/uma_core.c	Mon Aug 11 16:57:14 2003
+++ /usr/src/sys/vm/uma_core.c	Sat Aug 16 02:18:34 2003
@@ -694,6 +694,8 @@
 	ZONE_UNLOCK(zone);
 
 	if (zone->uz_flags & UMA_ZFLAG_OFFPAGE) {
+		if (zone->uz_ipers > UMA_MAX_OFFPAGE_ITEMS)
+			panic("Too many offpage items requested");
 		slab = uma_zalloc_internal(slabzone, NULL, wait);
 		if (slab == NULL) {
 			ZONE_LOCK(zone);
@@ -935,7 +937,8 @@
 
 	zone->uz_rsize = rsize;
 
-	rsize += 1;	/* Account for the byte of linkage */
+	/* Account for linkage */
+	rsize += sizeof(((struct uma_slab *) 0)->us_freelist[0]);
 	zone->uz_ipers = (UMA_SLAB_SIZE - sizeof(struct uma_slab)) / rsize;
 	zone->uz_ppera = 1;
 
@@ -955,7 +958,8 @@
 		    (zone->uz_flags & UMA_ZFLAG_CACHEONLY))
 			return;
 		ipers = UMA_SLAB_SIZE / zone->uz_rsize;
-		if (ipers > zone->uz_ipers) {
+		if ((ipers > zone->uz_ipers) &&
+		    (ipers <= UMA_MAX_OFFPAGE_ITEMS)) {
 			zone->uz_flags |= UMA_ZFLAG_OFFPAGE;
 			if ((zone->uz_flags & UMA_ZFLAG_MALLOC) == 0)
 				zone->uz_flags |= UMA_ZFLAG_HASH;
@@ -1078,7 +1082,8 @@
 		int waste;
 
 		/* Size of the slab struct and free list */
-		totsize = sizeof(struct uma_slab) + zone->uz_ipers;
+		totsize = sizeof(struct uma_slab) + zone->uz_ipers *
+			sizeof(((struct uma_slab *) 0)->us_freelist[0]);
 		if (totsize & UMA_ALIGN_PTR)
 			totsize = (totsize & ~UMA_ALIGN_PTR) +
 			    (UMA_ALIGN_PTR + 1);
@@ -1098,8 +1103,8 @@
 			zone->uz_cacheoff = 0;
 		} 
 
-		totsize = zone->uz_pgoff + sizeof(struct uma_slab)
-		    + zone->uz_ipers;
+		totsize = zone->uz_pgoff + sizeof(struct uma_slab) +
+		    zone->uz_ipers * sizeof(((struct uma_slab *) 0)->us_freelist[0]);
 		/* I don't think it's possible, but I'll make sure anyway */
 		if (totsize > UMA_SLAB_SIZE) {
 			printf("zone %s ipers %d rsize %d size %d\n",
@@ -1249,11 +1254,8 @@
 	 * This is the max number of free list items we'll have with
 	 * offpage slabs.
 	 */
-
-	slabsize = UMA_SLAB_SIZE - sizeof(struct uma_slab);
-	slabsize /= UMA_MAX_WASTE;
-	slabsize++;			/* In case there it's rounded */
-	slabsize += sizeof(struct uma_slab);
+	slabsize = sizeof(struct uma_slab) + UMA_MAX_OFFPAGE_ITEMS *
+		sizeof(((struct uma_slab *) 0)->us_freelist[0]);
 
 	/* Now make a zone for slab headers */
 	slabzone = uma_zcreate("UMA Slabs",
diff -u -r /usr/src/sys.old/vm/uma_int.h /usr/src/sys/vm/uma_int.h
--- /usr/src/sys.old/vm/uma_int.h	Mon Aug 11 16:57:15 2003
+++ /usr/src/sys/vm/uma_int.h	Fri Aug 15 22:49:24 2003
@@ -151,7 +151,7 @@
 	u_int8_t	us_flags;		/* Page flags see uma.h */
 	u_int8_t	us_freecount;	/* How many are free? */
 	u_int8_t	us_firstfree;	/* First free item index */
-	u_int8_t	us_freelist[1];	/* Free List (actually larger) */
+	u_int32_t	us_freelist[1];	/* Free List (actually larger) */
 };
 
 #define us_link	us_type._us_link


More information about the cvs-src mailing list