DPDK patches and discussions
 help / color / mirror / Atom feed
* Re: [dpdk-dev] [PATCH v2] mbuf: optimize rte_mbuf_refcnt_update
@ 2015-12-27  9:39 Hanoch Haim (hhaim)
  2016-01-04 13:53 ` Olivier MATZ
  0 siblings, 1 reply; 12+ messages in thread
From: Hanoch Haim (hhaim) @ 2015-12-27  9:39 UTC (permalink / raw)
  To: bruce.richardson
  Cc: dev, Hanoch Haim (hhaim), Ido Barnea (ibarnea), Itay Marom (imarom)

Hi Bruce,

I'm Hanoch from Cisco Systems works for  the https://github.com/cisco-system-traffic-generator/trex-core traffic generator project.

While upgrading from DPDK 1.8 to 2.2 Ido found that the following commit creates a mbuf corruption and result in Tx hang



commit f20b50b946da9070d21e392e4dbc7d9f68bc983e

Author: Olivier Matz <olivier.matz@6wind.com>

Date:   Mon Jun 8 16:57:22 2015 +0200



Looking at the change it is clear why there is an issue, wanted to get your input.



Init

-----

alloc const mbuf  ==> mbuf-a (ref=1)



Simple case that works

---------------------



thread 1 , tx: alloc-mbuf->attach(mbuf-a) (ref=2)  inc- non atomic

thread 1 , tx: alloc-mbuf->attach(mbuf-a) (ref32)  inc- atomic

thread 1 , drv : free()                    (ref=2) dec- atomic

thread 1 , drv : free()                    (ref=3) dec - non atomic





Simple case that does not work

---------------------



Both do that in parallel



thread 2 tx : alloc-mbuf->attach(mbuf-a)  (ref=2)  inc- non atomic

thread 1 tx : alloc-mbuf->attach(mbuf-a)  (ref=2)  inc- non atomic



  ==> ref in corrupted



thread 1 drv : free()                    (ref=0)   - free

thread 1 drv : free()                    (ref=-1)  - ???





Just as a side note that in our case we could benefit from this optimization by making a small change in our code, as our common case could be alloc/free of simple mbuf and in such scenario there is no atomic operation in both cases. But I think the general case is broken.



Could you explain what was your use case or this optimization? Is it a valid example the aforementioned example



thanks,

Hanoh

Cisco Systems







On Mon, Jun 08, 2015 at 04:57:22PM +0200, Olivier Matz wrote:

> In __rte_pktmbuf_prefree_seg(), there was an optimization to avoid using

> a costly atomic operation when updating the mbuf reference counter if

> its value is 1. Indeed, it means that we are the only owner of the mbuf,

> and therefore nobody can change it at the same time.

>

> We can generalize this optimization directly in rte_mbuf_refcnt_update()

> so the other callers of this function, like rte_pktmbuf_attach(), can

> also take advantage of this optimization.

>

> Signed-off-by: Olivier Matz <olivier.matz at 6wind.com<http://dpdk.org/ml/listinfo/dev>>



Acked-by: Bruce Richardson <bruce.richardson at intel.com<http://dpdk.org/ml/listinfo/dev>>


Hanoh

^ permalink raw reply	[flat|nested] 12+ messages in thread
* [dpdk-dev] [PATCH] mbuf: optimize first reference increment in rte_pktmbuf_attach
@ 2015-06-01  9:32 Olivier Matz
  2015-06-08 14:57 ` [dpdk-dev] [PATCH v2] mbuf: optimize rte_mbuf_refcnt_update Olivier Matz
  0 siblings, 1 reply; 12+ messages in thread
From: Olivier Matz @ 2015-06-01  9:32 UTC (permalink / raw)
  To: dev

As it's done in __rte_pktmbuf_prefree_seg(), we can avoid using an
atomic increment in rte_pktmbuf_attach() by checking if we are the
only owner of the mbuf first.

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---
 lib/librte_mbuf/rte_mbuf.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h
index ab6de67..cea35b7 100644
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -838,7 +838,11 @@ static inline void rte_pktmbuf_attach(struct rte_mbuf *mi, struct rte_mbuf *m)
 	else
 		md = rte_mbuf_from_indirect(m);
 
-	rte_mbuf_refcnt_update(md, 1);
+	/* optimize the case where we are the only owner */
+	if (likely(rte_mbuf_refcnt_read(md) == 1))
+		rte_mbuf_refcnt_set(md, 2);
+	else
+		rte_mbuf_refcnt_update(md, 1);
 	mi->priv_size = m->priv_size;
 	mi->buf_physaddr = m->buf_physaddr;
 	mi->buf_addr = m->buf_addr;
-- 
2.1.4

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

end of thread, other threads:[~2016-01-13 16:40 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-27  9:39 [dpdk-dev] [PATCH v2] mbuf: optimize rte_mbuf_refcnt_update Hanoch Haim (hhaim)
2016-01-04 13:53 ` Olivier MATZ
2016-01-04 14:43   ` Hanoch Haim (hhaim)
2016-01-05 10:57     ` Olivier MATZ
2016-01-05 11:11       ` Hanoch Haim (hhaim)
2016-01-05 12:12         ` Olivier MATZ
2016-01-13 11:48         ` Bruce Richardson
2016-01-13 16:28           ` Hanoch Haim (hhaim)
2016-01-13 16:40             ` Bruce Richardson
  -- strict thread matches above, loose matches on Subject: below --
2015-06-01  9:32 [dpdk-dev] [PATCH] mbuf: optimize first reference increment in rte_pktmbuf_attach Olivier Matz
2015-06-08 14:57 ` [dpdk-dev] [PATCH v2] mbuf: optimize rte_mbuf_refcnt_update Olivier Matz
2015-06-09 12:57   ` Bruce Richardson
2015-06-12 14:10     ` Thomas Monjalon

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