Skip to content

Commit

Permalink
vhost: fix missing memory table NUMA realloc
Browse files Browse the repository at this point in the history
[ upstream commit 8119ca9 ]

When the guest allocates virtqueues on a different NUMA node
than the one the Vhost metadata are allocated, both the Vhost
device struct and the virtqueues struct are reallocated.

However, reallocating the Vhost memory table was missing, which
likely causes at least one cross-NUMA accesses for every burst
of packets.

This patch reallocates this table on the same NUMA node as the
other metadata.

Fixes: 552e8fd ("vhost: simplify memory regions handling")

Reported-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
  • Loading branch information
mcoquelin authored and cpaelzer committed Aug 9, 2021
1 parent 75d705f commit 3548366
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/librte_vhost/vhost_user.c
Expand Up @@ -498,8 +498,8 @@ vhost_user_set_vring_num(struct virtio_net **pdev,
}

/*
* Reallocate virtio_dev and vhost_virtqueue data structure to make them on the
* same numa node as the memory of vring descriptor.
* Reallocate virtio_dev, vhost_virtqueue and related data structures to
* make them on the same numa node as the memory of vring descriptor.
*/
#ifdef RTE_LIBRTE_VHOST_NUMA
static struct virtio_net*
Expand Down Expand Up @@ -593,6 +593,9 @@ numa_realloc(struct virtio_net *dev, int index)
goto out;
}
if (oldnode != newnode) {
struct rte_vhost_memory *old_mem;
ssize_t mem_size;

RTE_LOG(INFO, VHOST_CONFIG,
"reallocate dev from %d to %d node\n",
oldnode, newnode);
Expand All @@ -604,6 +607,18 @@ numa_realloc(struct virtio_net *dev, int index)

memcpy(dev, old_dev, sizeof(*dev));
rte_free(old_dev);

mem_size = sizeof(struct rte_vhost_memory) +
sizeof(struct rte_vhost_mem_region) * dev->mem->nregions;
old_mem = dev->mem;
dev->mem = rte_malloc_socket(NULL, mem_size, 0, newnode);
if (!dev->mem) {
dev->mem = old_mem;
goto out;
}

memcpy(dev->mem, old_mem, mem_size);
rte_free(old_mem);
}

out:
Expand Down

0 comments on commit 3548366

Please sign in to comment.