Skip to contentSkip to conversation

suggested patch: testpmd txonly mbuf_alloc does not increment refcnt

PATCH In review Han, Dongsu 4 participants 9 messages May 2, 2013 – May 6, 2013 7 messages not in the archive

lore
Share & tools
lore
#0 lore raw

Hi dpdk-dev,
test-pmd txonly leaks mbuf from the pool.
tx_mbuf_alloc does not change the refcnt and the refcnt is 0 when it is first allocated.

However, rte_pktmbuf_free_seg called by the driver's xmit code decrements
reference count to -1. So mbuf never goes back to the pool.

As a result, txonly can't send packets after it exhausts the mempool.
There might be multiple ways to fix this. I decided not to touch memory management.

Thanks,
-Dongsu Han

---

app/test-pmd/txonly.c +0 -0
index d7c8c31..ee673e5 100644
@@ -92,14 +92,7 @@ static struct udp_hdr pkt_udp_hdr; /**< UDP header of

transmitted packets. */
static inline struct rte_mbuf *
tx_mbuf_alloc(struct rte_mempool *mp)
{
- struct rte_mbuf *m;
- void *mb;
-
- if (rte_mempool_get(mp, &mb) < 0)
- return NULL;

-       m = (struct rte_mbuf *)mb;
-       __rte_mbuf_sanity_check(m, RTE_MBUF_PKT, 1);
-       return m;
+       return rte_pktmbuf_alloc(mp);

}

_______________________________________________
dev mailing list
[email protected]
http://dpdk.org/ml/listinfo/dev

A message that is not in the archive (sent off-list or not yet received): CAAYH+dW3RenDv9=dn0Mtdubp0443OWqAqPYfHjGKfQcjQHNgxg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#2 lore raw

PATCH 1/1 app: fix refcnt in mbuf allocation

Hi Dongsu Han,

I think your fix is right.
I've just removed tx_mbuf_alloc() and directly called rte_pktmbuf_alloc() instead. Is it OK for you ?
Could you also review this (modified) description ?

Thank you

---

From: Dongsu Han <dongsuh at cs.cmu.edu>

test-pmd txonly leaks mbuf from the pool.
The function tx_mbuf_alloc() does not change the refcnt
and the refcnt is 0 when it is first allocated.
However, rte_pktmbuf_free_seg called by the driver's xmit code decrements reference count to -1. So mbuf never goes back to the pool. As a result, txonly can't send packets after it exhausts the mempool.

The function tx_mbuf_alloc() was getting mbuf directly from mempool and so was bypassing mbuf API.
By using the right API, refcnt is correctly handled among other initializations.

---
 app/test-pmd/txonly.c |   17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)
app/test-pmd/txonly.c +2 -15
index d7c8c31..53f7138 100644
@@ -89,19 +89,6 @@
 static struct ipv4_hdr  pkt_ip_hdr;  /**< IP header of transmitted packets. */
 static struct udp_hdr pkt_udp_hdr; /**< UDP header of transmitted packets. */
 
-static inline struct rte_mbuf *
-tx_mbuf_alloc(struct rte_mempool *mp)
-{
-	struct rte_mbuf *m;
-	void *mb;
-
-	if (rte_mempool_get(mp, &mb) < 0)
-		return NULL;
-	m = (struct rte_mbuf *)mb;
-	__rte_mbuf_sanity_check(m, RTE_MBUF_PKT, 1);
-	return m;
-}
-
 static void
 copy_buf_to_pkt_segs(void* buf, unsigned len, struct rte_mbuf *pkt,
 		     unsigned offset)
