physically contiguous jumbo frames

Alan Cox alc at cs.rice.edu
Sat Dec 1 13:33:04 PST 2007


The reimplementation of contigmalloc(9) in HEAD and RELENG_7 makes the 
allocation of physically contiguous jumbo frames a real possibility.  If 
you're using jumbo frames, please test the attached patch.  Andrew 
Gallatin has already tested this patch with mxge and asked that I bump 
__FreeBSD_version.

Thanks,
Alan

-------------- next part --------------
Index: kern/kern_mbuf.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_mbuf.c,v
retrieving revision 1.34
diff -p -u -r1.34 kern_mbuf.c
--- kern/kern_mbuf.c	26 Oct 2007 16:33:47 -0000	1.34
+++ kern/kern_mbuf.c	27 Nov 2007 11:25:59 -0000
@@ -166,6 +166,10 @@ static void	mb_zfini_pack(void *, int);
 
 static void	mb_reclaim(void *);
 static void	mbuf_init(void *);
+static void    *mbuf_jumbo_alloc(uma_zone_t, int, u_int8_t *, int);
+static void	mbuf_jumbo_free(void *, int, u_int8_t);
+
+static MALLOC_DEFINE(M_JUMBOFRAME, "jumboframes", "mbuf jumbo frame buffers");
 
 /* Ensure that MSIZE doesn't break dtom() - it must be a power of 2 */
 CTASSERT((((MSIZE - 1) ^ MSIZE) + 1) >> 1 == MSIZE);
@@ -226,6 +230,8 @@ mbuf_init(void *dummy)
 	    UMA_ALIGN_PTR, UMA_ZONE_REFCNT);
 	if (nmbjumbo9 > 0)
 		uma_zone_set_max(zone_jumbo9, nmbjumbo9);
+	uma_zone_set_allocf(zone_jumbo9, mbuf_jumbo_alloc);
+	uma_zone_set_freef(zone_jumbo9, mbuf_jumbo_free);
 
 	zone_jumbo16 = uma_zcreate(MBUF_JUMBO16_MEM_NAME, MJUM16BYTES,
 	    mb_ctor_clust, mb_dtor_clust,
@@ -237,6 +243,8 @@ mbuf_init(void *dummy)
 	    UMA_ALIGN_PTR, UMA_ZONE_REFCNT);
 	if (nmbjumbo16 > 0)
 		uma_zone_set_max(zone_jumbo16, nmbjumbo16);
+	uma_zone_set_allocf(zone_jumbo16, mbuf_jumbo_alloc);
+	uma_zone_set_freef(zone_jumbo16, mbuf_jumbo_free);
 
 	zone_ext_refcnt = uma_zcreate(MBUF_EXTREFCNT_MEM_NAME, sizeof(u_int),
 	    NULL, NULL,
@@ -274,6 +282,31 @@ mbuf_init(void *dummy)
 }
 
 /*
+ * UMA backend page allocator for the jumbo frame zones.
+ *
+ * Allocates kernel virtual memory that is backed by contiguous physical
+ * pages.
+ */
+static void *
+mbuf_jumbo_alloc(uma_zone_t zone, int bytes, u_int8_t *flags, int wait)
+{
+
+	*flags = UMA_SLAB_PRIV;
+	return (contigmalloc(bytes, M_JUMBOFRAME, wait, (vm_paddr_t)0,
+	    ~(vm_paddr_t)0, 1, 0));
+}
+
+/*
+ * UMA backend page deallocator for the jumbo frame zones.
+ */
+static void
+mbuf_jumbo_free(void *mem, int size, u_int8_t flags)
+{
+
+	contigfree(mem, size, M_JUMBOFRAME);
+}
+
+/*
  * Constructor for Mbuf master zone.
  *
  * The 'arg' pointer points to a mb_args structure which
Index: sys/param.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/param.h,v
retrieving revision 1.315
diff -p -u -r1.315 param.h
--- sys/param.h	28 Nov 2007 21:54:46 -0000	1.315
+++ sys/param.h	30 Nov 2007 18:34:29 -0000
@@ -57,7 +57,7 @@
  *		is created, otherwise 1.
  */
 #undef __FreeBSD_version
-#define __FreeBSD_version 800004	/* Master, propagated to newvers */
+#define __FreeBSD_version 800005	/* Master, propagated to newvers */
 
 #ifndef LOCORE
 #include <sys/types.h>


More information about the freebsd-net mailing list