mbuf: add explanation for confusing checks when freeing
[dpdk.git] / lib / librte_mbuf / rte_mbuf.h
index 6b1e50d..0265172 100644 (file)
@@ -285,11 +285,10 @@ struct rte_mbuf {
                             PKT_RX_FDIR_* flag in ol_flags. */
                } fdir;           /**< Filter identifier if FDIR enabled */
                uint32_t sched;   /**< Hierarchical scheduler */
-               uint32_t usr;     /**< User defined tags. See @rte_distributor_process */
+               uint32_t usr;     /**< User defined tags. See rte_distributor_process() */
        } hash;                   /**< hash information */
 
-       /* sequence number - field used in distributor and reorder library */
-       uint32_t seqn;
+       uint32_t seqn; /**< Sequence number. See also rte_reorder_insert() */
 
        /* second cache line - fields only used in slow path or on TX */
        MARKER cacheline1 __rte_cache_aligned;
@@ -765,6 +764,16 @@ __rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 {
        __rte_mbuf_sanity_check(m, 0);
 
+       /*
+        * Check to see if this is the last reference to the mbuf.
+        * Note: the double check here is deliberate. If the ref_cnt is "atomic"
+        * the call to "refcnt_update" is a very expensive operation, so we
+        * don't want to call it in the case where we know we are the holder
+        * of the last reference to this mbuf i.e. ref_cnt == 1.
+        * If however, ref_cnt != 1, it's still possible that we may still be
+        * the final decrementer of the count, so we need to check that
+        * result also, to make sure the mbuf is freed properly.
+        */
        if (likely (rte_mbuf_refcnt_read(m) == 1) ||
                        likely (rte_mbuf_refcnt_update(m, -1) == 0)) {