@@ -223,7 +210,7 @@ pkt_burst_transmit(struct fwd_stream *fs)
 	vlan_tci = ports[fs->tx_port].tx_vlan_id;
 	ol_flags = ports[fs->tx_port].tx_ol_flags;
 	for (nb_pkt = 0; nb_pkt < nb_pkt_per_burst; nb_pkt++) {
-		pkt = tx_mbuf_alloc(mbp);
+		pkt = rte_pktmbuf_alloc(mbp);
 		if (pkt == NULL) {
 		nomore_mbuf:
 			if (nb_pkt == 0)
@@ -233,7 +220,7 @@ pkt_burst_transmit(struct fwd_stream *fs)
 		pkt->pkt.data_len = tx_pkt_seg_lengths[0];
 		pkt_seg = pkt;
 		for (i = 1; i < tx_pkt_nb_segs; i++) {
-			pkt_seg->pkt.next = tx_mbuf_alloc(mbp);
+			pkt_seg->pkt.next = rte_pktmbuf_alloc(mbp);
 			if (pkt_seg->pkt.next == NULL) {
 				pkt->pkt.nb_segs = i;
 				rte_pktmbuf_free(pkt);
Signature · 1 line
1.7.10.4

A message that is not in the archive (sent off-list or not yet received): 1367844470-15346-1-git-send-email-thomas.monjalon-pdR9zngts4EAvxtiuMwx3w@public.gmane.org

#4 lore raw

Re: [PATCH] app: fix refcnt in mbuf allocation

Sounds good. With the two bug fixes I submitted txonly now runs perfectly. Thanks!
-Dongsu

Quoted 79 lines · Thomas Monjalon

Hi Dongsu Han,

I think your fix is right.
I've just removed tx_mbuf_alloc() and directly called rte_pktmbuf_alloc() instead.
Is it OK for you ?
Could you also review this (modified) description ?

Thank you

---

From: Dongsu Han <dongsuh at cs.cmu.edu>

test-pmd txonly leaks mbuf from the pool.
The function tx_mbuf_alloc() does not change the refcnt
and the refcnt is 0 when it is first allocated.
However, rte_pktmbuf_free_seg called by the driver's xmit code decrements reference count to -1. So mbuf never goes back to the pool. As a result, txonly can't send packets after it exhausts the mempool.

The function tx_mbuf_alloc() was getting mbuf directly from mempool and so was bypassing mbuf API.
By using the right API, refcnt is correctly handled among other initializations.

---
 app/test-pmd/txonly.c |   17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)
app/test-pmd/txonly.c +0 -0
index d7c8c31..53f7138 100644
@@ -89,19 +89,6 @@
 static struct ipv4_hdr  pkt_ip_hdr;  /**< IP header of transmitted

packets. */
static struct udp_hdr pkt_udp_hdr; /**< UDP header of transmitted
packets. */

app/test-pmd/txonly.c +2 -16
-static inline struct rte_mbuf *
-tx_mbuf_alloc(struct rte_mempool *mp)
-{
-       struct rte_mbuf *m;
-       void *mb;
-
-       if (rte_mempool_get(mp, &mb) < 0)
-               return NULL;
-       m = (struct rte_mbuf *)mb;
-       __rte_mbuf_sanity_check(m, RTE_MBUF_PKT, 1);
-       return m;
-}
-
 static void
 copy_buf_to_pkt_segs(void* buf, unsigned len, struct rte_mbuf *pkt,
                     unsigned offset)
@@ -223,7 +210,7 @@ pkt_burst_transmit(struct fwd_stream *fs)
        vlan_tci = ports[fs->tx_port].tx_vlan_id;
        ol_flags = ports[fs->tx_port].tx_ol_flags;
        for (nb_pkt = 0; nb_pkt < nb_pkt_per_burst; nb_pkt++) {
-               pkt = tx_mbuf_alloc(mbp);
+               pkt = rte_pktmbuf_alloc(mbp);
                if (pkt == NULL) {
                nomore_mbuf:
                        if (nb_pkt == 0)
@@ -233,7 +220,7 @@ pkt_burst_transmit(struct fwd_stream *fs)
                pkt->pkt.data_len = tx_pkt_seg_lengths[0];
                pkt_seg = pkt;
                for (i = 1; i < tx_pkt_nb_segs; i++) {
-                       pkt_seg->pkt.next = tx_mbuf_alloc(mbp);
+                       pkt_seg->pkt.next = rte_pktmbuf_alloc(mbp);
                        if (pkt_seg->pkt.next == NULL) {
                                pkt->pkt.nb_segs = i;
                                rte_pktmbuf_free(pkt);
--

1.7.10.4

Quoted 5 lines

_______________________________________________
dev mailing list
[email protected]
http://dpdk.org/ml/listinfo/dev

_______________________________________________
dev mailing list
[email protected]
http://dpdk.org/ml/listinfo/dev

A message that is not in the archive (sent off-list or not yet received): CAAYH+dX-n2vbZh8P-by0Vk-sPn-E+ZSTMx1HJnKiHXgh-5G+wQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#6 lore raw

Re: [PATCH] app: fix refcnt in mbuf allocation

Hi all (replying below)

Quoted 12 lines · Dongsu

Sounds good. With the two bug fixes I submitted txonly now runs perfectly. Thanks!
-Dongsu

Quoted 7 lines · Thomas Monjalon

Hi Dongsu Han,

I think your fix is right.
I've just removed tx_mbuf_alloc() and directly called rte_pktmbuf_alloc() instead.
Is it OK for you ?
Could you also review this (modified) description ?

[...]

While using rte_pktmbuf_alloc() is the correct fix, it's much slower than __rte_mbuf_raw_alloc() due to the unnecessary call to rte_pktmbuf_reset().

Since testpmd is often used for performance testing, we should consider a wrapper function calling __rte_mbuf_raw_alloc() directly instead, as in rte_rxmbuf_alloc() implemented in igb and ixgbe PMDs.

Signature · 2 lines
Adrien Mazarguil
6WIND

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

Re: [PATCH] app: fix refcnt in mbuf allocation

In addition to this, we should probably clone pkt mbuf using rte_pktmbuf_clone()
and transmit the cloned packet. This will avoid having to copy the mac and IP headers.

-Dongsu

On Mon, May 6, 2013 at 9:56 AM, Adrien Mazarguil <[email protected]

Quoted 37 lines

wrote:

Hi all (replying below)

Quoted 1 line · Dongsu

Sounds good. With the two bug fixes I submitted txonly now runs

perfectly.

Quoted 3 lines

Thanks!
-Dongsu
On May 6, 2013 8:47 AM, "Thomas Monjalon" <[email protected]>

Quoted 5 lines · wrote:
Quoted 5 lines

Hi Dongsu Han,

I think your fix is right.
I've just removed tx_mbuf_alloc() and directly called

rte_pktmbuf_alloc()

Quoted 3 lines
Quoted 3 lines

instead.
Is it OK for you ?
Could you also review this (modified) description ?

[...]

While using rte_pktmbuf_alloc() is the correct fix, it's much slower than __rte_mbuf_raw_alloc() due to the unnecessary call to rte_pktmbuf_reset().

Since testpmd is often used for performance testing, we should consider a wrapper function calling __rte_mbuf_raw_alloc() directly instead, as in rte_rxmbuf_alloc() implemented in igb and ixgbe PMDs.

--
Adrien Mazarguil
6WIND
_______________________________________________
dev mailing list
[email protected]
http://dpdk.org/ml/listinfo/dev

A message that is not in the archive (sent off-list or not yet received): CAAYH+dWnQ_eP-evFv2ABL8s==Oq1VB0secy1Dj4ZH9BA6ac9wA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#10 lore raw

Re: app: fix refcnt in mbuf allocation

06/05/2013 17:47, Han, Dongsu :

Quoted 4 lines

In addition to this, we should probably clone pkt mbuf using rte_pktmbuf_clone()
and transmit the cloned packet. This will avoid having to copy the mac and IP headers.

Yes, it could be faster but it is not always possible because rte_pktmbuf_clone() is available only if the feature RTE_MBUF_SCATTER_GATHER is enabled.

Signature · 1 line
Thomas
#11 lore raw

PATCH 1/1 app: fix refcnt in mbuf allocation

In reply to a message not in the archive

From: Dongsu Han <[email protected]>

test-pmd txonly leaks mbuf from the pool.
The function tx_mbuf_alloc() does not change the refcnt
and the refcnt is 0 when it is first allocated.
However, rte_pktmbuf_free_seg called by the driver's xmit code decrements reference count to -1. So mbuf never goes back to the pool. As a result, txonly can't send packets after it exhausts the mempool.

The function tx_mbuf_alloc() was getting mbuf directly from mempool and so was bypassing mbuf API.
The dedicated function is rte_pktmbuf_alloc() but it is much slower because it does unnecessary initializations in rte_pktmbuf_reset().
By using the internal API __rte_mbuf_raw_alloc(), refcnt is correctly handled without adding too much overload.

---
 app/test-pmd/txonly.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
app/test-pmd/txonly.c +1 -4
index d7c8c31..e7c9a1a 100644
@@ -93,11 +93,8 @@ static inline struct rte_mbuf *
 tx_mbuf_alloc(struct rte_mempool *mp)
 {
 	struct rte_mbuf *m;
-	void *mb;
 
-	if (rte_mempool_get(mp, &mb) < 0)
-		return NULL;
-	m = (struct rte_mbuf *)mb;
+	m = __rte_mbuf_raw_alloc(mp);
 	__rte_mbuf_sanity_check(m, RTE_MBUF_PKT, 1);
 	return m;
 }
Signature · 1 line
1.7.10.4

A message that is not in the archive (sent off-list or not yet received): 1367856001-25036-1-git-send-email-thomas.monjalon-pdR9zngts4EAvxtiuMwx3w@public.gmane.org

#13 lore raw

Re: [PATCH] app: fix refcnt in mbuf allocation

Quoted 41 lines · Thomas Monjalon

From: Dongsu Han <[email protected]>

test-pmd txonly leaks mbuf from the pool.
The function tx_mbuf_alloc() does not change the refcnt
and the refcnt is 0 when it is first allocated.
However, rte_pktmbuf_free_seg called by the driver's xmit code decrements reference count to -1. So mbuf never goes back to the pool. As a result, txonly can't send packets after it exhausts the mempool.

The function tx_mbuf_alloc() was getting mbuf directly from mempool and so was bypassing mbuf API.
The dedicated function is rte_pktmbuf_alloc() but it is much slower because it does unnecessary initializations in rte_pktmbuf_reset().
By using the internal API __rte_mbuf_raw_alloc(), refcnt is correctly handled without adding too much overload.

---
 app/test-pmd/txonly.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
app/test-pmd/txonly.c +1 -4
index d7c8c31..e7c9a1a 100644
@@ -93,11 +93,8 @@ static inline struct rte_mbuf *
 tx_mbuf_alloc(struct rte_mempool *mp)
 {
 	struct rte_mbuf *m;
-	void *mb;
 
-	if (rte_mempool_get(mp, &mb) < 0)
-		return NULL;
-	m = (struct rte_mbuf *)mb;
+	m = __rte_mbuf_raw_alloc(mp);
 	__rte_mbuf_sanity_check(m, RTE_MBUF_PKT, 1);
 	return m;
 }
Signature · 1 line
1.7.10.4

Looks good.

Signature · 2 lines
Adrien Mazarguil
6WIND

A message that is not in the archive (sent off-list or not yet received): [email protected]

#15 lore raw

Re: [PATCH] app: fix refcnt in mbuf allocation

pushed

thank you all

Signature · 1 line
Thomas