From: Stefan Hajnoczi <stefanha@redhat.com>
To: kvm@vger.kernel.org
Cc: virtualization@lists.linux-foundation.org,
"Michael S. Tsirkin" <mst@redhat.com>,
Jason Wang <jasowang@redhat.com>
Subject: [RFC 1/3] virtio-pci: use NUMA-aware memory allocation in probe
Date: Thu, 25 Jun 2020 14:57:50 +0100 [thread overview]
Message-ID: <20200625135752.227293-2-stefanha@redhat.com> (raw)
In-Reply-To: <20200625135752.227293-1-stefanha@redhat.com>
Allocate frequently-accessed data structures from the NUMA node
associated with this virtio-pci device. This avoids slow cross-NUMA node
memory accesses.
Only the following memory allocations are made NUMA-aware:
1. Called during probe. If called in the data path then hopefully we're
executing on a CPU in the same NUMA node as the device. If the CPU is
not in the right NUMA node then it's unclear whether forcing memory
allocations to use the device's NUMA node will increase or decrease
performance.
2. Memory will be frequently accessed from the data path. There is no
need to worry about data that is not accessed from
performance-critical code paths.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
drivers/virtio/virtio_pci_common.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
index 222d630c41fc..cc6e49f9c698 100644
--- a/drivers/virtio/virtio_pci_common.c
+++ b/drivers/virtio/virtio_pci_common.c
@@ -178,11 +178,13 @@ static struct virtqueue *vp_setup_vq(struct virtio_device *vdev, unsigned index,
u16 msix_vec)
{
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
- struct virtio_pci_vq_info *info = kmalloc(sizeof *info, GFP_KERNEL);
+ int node = dev_to_node(&vdev->dev);
+ struct virtio_pci_vq_info *info;
struct virtqueue *vq;
unsigned long flags;
/* fill out our structure that represents an active queue */
+ info = kmalloc_node(sizeof *info, GFP_KERNEL, node);
if (!info)
return ERR_PTR(-ENOMEM);
@@ -283,10 +285,12 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
struct irq_affinity *desc)
{
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
+ int node = dev_to_node(&vdev->dev);
u16 msix_vec;
int i, err, nvectors, allocated_vectors, queue_idx = 0;
- vp_dev->vqs = kcalloc(nvqs, sizeof(*vp_dev->vqs), GFP_KERNEL);
+ vp_dev->vqs = kcalloc_node(nvqs, sizeof(*vp_dev->vqs),
+ GFP_KERNEL, node);
if (!vp_dev->vqs)
return -ENOMEM;
@@ -355,9 +359,11 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned nvqs,
const char * const names[], const bool *ctx)
{
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
+ int node = dev_to_node(&vdev->dev);
int i, err, queue_idx = 0;
- vp_dev->vqs = kcalloc(nvqs, sizeof(*vp_dev->vqs), GFP_KERNEL);
+ vp_dev->vqs = kcalloc_node(nvqs, sizeof(*vp_dev->vqs),
+ GFP_KERNEL, node);
if (!vp_dev->vqs)
return -ENOMEM;
@@ -513,10 +519,12 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
const struct pci_device_id *id)
{
struct virtio_pci_device *vp_dev, *reg_dev = NULL;
+ int node = dev_to_node(&pci_dev->dev);
int rc;
/* allocate our structure and fill it out */
- vp_dev = kzalloc(sizeof(struct virtio_pci_device), GFP_KERNEL);
+ vp_dev = kzalloc_node(sizeof(struct virtio_pci_device),
+ GFP_KERNEL, node);
if (!vp_dev)
return -ENOMEM;
--
2.26.2
next prev parent reply other threads:[~2020-06-25 13:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-25 13:57 [RFC 0/3] virtio: NUMA-aware memory allocation Stefan Hajnoczi
2020-06-25 13:57 ` Stefan Hajnoczi [this message]
2020-06-25 13:57 ` [RFC 2/3] virtio_ring: use NUMA-aware memory allocation in probe Stefan Hajnoczi
2020-06-25 13:57 ` [RFC 3/3] virtio-blk: " Stefan Hajnoczi
2020-06-28 6:34 ` [RFC 0/3] virtio: NUMA-aware memory allocation Jason Wang
2020-06-29 9:26 ` Stefan Hajnoczi
2020-06-29 15:28 ` Michael S. Tsirkin
2020-06-30 8:47 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200625135752.227293-2-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=jasowang@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mst@redhat.com \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).