[PATCH v7 3/7] mbuf: record mbuf operations history
Morten Brørup
mb at smartsharesystems.com
Fri Oct 17 00:29:18 CEST 2025
> + /* Calculate total allocated mbufs */
> + uint64_t total_allocated = 0;
> + for (enum rte_mbuf_history_op op = RTE_MBUF_HISTORY_OP_LIB_ALLOC;
> + op < RTE_MBUF_HISTORY_OP_MAX; op++)
> + total_allocated += stats[op];
I might be overly cautious here, but the app (or driver) might have a bug, and mark the mbuf with OP_APP_FREE (or OP_PMD_FREE) without actually freeing the mbuf back to the mempool.
So you should only trust the mempool library (OP_LIB_FREE) to mark the mbuf as actually freed. I.e. start the loop at op = RTE_MBUF_HISTORY_OP_LIB_FREE.
The app/driver should eventually call rte_mbuf_raw_free_bulk() or similar to release the mbuf back to the mempool.
> +/**
> + * History operation types.
> + */
> +enum rte_mbuf_history_op {
> + RTE_MBUF_HISTORY_OP_NEVER = 0, /**< Initial state - never
> allocated */
> + RTE_MBUF_HISTORY_OP_LIB_FREE = 1, /**< Freed back to pool */
> + RTE_MBUF_HISTORY_OP_PMD_FREE = 2, /**< Freed by PMD */
> + RTE_MBUF_HISTORY_OP_APP_FREE = 3, /**< Freed by application */
> + /* With ops below, mbuf is considered allocated. */
> + RTE_MBUF_HISTORY_OP_LIB_ALLOC = 4, /**< Allocation in mbuf
> library */
> + RTE_MBUF_HISTORY_OP_PMD_ALLOC = 5, /**< Allocated by PMD for Rx
> */
> + RTE_MBUF_HISTORY_OP_APP_ALLOC = 6, /**< Allocated by application
> */
> + RTE_MBUF_HISTORY_OP_RX = 7, /**< Received */
> + RTE_MBUF_HISTORY_OP_TX = 8, /**< Sent */
> + RTE_MBUF_HISTORY_OP_TX_PREP = 9, /**< Being prepared before Tx
> */
> + RTE_MBUF_HISTORY_OP_TX_BUSY = 10, /**< Returned due to Tx busy
> */
> + RTE_MBUF_HISTORY_OP_ENQUEUE = 11, /**< Enqueued for processing
> */
> + RTE_MBUF_HISTORY_OP_DEQUEUE = 12, /**< Dequeued for processing
> */
> + /* 13, reserved for future */
> + RTE_MBUF_HISTORY_OP_USR2 = 14, /**< Application-defined
> event 2 */
> + RTE_MBUF_HISTORY_OP_USR1 = 15, /**< Application-defined
> event 1 */
> + RTE_MBUF_HISTORY_OP_MAX = 16, /**< Maximum number of
> operation types */
> +};
More information about the dev
mailing list