Commit 0aea51c3 authored by Amit Shah's avatar Amit Shah Committed by Rusty Russell

virtio_net: Check for room in the vq before adding buffer

Saves us one cycle of alloc-add-free if the queue was full.
Signed-off-by: default avatarAmit Shah <amit.shah@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (modified)
parent 48925e37
...@@ -280,7 +280,7 @@ static bool try_fill_recv_maxbufs(struct virtnet_info *vi, gfp_t gfp) ...@@ -280,7 +280,7 @@ static bool try_fill_recv_maxbufs(struct virtnet_info *vi, gfp_t gfp)
bool oom = false; bool oom = false;
sg_init_table(sg, 2+MAX_SKB_FRAGS); sg_init_table(sg, 2+MAX_SKB_FRAGS);
for (;;) { do {
struct skb_vnet_hdr *hdr; struct skb_vnet_hdr *hdr;
skb = netdev_alloc_skb(vi->dev, MAX_PACKET_LEN + NET_IP_ALIGN); skb = netdev_alloc_skb(vi->dev, MAX_PACKET_LEN + NET_IP_ALIGN);
...@@ -323,7 +323,7 @@ static bool try_fill_recv_maxbufs(struct virtnet_info *vi, gfp_t gfp) ...@@ -323,7 +323,7 @@ static bool try_fill_recv_maxbufs(struct virtnet_info *vi, gfp_t gfp)
break; break;
} }
vi->num++; vi->num++;
} } while (err >= num);
if (unlikely(vi->num > vi->max)) if (unlikely(vi->num > vi->max))
vi->max = vi->num; vi->max = vi->num;
vi->rvq->vq_ops->kick(vi->rvq); vi->rvq->vq_ops->kick(vi->rvq);
...@@ -341,7 +341,7 @@ static bool try_fill_recv(struct virtnet_info *vi, gfp_t gfp) ...@@ -341,7 +341,7 @@ static bool try_fill_recv(struct virtnet_info *vi, gfp_t gfp)
if (!vi->mergeable_rx_bufs) if (!vi->mergeable_rx_bufs)
return try_fill_recv_maxbufs(vi, gfp); return try_fill_recv_maxbufs(vi, gfp);
for (;;) { do {
skb_frag_t *f; skb_frag_t *f;
skb = netdev_alloc_skb(vi->dev, GOOD_COPY_LEN + NET_IP_ALIGN); skb = netdev_alloc_skb(vi->dev, GOOD_COPY_LEN + NET_IP_ALIGN);
...@@ -375,7 +375,7 @@ static bool try_fill_recv(struct virtnet_info *vi, gfp_t gfp) ...@@ -375,7 +375,7 @@ static bool try_fill_recv(struct virtnet_info *vi, gfp_t gfp)
break; break;
} }
vi->num++; vi->num++;
} } while (err > 0);
if (unlikely(vi->num > vi->max)) if (unlikely(vi->num > vi->max))
vi->max = vi->num; vi->max = vi->num;
vi->rvq->vq_ops->kick(vi->rvq); vi->rvq->vq_ops->kick(vi->rvq);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment