virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
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 3/3] virtio-blk: use NUMA-aware memory allocation in probe
Date: Thu, 25 Jun 2020 14:57:52 +0100	[thread overview]
Message-ID: <20200625135752.227293-4-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 device to avoid 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/block/virtio_blk.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 9d21bf0f155e..40845e9ad3b1 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -482,6 +482,7 @@ static int init_vq(struct virtio_blk *vblk)
 	unsigned short num_vqs;
 	struct virtio_device *vdev = vblk->vdev;
 	struct irq_affinity desc = { 0, };
+	int node = dev_to_node(&vdev->dev);
 
 	err = virtio_cread_feature(vdev, VIRTIO_BLK_F_MQ,
 				   struct virtio_blk_config, num_queues,
@@ -491,7 +492,8 @@ static int init_vq(struct virtio_blk *vblk)
 
 	num_vqs = min_t(unsigned int, nr_cpu_ids, num_vqs);
 
-	vblk->vqs = kmalloc_array(num_vqs, sizeof(*vblk->vqs), GFP_KERNEL);
+	vblk->vqs = kmalloc_array_node(num_vqs, sizeof(*vblk->vqs),
+				       GFP_KERNEL, node);
 	if (!vblk->vqs)
 		return -ENOMEM;
 
@@ -683,6 +685,7 @@ module_param_named(queue_depth, virtblk_queue_depth, uint, 0444);
 
 static int virtblk_probe(struct virtio_device *vdev)
 {
+	int node = dev_to_node(&vdev->dev);
 	struct virtio_blk *vblk;
 	struct request_queue *q;
 	int err, index;
@@ -714,7 +717,7 @@ static int virtblk_probe(struct virtio_device *vdev)
 
 	/* We need an extra sg elements at head and tail. */
 	sg_elems += 2;
-	vdev->priv = vblk = kmalloc(sizeof(*vblk), GFP_KERNEL);
+	vdev->priv = vblk = kmalloc_node(sizeof(*vblk), GFP_KERNEL, node);
 	if (!vblk) {
 		err = -ENOMEM;
 		goto out_free_index;
-- 
2.26.2


  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 ` [RFC 1/3] virtio-pci: use NUMA-aware memory allocation in probe Stefan Hajnoczi
2020-06-25 13:57 ` [RFC 2/3] virtio_ring: " Stefan Hajnoczi
2020-06-25 13:57 ` Stefan Hajnoczi [this message]
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-4-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).