DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Morten Brørup" <mb@smartsharesystems.com>
To: <dev@dpdk.org>
Subject: [dpdk-dev] [RFC] mbuf: rte_pktmbuf_free() optimized for multi-seg packets
Date: Fri, 27 Sep 2019 12:42:47 +0200	[thread overview]
Message-ID: <98CBD80474FA8B44BF855DF32C47DC35B42AD5@smartserver.smartshare.dk> (raw)

Hi all,

The rte_pktmbuf_free() function could be optimized by freeing multiple segments in bulk using rte_mempool_put_bulk().

I got this idea while optimizing the rte_pktmbuf_free_bulk() function similarly, as suggested by Stephen Hemminger and Konstantin Ananyev.


If any of you DPDK performance freaks want to test this concept, here's some source code to get you started.


/**
 * @internal Size of the array holding mbufs from the same membool to be freed
 * in bulk.
 */
#define RTE_PKTMBUF_FREE_BULK_SZ 64

/**
 * @internal helper function for freeing a bulk of mbufs via an array holding
 * mbufs from the same mempool.
 */
static __rte_always_inline void
rte_pktmbuf_free_seg_via_array(struct rte_mbuf *m,
	struct rte_mbuf * * const free, unsigned int * const nb_free)
{
	m = rte_pktmbuf_prefree_seg(m);
	if (likely(m != NULL)) {
		if (*nb_free >= RTE_PKTMBUF_FREE_BULK_SZ ||
		    (*nb_free > 0 && m->pool != free[0]->pool)) {
			rte_mempool_put_bulk(free[0]->pool, (void **)free,
					     *nb_free);
			*nb_free = 0;
		}

		free[(*nb_free)++] = m;
	}
}

/**
 * Free a packet mbuf back into its original mempool.
 *
 * Free an mbuf, and all its segments in case of chained buffers. Each
 * segment is added back into its original mempool.
 *
 * @param m
 *   The packet mbuf to be freed. If NULL, the function does nothing.
 */
static inline void rte_pktmbuf_free(struct rte_mbuf *m)
{
	struct rte_mbuf *m_next, *free[RTE_PKTMBUF_FREE_BULK_SZ];
	unsigned int nb_free = 0;

	if (unlikely(m == NULL)) return;

	__rte_mbuf_sanity_check(m, 1);

	do {
		m_next = m->next;
		rte_pktmbuf_free_seg_via_array(m, free, &nb_free);
		m = m_next;
	} while (m != NULL);

	if (nb_free > 0)
		rte_mempool_put_bulk(free[0]->pool, (void **)free, nb_free);
}


Med venlig hilsen / kind regards

Morten Brørup
CTO


SmartShare Systems A/S
Tonsbakken 16-18
DK-2740 Skovlunde
Denmark

Office      +45 70 20 00 93
Direct      +45 89 93 50 22
Mobile     +45 25 40 82 12

mb@smartsharesystems.com
www.smartsharesystems.com


                 reply	other threads:[~2019-09-27 10:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=98CBD80474FA8B44BF855DF32C47DC35B42AD5@smartserver.smartshare.dk \
    --to=mb@smartsharesystems.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).