Date: Thu, 29 Aug 2013 12:57:06 -0700 From: Navdeep Parhar <np@FreeBSD.org> To: freebsd-net@FreeBSD.org Subject: Please review: atomic updates to mbuf's external refcount Message-ID: <521FA792.9000807@FreeBSD.org>
next in thread | raw e-mail | index | archive | help
I'd like to merge r254341 from user/np/cxl_tuning to head if there are no objections. It eliminates a couple of iffy looking constructs in uipc_mbuf.c http://svnweb.freebsd.org/base/user/np/cxl_tuning/sys/kern/uipc_mbuf.c?r1=254334&r2=254341&diff_format=u --------------------- Always increment or decrement an mbuf's external refcount atomically. Always decrement it in mb_free_ext() so that an external free routine can safely assert the refcount is 0 (and not 0 or 1) when it's called. --------------------- Regards, Navdeep diff -r 9e9639a7df80 -r 9753d3e51363 sys/kern/uipc_mbuf.c --- a/sys/kern/uipc_mbuf.c Thu Aug 29 11:16:04 2013 -0700 +++ b/sys/kern/uipc_mbuf.c Thu Aug 29 11:16:04 2013 -0700 @@ -282,7 +282,7 @@ m_extadd(struct mbuf *mb, caddr_t buf, u /* * Non-directly-exported function to clean up after mbufs with M_EXT - * storage attached to them if the reference count hits 1. + * storage attached to them if the reference count hits 0. */ void mb_free_ext(struct mbuf *m) @@ -298,8 +298,7 @@ mb_free_ext(struct mbuf *m) skipmbuf = (m->m_flags & M_NOFREE); /* Free attached storage if this mbuf is the only reference to it. */ - if (*(m->m_ext.ref_cnt) == 1 || - atomic_fetchadd_int(m->m_ext.ref_cnt, -1) == 1) { + if (atomic_fetchadd_int(m->m_ext.ref_cnt, -1) == 1) { switch (m->m_ext.ext_type) { case EXT_PACKET: /* The packet zone is special. */ if (*(m->m_ext.ref_cnt) == 0) @@ -367,10 +366,7 @@ mb_dupcl(struct mbuf *n, struct mbuf *m) KASSERT(m->m_ext.ref_cnt != NULL, ("%s: ref_cnt not set", __func__)); KASSERT((n->m_flags & M_EXT) == 0, ("%s: M_EXT set", __func__)); - if (*(m->m_ext.ref_cnt) == 1) - *(m->m_ext.ref_cnt) += 1; - else - atomic_add_int(m->m_ext.ref_cnt, 1); + atomic_add_int(m->m_ext.ref_cnt, 1); n->m_ext.ext_buf = m->m_ext.ext_buf; n->m_ext.ext_free = m->m_ext.ext_free; n->m_ext.ext_arg1 = m->m_ext.ext_arg1;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?521FA792.9000807>