dev.dpdk.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rte_mbuf: scattered pktmbufs freeing optimization
@ 2015-02-26 23:15 vadim.suraev-Re5JQEeQqe8AvxtiuMwx3w
       [not found] ` <1424992506-20484-1-git-send-email-vadim.suraev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: vadim.suraev-Re5JQEeQqe8AvxtiuMwx3w @ 2015-02-26 23:15 UTC (permalink / raw)
  To: dev-VfR2kkLFssw

From: "vadim.suraev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <vadim.suraev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

new function - rte_pktmbuf_free_bulk makes freeing long
scattered (chained) pktmbufs belonging to the same pool 
more optimal using rte_mempool_put_bulk rather than calling
rte_mempool_put for each segment. 
Inlike rte_pktmbuf_free, which calls rte_pktmbuf_free_seg,
this function calls __rte_pktmbuf_prefree_seg. If non-NULL
returned, the pointer is placed in an array. When array is
filled or when the last segment is processed, rte_mempool_put_bulk 
is called. In case of multiple producers, performs 3 times better.


Signed-off-by: vadim.suraev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <vadim.suraev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 lib/librte_mbuf/rte_mbuf.h |   55 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h
index 17ba791..1d6f848 100644
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -824,6 +824,61 @@ static inline void rte_pktmbuf_free(struct rte_mbuf *m)
 	}
 }
 
+/* This macro defines the size of max bulk of mbufs to free for rte_pktmbuf_free_bulk */
+#define MAX_MBUF_FREE_SIZE 32
+
+/* If RTE_LIBRTE_MBUF_DEBUG is enabled, checks if all mbufs must belong to the same mempool */
+#ifdef RTE_LIBRTE_MBUF_DEBUG
+
+#define RTE_MBUF_MEMPOOL_CHECK1(m) struct rte_mempool *first_buffers_mempool = (m) ? (m)->pool : NULL
+
+#define RTE_MBUF_MEMPOOL_CHECK2(m) RTE_MBUF_ASSERT(first_buffers_mempool == (m)->pool)
+
+#else
+
+#define RTE_MBUF_MEMPOOL_CHECK1(m)
+
+#define RTE_MBUF_MEMPOOL_CHECK2(m)
+
+#endif
+
+/**
+ * Free chained (scattered) mbuf into its original mempool.
+ *
+ * All the mbufs in the chain must belong to the same mempool.
+ *
+ * @param head
+ *   The head of mbufs to be freed chain
+ */
+
+static inline void __attribute__((always_inline))
+rte_pktmbuf_free_bulk(struct rte_mbuf *head)
+{
+    void *mbufs[MAX_MBUF_FREE_SIZE];
+    unsigned mbufs_count = 0;
+    struct rte_mbuf *next;
+
+    RTE_MBUF_MEMPOOL_CHECK1(head);
+
+    while(head) {
+        next = head->next;
+        head->next = NULL;
+        if(__rte_pktmbuf_prefree_seg(head)) {
+            RTE_MBUF_ASSERT(rte_mbuf_refcnt_read(head) == 0);
+            RTE_MBUF_MEMPOOL_CHECK2(head);
+            mbufs[mbufs_count++] = head;
+        }
+        head = next;
+        if(mbufs_count == MAX_MBUF_FREE_SIZE) {
+            rte_mempool_put_bulk(((struct rte_mbuf *)mbufs[0])->pool,mbufs,mbufs_count);
+            mbufs_count = 0;
+        }
+    }
+    if(mbufs_count > 0) {
+        rte_mempool_put_bulk(((struct rte_mbuf *)mbufs[0])->pool,mbufs,mbufs_count);
+    }
+}
+
 /**
  * Creates a "clone" of the given packet mbuf.
  *
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-03-09  8:38 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-26 23:15 [PATCH] rte_mbuf: scattered pktmbufs freeing optimization vadim.suraev-Re5JQEeQqe8AvxtiuMwx3w
     [not found] ` <1424992506-20484-1-git-send-email-vadim.suraev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-02-27  0:49   ` Stephen Hemminger
2015-02-27 11:17   ` Ananyev, Konstantin
     [not found]     ` <2601191342CEEE43887BDE71AB977258213F2C93-pww93C2UFcwu0RiL9chJVbfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2015-02-27 12:18       ` Vadim Suraev
     [not found]         ` <2601191342CEEE43887BDE71AB977258213F2E3D@irsmsx105.ger.corp.intel.com>
     [not found]           ` <2601191342CEEE43887BDE71AB977258213F2E3D-pww93C2UFcwu0RiL9chJVbfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2015-02-27 13:10             ` Ananyev, Konstantin
     [not found]         ` <CAJ0CJ8kJk5F+kygm1hZXX+d8dn0PmpQObyRHuA6uObkHEfMAxg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-02-27 13:20           ` Olivier MATZ
     [not found]             ` <54F06F3A.40401-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>
2015-02-27 17:09               ` Vadim Suraev
     [not found]                 ` <CAJ0CJ8=0LCSrBE4QYA1bdKaXRGdNDDhzhpbwJ4oSj_tT+t=CQA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-04  8:54                   ` Olivier MATZ
     [not found]                     ` <54F6C832.4070505-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>
2015-03-06 23:24                       ` Vadim Suraev
     [not found]                         ` <CAJ0CJ8nhhESK45c0vY4gxxg1O=1Mv-c=ht=ONEeOKNW9Ao6sHA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-09  8:38                           ` Olivier MATZ

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).