[dpdk-dev] [PATCH] app: fix refcnt in mbuf allocation

Han, Dongsu dongsuh at cs.cmu.edu
Mon May 6 15:28:33 CEST 2013


Sounds good. With the two bug fixes I submitted txonly now runs perfectly.
Thanks!
-Dongsu
On May 6, 2013 8:47 AM, "Thomas Monjalon" <thomas.monjalon at 6wind.com> wrote:

> 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.
>
> Signed-off-by: Dongsu Han <dongsuh at cs.cmu.edu>
> Signed-off-by: Thomas Monjalon <thomas.monjalon at 6wind.com>
> ---
>  app/test-pmd/txonly.c |   17 ++---------------
>  1 file changed, 2 insertions(+), 15 deletions(-)
>
> diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
> index d7c8c31..53f7138 100644
> --- a/app/test-pmd/txonly.c
> +++ b/app/test-pmd/txonly.c
> @@ -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);
> --
> 1.7.10.4
>
> _______________________________________________
> dev mailing list
> dev at dpdk.org
> http://dpdk.org/ml/listinfo/dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://dpdk.org/ml/archives/dev/attachments/20130506/cb5de9f9/attachment.html>


More information about the dev mailing list