Please review: lazy ext refcount initialization

Navdeep Parhar np at FreeBSD.org
Thu Aug 29 22:58:34 UTC 2013


I'd like to merge r254342 from user/np/cxl_tuning to head if there are
no objections.

http://svnweb.freebsd.org/base/user/np/cxl_tuning/sys/kern/kern_mbuf.c?r1=254334&r2=254342&diff_format=u
http://svnweb.freebsd.org/base/user/np/cxl_tuning/sys/sys/mbuf.h?r1=254334&r2=254342&diff_format=u

---------------------
Perform lazy initialization of a cluster's refcount if possible.  This
doesn't change anything for the common cases where the constructor is
given an mbuf to attach to the cluster, or when the cluster is obtained
with m_cljget(NULL, ...) and attached later with m_cljset().  But it
allows for an alternate usage scenario where the cluster is managed
EXT_EXTREF style without ever having to look up its "usual" refcount via
uma_find_refcnt.
---------------------

Regards,
Navdeep

diff -r 9753d3e51363 -r c9388a59fba6 sys/kern/kern_mbuf.c
--- a/sys/kern/kern_mbuf.c	Thu Aug 29 11:16:04 2013 -0700
+++ b/sys/kern/kern_mbuf.c	Thu Aug 29 11:16:04 2013 -0700
@@ -503,8 +503,6 @@ mb_dtor_pack(void *mem, int size, void *
 static int
 mb_ctor_clust(void *mem, int size, void *arg, int how)
 {
-	struct mbuf *m;
-	u_int *refcnt;
 	int type;
 	uma_zone_t zone;

@@ -535,10 +533,11 @@ mb_ctor_clust(void *mem, int size, void
 		break;
 	}

-	m = (struct mbuf *)arg;
-	refcnt = uma_find_refcnt(zone, mem);
-	*refcnt = 1;
-	if (m != NULL) {
+	if (arg != NULL) {
+		struct mbuf *m = arg;
+		u_int *refcnt = uma_find_refcnt(zone, mem);
+
+		*refcnt = 1;
 		m->m_ext.ext_buf = (caddr_t)mem;
 		m->m_data = m->m_ext.ext_buf;
 		m->m_flags |= M_EXT;
@@ -549,6 +548,10 @@ mb_ctor_clust(void *mem, int size, void
 		m->m_ext.ext_type = type;
 		m->m_ext.ext_flags = 0;
 		m->m_ext.ref_cnt = refcnt;
+	} else {
+#ifdef INVARIANTS
+		*uma_find_refcnt(zone, mem) = 0;
+#endif
 	}

 	return (0);
diff -r 9753d3e51363 -r c9388a59fba6 sys/sys/mbuf.h
--- a/sys/sys/mbuf.h	Thu Aug 29 11:16:04 2013 -0700
+++ b/sys/sys/mbuf.h	Thu Aug 29 11:16:04 2013 -0700
@@ -721,6 +721,7 @@ m_cljset(struct mbuf *m, void *cl, int t
 	m->m_ext.ext_type = type;
 	m->m_ext.ext_flags = 0;
 	m->m_ext.ref_cnt = uma_find_refcnt(zone, cl);
+	*m->m_ext.ref_cnt = 1;
 	m->m_flags |= M_EXT;

 }



More information about the freebsd-net mailing list