vhost: logs sharing
commit309750fad51f17d1ec6195c5d8ad7d741596ddb6
authorJason Wang <jasowang@redhat.com>
Thu, 4 Jun 2015 09:28:46 +0000 (4 05:28 -0400)
committerMichael S. Tsirkin <mst@redhat.com>
Thu, 4 Jun 2015 10:44:49 +0000 (4 12:44 +0200)
treecc12aaf687a92a9d35870700035234e10dd6791c
parent6e7d82497dc8da7d420c8fa6632d759e08a18bc3
vhost: logs sharing

Currently we allocate one vhost log per vhost device. This is sub
optimal when:

- Guest has several device with vhost as backend
- Guest has multiqueue devices

In the above cases, we can avoid the memory allocation by sharing a
single vhost log among all the vhost devices. This is done through:

- Introducing a new vhost_log structure with refcnt inside.
- Using a global pointer to vhost_log structure that will be used. And
  introduce helper to get the log with expected log size and helper to
- drop the refcnt to the old log.
- Each vhost device still keep track of a pointer to the log that was
  used.

With above, if no resize happens, all vhost device will share a single
vhost log. During resize, a new vhost_log structure will be allocated
and made for the global pointer. And each vhost devices will drop the
refcnt to the old log.

Tested by doing scp during migration for a 2 queues virtio-net-pci.

Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
hw/virtio/vhost.c
include/hw/virtio/vhost.h