From patchwork Thu Jun 17 15:37:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 94369 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A4087A0C4B; Thu, 17 Jun 2021 17:39:07 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2AA6A410F0; Thu, 17 Jun 2021 17:39:03 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id E9A4F410EE for ; Thu, 17 Jun 2021 17:39:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623944341; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Lq5S9QpNR+V/YLgN1FInx0fcINIGFJRQhaj32q8wCGg=; b=Iz9c8WrCB6dH8rONkz5ZvVSzzjyHVsknL542po4IrITL6IUvz/uDA/Q3C4ngERjwRFW+4o EePXTKUv2GAAv6LQxM64bTfsDZVwmTxIAFi++2hHian7xAP+8uIptl4IR0Ewvb4KTwmpsW mnssPDtsnYTmpqtwXBliNu6Wzk19G4s= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-344-ixstYSwkMJOYbCePiK_RwQ-1; Thu, 17 Jun 2021 11:39:00 -0400 X-MC-Unique: ixstYSwkMJOYbCePiK_RwQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 50A2180ED8E; Thu, 17 Jun 2021 15:38:33 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.36.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 398227012F; Thu, 17 Jun 2021 15:38:32 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbo.xia@intel.com Cc: Maxime Coquelin Date: Thu, 17 Jun 2021 17:37:38 +0200 Message-Id: <20210617153739.178011-7-maxime.coquelin@redhat.com> In-Reply-To: <20210617153739.178011-1-maxime.coquelin@redhat.com> References: <20210617153739.178011-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v4 6/7] vhost: allocate all data on same node as virtqueue X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch saves the NUMA node the virtqueue is allocated on at init time, in order to allocate all other data on the same node. While most of the data are allocated before numa_realloc() is called and so the data will be reallocated properly, some data like the log cache are most likely allocated after. For the virtio device metadata, we decide to allocate them on the same node as the VQ 0. Signed-off-by: Maxime Coquelin --- lib/vhost/vhost.c | 34 ++++++++++++++++------------------ lib/vhost/vhost.h | 1 + lib/vhost/vhost_user.c | 41 ++++++++++++++++++++++++++++------------- 3 files changed, 45 insertions(+), 31 deletions(-) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index c96f6335c8..0000cd3297 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -261,7 +261,7 @@ vhost_alloc_copy_ind_table(struct virtio_net *dev, struct vhost_virtqueue *vq, uint64_t src, dst; uint64_t len, remain = desc_len; - idesc = rte_malloc(__func__, desc_len, 0); + idesc = rte_malloc_socket(__func__, desc_len, 0, vq->numa_node); if (unlikely(!idesc)) return NULL; @@ -549,6 +549,7 @@ static void init_vring_queue(struct virtio_net *dev, uint32_t vring_idx) { struct vhost_virtqueue *vq; + int numa_node = SOCKET_ID_ANY; if (vring_idx >= VHOST_MAX_VRING) { VHOST_LOG_CONFIG(ERR, @@ -570,6 +571,15 @@ init_vring_queue(struct virtio_net *dev, uint32_t vring_idx) vq->callfd = VIRTIO_UNINITIALIZED_EVENTFD; vq->notif_enable = VIRTIO_UNINITIALIZED_NOTIF; +#ifdef RTE_LIBRTE_VHOST_NUMA + if (get_mempolicy(&numa_node, NULL, 0, vq, MPOL_F_NODE | MPOL_F_ADDR)) { + VHOST_LOG_CONFIG(ERR, "(%d) failed to query numa node: %s\n", + dev->vid, rte_strerror(errno)); + numa_node = SOCKET_ID_ANY; + } +#endif + vq->numa_node = numa_node; + vhost_user_iotlb_init(dev, vring_idx); } @@ -1616,7 +1626,6 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id, struct vhost_virtqueue *vq; struct virtio_net *dev = get_device(vid); struct rte_vhost_async_features f; - int node; if (dev == NULL || ops == NULL) return -1; @@ -1651,20 +1660,9 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id, goto reg_out; } -#ifdef RTE_LIBRTE_VHOST_NUMA - if (get_mempolicy(&node, NULL, 0, vq, MPOL_F_NODE | MPOL_F_ADDR)) { - VHOST_LOG_CONFIG(ERR, - "unable to get numa information in async register. " - "allocating async buffer memory on the caller thread node\n"); - node = SOCKET_ID_ANY; - } -#else - node = SOCKET_ID_ANY; -#endif - vq->async_pkts_info = rte_malloc_socket(NULL, vq->size * sizeof(struct async_inflight_info), - RTE_CACHE_LINE_SIZE, node); + RTE_CACHE_LINE_SIZE, vq->numa_node); if (!vq->async_pkts_info) { vhost_free_async_mem(vq); VHOST_LOG_CONFIG(ERR, @@ -1675,7 +1673,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id, vq->it_pool = rte_malloc_socket(NULL, VHOST_MAX_ASYNC_IT * sizeof(struct rte_vhost_iov_iter), - RTE_CACHE_LINE_SIZE, node); + RTE_CACHE_LINE_SIZE, vq->numa_node); if (!vq->it_pool) { vhost_free_async_mem(vq); VHOST_LOG_CONFIG(ERR, @@ -1686,7 +1684,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id, vq->vec_pool = rte_malloc_socket(NULL, VHOST_MAX_ASYNC_VEC * sizeof(struct iovec), - RTE_CACHE_LINE_SIZE, node); + RTE_CACHE_LINE_SIZE, vq->numa_node); if (!vq->vec_pool) { vhost_free_async_mem(vq); VHOST_LOG_CONFIG(ERR, @@ -1698,7 +1696,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id, if (vq_is_packed(dev)) { vq->async_buffers_packed = rte_malloc_socket(NULL, vq->size * sizeof(struct vring_used_elem_packed), - RTE_CACHE_LINE_SIZE, node); + RTE_CACHE_LINE_SIZE, vq->numa_node); if (!vq->async_buffers_packed) { vhost_free_async_mem(vq); VHOST_LOG_CONFIG(ERR, @@ -1709,7 +1707,7 @@ int rte_vhost_async_channel_register(int vid, uint16_t queue_id, } else { vq->async_descs_split = rte_malloc_socket(NULL, vq->size * sizeof(struct vring_used_elem), - RTE_CACHE_LINE_SIZE, node); + RTE_CACHE_LINE_SIZE, vq->numa_node); if (!vq->async_descs_split) { vhost_free_async_mem(vq); VHOST_LOG_CONFIG(ERR, diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h index 8078ddff79..8ffe387556 100644 --- a/lib/vhost/vhost.h +++ b/lib/vhost/vhost.h @@ -164,6 +164,7 @@ struct vhost_virtqueue { uint16_t batch_copy_nb_elems; struct batch_copy_elem *batch_copy_elems; + int numa_node; bool used_wrap_counter; bool avail_wrap_counter; diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c index 0590ef6d14..faf1e7db84 100644 --- a/lib/vhost/vhost_user.c +++ b/lib/vhost/vhost_user.c @@ -433,10 +433,10 @@ vhost_user_set_vring_num(struct virtio_net **pdev, if (vq_is_packed(dev)) { if (vq->shadow_used_packed) rte_free(vq->shadow_used_packed); - vq->shadow_used_packed = rte_malloc(NULL, + vq->shadow_used_packed = rte_malloc_socket(NULL, vq->size * sizeof(struct vring_used_elem_packed), - RTE_CACHE_LINE_SIZE); + RTE_CACHE_LINE_SIZE, vq->numa_node); if (!vq->shadow_used_packed) { VHOST_LOG_CONFIG(ERR, "failed to allocate memory for shadow used ring.\n"); @@ -447,9 +447,9 @@ vhost_user_set_vring_num(struct virtio_net **pdev, if (vq->shadow_used_split) rte_free(vq->shadow_used_split); - vq->shadow_used_split = rte_malloc(NULL, + vq->shadow_used_split = rte_malloc_socket(NULL, vq->size * sizeof(struct vring_used_elem), - RTE_CACHE_LINE_SIZE); + RTE_CACHE_LINE_SIZE, vq->numa_node); if (!vq->shadow_used_split) { VHOST_LOG_CONFIG(ERR, @@ -460,9 +460,9 @@ vhost_user_set_vring_num(struct virtio_net **pdev, if (vq->batch_copy_elems) rte_free(vq->batch_copy_elems); - vq->batch_copy_elems = rte_malloc(NULL, + vq->batch_copy_elems = rte_malloc_socket(NULL, vq->size * sizeof(struct batch_copy_elem), - RTE_CACHE_LINE_SIZE); + RTE_CACHE_LINE_SIZE, vq->numa_node); if (!vq->batch_copy_elems) { VHOST_LOG_CONFIG(ERR, "failed to allocate memory for batching copy.\n"); @@ -498,6 +498,9 @@ numa_realloc(struct virtio_net *dev, int index) return dev; } + if (node == vq->numa_node) + goto out_dev_realloc; + if (vq->ready) { vq->ready = false; vhost_user_notify_queue_state(dev, index, 0); @@ -558,6 +561,10 @@ numa_realloc(struct virtio_net *dev, int index) vq->log_cache = lc; } + vq->numa_node = node; + +out_dev_realloc: + if (dev->flags & VIRTIO_DEV_RUNNING) return dev; @@ -1212,7 +1219,7 @@ vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg, struct virtio_net *dev = *pdev; struct VhostUserMemory *memory = &msg->payload.memory; struct rte_vhost_mem_region *reg; - + int numa_node = SOCKET_ID_ANY; uint64_t mmap_offset; uint32_t i; @@ -1252,13 +1259,21 @@ vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg, for (i = 0; i < dev->nr_vring; i++) vhost_user_iotlb_flush_all(dev->virtqueue[i]); + /* + * If VQ 0 has already been allocated, try to allocate on the same + * NUMA node. It can be reallocated later in numa_realloc(). + */ + if (dev->nr_vring > 0) + numa_node = dev->virtqueue[0]->numa_node; + dev->nr_guest_pages = 0; if (dev->guest_pages == NULL) { dev->max_guest_pages = 8; - dev->guest_pages = rte_zmalloc(NULL, + dev->guest_pages = rte_zmalloc_socket(NULL, dev->max_guest_pages * sizeof(struct guest_page), - RTE_CACHE_LINE_SIZE); + RTE_CACHE_LINE_SIZE, + numa_node); if (dev->guest_pages == NULL) { VHOST_LOG_CONFIG(ERR, "(%d) failed to allocate memory " @@ -1268,8 +1283,8 @@ vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg, } } - dev->mem = rte_zmalloc("vhost-mem-table", sizeof(struct rte_vhost_memory) + - sizeof(struct rte_vhost_mem_region) * memory->nregions, 0); + dev->mem = rte_zmalloc_socket("vhost-mem-table", sizeof(struct rte_vhost_memory) + + sizeof(struct rte_vhost_mem_region) * memory->nregions, 0, numa_node); if (dev->mem == NULL) { VHOST_LOG_CONFIG(ERR, "(%d) failed to allocate memory for dev->mem\n", @@ -2192,9 +2207,9 @@ vhost_user_set_log_base(struct virtio_net **pdev, struct VhostUserMsg *msg, rte_free(vq->log_cache); vq->log_cache = NULL; vq->log_cache_nb_elem = 0; - vq->log_cache = rte_zmalloc("vq log cache", + vq->log_cache = rte_malloc_socket("vq log cache", sizeof(struct log_cache_entry) * VHOST_LOG_CACHE_NR, - 0); + 0, vq->numa_node); /* * If log cache alloc fail, don't fail migration, but no * caching will be done, which will impact performance