virtio-net: avoid unnecessary sg initialzation
Subsystems (4)
PATCH 1/1 virtio-net: avoid unnecessary sg initialzation
Usually an skb does not have up to MAX_SKB_FRAGS frags. So no need to initialize the unuse part of sg. This patch initialize the sg based on the real number it will used:
- during xmit, it could be inferred from nr_frags and can_push.
- for small receive buffer, it will also be 2.
Cc Michael S. Tsirkin <[email protected]>
Signed-off-by Jason Wang <[email protected]>
--- drivers/net/virtio_net.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/virtio_net.c +2 -2
@@ -540,7 +540,7 @@ static int add_recvbuf_small(struct virtnet_info *vi, struct receive_queue *rq,skb_put (skb,GOOD_PACKET_LEN ); hdr =skb_vnet_hdr (skb); -sg_init_table (rq->sg,MAX_SKB_FRAGS +2 ); +sg_init_table (rq->sg,2 );sg_set_buf (rq->sg, hdr, vi->hdr_len);skb_to_sgvec (skb, rq->sg +1 ,0 , skb->len);
@@ -893,7 +893,7 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb)if (vi->mergeable_rx_bufs) hdr->num_buffers =0 ; -sg_init_table (sq->sg,MAX_SKB_FRAGS +2 ); +sg_init_table (sq->sg,skb_shinfo (skb)->nr_frags + (can_push ?1 :2 ));if (can_push) {__skb_push (skb, hdr_len); num_sg =skb_to_sgvec (skb, sq->sg,0 , skb->len);
Signature · 1 line
2.1.4
David Miller
maintainerFrom: Jason Wang <[email protected]>
Date: Thu, 27 Aug 2015 14:53:06 +0800
Quoted 9 lines
Usually an skb does not have up to
MAX_SKB_FRAGSfrags. So no need to initialize the unuse part of sg. This patch initialize the sg based on the real number it will used:- during xmit, it could be inferred from
nr_fragsandcan_push.
- for small receive buffer, it will also be 2.Cc Michael S. Tsirkin <[email protected]>Signed-off-by Jason Wang <[email protected]>
This looks fine, thanks Jason.