diff options
author | Sasha Levin <sasha.levin@oracle.com> | 2013-04-28 22:30:08 -0400 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2013-04-28 23:17:05 -0400 |
commit | 55257d72bd1c51f25106350f4983ec19f62ed1fa (patch) | |
tree | 5a8017d9fbebfe3f225a77bc2aabae2d4a6f859d | |
parent | 6b39271746de131366a14bcf04f5740cdc4abdef (diff) |
virtio-net: fill only rx queues which are being used
Due to MQ support we may allocate a whole bunch of rx queues but
never use them. With this patch we'll safe the space used by
the receive buffers until they are actually in use:
sh-4.2# free -h
total used free shared buffers cached
Mem: 490M 35M 455M 0B 0B 4.1M
-/+ buffers/cache: 31M 459M
Swap: 0B 0B 0B
sh-4.2# ethtool -L eth0 combined 8
sh-4.2# free -h
total used free shared buffers cached
Mem: 490M 162M 327M 0B 0B 4.1M
-/+ buffers/cache: 158M 331M
Swap: 0B 0B 0B
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
-rw-r--r-- | drivers/net/virtio_net.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index d88d4366d9ac..b082e1c39031 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c | |||
@@ -581,7 +581,7 @@ static void refill_work(struct work_struct *work) | |||
581 | bool still_empty; | 581 | bool still_empty; |
582 | int i; | 582 | int i; |
583 | 583 | ||
584 | for (i = 0; i < vi->max_queue_pairs; i++) { | 584 | for (i = 0; i < vi->curr_queue_pairs; i++) { |
585 | struct receive_queue *rq = &vi->rq[i]; | 585 | struct receive_queue *rq = &vi->rq[i]; |
586 | 586 | ||
587 | napi_disable(&rq->napi); | 587 | napi_disable(&rq->napi); |
@@ -636,7 +636,7 @@ static int virtnet_open(struct net_device *dev) | |||
636 | struct virtnet_info *vi = netdev_priv(dev); | 636 | struct virtnet_info *vi = netdev_priv(dev); |
637 | int i; | 637 | int i; |
638 | 638 | ||
639 | for (i = 0; i < vi->max_queue_pairs; i++) { | 639 | for (i = 0; i < vi->curr_queue_pairs; i++) { |
640 | /* Make sure we have some buffers: if oom use wq. */ | 640 | /* Make sure we have some buffers: if oom use wq. */ |
641 | if (!try_fill_recv(&vi->rq[i], GFP_KERNEL)) | 641 | if (!try_fill_recv(&vi->rq[i], GFP_KERNEL)) |
642 | schedule_delayed_work(&vi->refill, 0); | 642 | schedule_delayed_work(&vi->refill, 0); |
@@ -900,6 +900,7 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs) | |||
900 | struct scatterlist sg; | 900 | struct scatterlist sg; |
901 | struct virtio_net_ctrl_mq s; | 901 | struct virtio_net_ctrl_mq s; |
902 | struct net_device *dev = vi->dev; | 902 | struct net_device *dev = vi->dev; |
903 | int i; | ||
903 | 904 | ||
904 | if (!vi->has_cvq || !virtio_has_feature(vi->vdev, VIRTIO_NET_F_MQ)) | 905 | if (!vi->has_cvq || !virtio_has_feature(vi->vdev, VIRTIO_NET_F_MQ)) |
905 | return 0; | 906 | return 0; |
@@ -912,8 +913,12 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs) | |||
912 | dev_warn(&dev->dev, "Fail to set num of queue pairs to %d\n", | 913 | dev_warn(&dev->dev, "Fail to set num of queue pairs to %d\n", |
913 | queue_pairs); | 914 | queue_pairs); |
914 | return -EINVAL; | 915 | return -EINVAL; |
915 | } else | 916 | } else { |
917 | for (i = vi->curr_queue_pairs; i < queue_pairs; i++) | ||
918 | if (!try_fill_recv(&vi->rq[i], GFP_KERNEL)) | ||
919 | schedule_delayed_work(&vi->refill, 0); | ||
916 | vi->curr_queue_pairs = queue_pairs; | 920 | vi->curr_queue_pairs = queue_pairs; |
921 | } | ||
917 | 922 | ||
918 | return 0; | 923 | return 0; |
919 | } | 924 | } |
@@ -1566,7 +1571,7 @@ static int virtnet_probe(struct virtio_device *vdev) | |||
1566 | } | 1571 | } |
1567 | 1572 | ||
1568 | /* Last of all, set up some receive buffers. */ | 1573 | /* Last of all, set up some receive buffers. */ |
1569 | for (i = 0; i < vi->max_queue_pairs; i++) { | 1574 | for (i = 0; i < vi->curr_queue_pairs; i++) { |
1570 | try_fill_recv(&vi->rq[i], GFP_KERNEL); | 1575 | try_fill_recv(&vi->rq[i], GFP_KERNEL); |
1571 | 1576 | ||
1572 | /* If we didn't even get one input buffer, we're useless. */ | 1577 | /* If we didn't even get one input buffer, we're useless. */ |
@@ -1690,7 +1695,7 @@ static int virtnet_restore(struct virtio_device *vdev) | |||
1690 | 1695 | ||
1691 | netif_device_attach(vi->dev); | 1696 | netif_device_attach(vi->dev); |
1692 | 1697 | ||
1693 | for (i = 0; i < vi->max_queue_pairs; i++) | 1698 | for (i = 0; i < vi->curr_queue_pairs; i++) |
1694 | if (!try_fill_recv(&vi->rq[i], GFP_KERNEL)) | 1699 | if (!try_fill_recv(&vi->rq[i], GFP_KERNEL)) |
1695 | schedule_delayed_work(&vi->refill, 0); | 1700 | schedule_delayed_work(&vi->refill, 0); |
1696 | 1701 | ||