Skip to content

Commit

Permalink
netdev-dpdk: Fix memory leak in dpdk_do_tx_copy().
Browse files Browse the repository at this point in the history
This patch fixes a bug where rte_pktmbuf_alloc() would fail and
packets which succeeded to allocate memory with rte_pktmbuf_alloc()
would not be sent and leak memory.

Also, as a byproduct of using a local variable to record dropped
packets, this reduces the locking of the netdev's mutex when
multiple packets are dropped in dpdk_do_tx_copy().

Signed-off-by: Ryan Wilson <[email protected]>
Acked-by: Daniele Di Proietto <[email protected]>
Acked-by: Pravin B Shelar <[email protected]>
  • Loading branch information
Ryan Wilson authored and Pravin B Shelar committed Jun 30, 2014
1 parent 844f2d7 commit 175cf4d
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/netdev-dpdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,28 +661,25 @@ dpdk_do_tx_copy(struct netdev *netdev, struct dpif_packet ** pkts, int cnt)
{
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
struct rte_mbuf *mbufs[cnt];
int i, newcnt = 0;
int dropped = 0;
int newcnt = 0;
int i;

for (i = 0; i < cnt; i++) {
int size = ofpbuf_size(&pkts[i]->ofpbuf);
if (size > dev->max_packet_len) {
VLOG_WARN_RL(&rl, "Too big size %d max_packet_len %d",
(int)size , dev->max_packet_len);

ovs_mutex_lock(&dev->mutex);
dev->stats.tx_dropped++;
ovs_mutex_unlock(&dev->mutex);

dropped++;
continue;
}

mbufs[newcnt] = rte_pktmbuf_alloc(dev->dpdk_mp->mp);

if (!mbufs[newcnt]) {
ovs_mutex_lock(&dev->mutex);
dev->stats.tx_dropped++;
ovs_mutex_unlock(&dev->mutex);
return;
dropped += cnt - i;
break;
}

/* We have to do a copy for now */
Expand All @@ -694,6 +691,12 @@ dpdk_do_tx_copy(struct netdev *netdev, struct dpif_packet ** pkts, int cnt)
newcnt++;
}

if (dropped) {
ovs_mutex_lock(&dev->mutex);
dev->stats.tx_dropped += dropped;
ovs_mutex_unlock(&dev->mutex);
}

dpdk_queue_pkts(dev, NON_PMD_THREAD_TX_QUEUE, mbufs, newcnt);
dpdk_queue_flush(dev, NON_PMD_THREAD_TX_QUEUE);
}
Expand Down

0 comments on commit 175cf4d

Please sign in to comment.