From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E8B58A0C49; Tue, 15 Jun 2021 10:33:56 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 58AE74114E; Tue, 15 Jun 2021 10:33:28 +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 9AB44410FD for ; Tue, 15 Jun 2021 10:33:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623746005; 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=maHCVlVVnBr8oT9pX+Np94DYYMSd8l/oEU5Zjdrdufs=; b=ZtKES3ScyYCA4XYFEWnmq43qZf+CV3WfDF9xuN3nmm8fNVw3jjq9WK3W3a4tQ//M/jcOMn EBXN98SJEobARlQY4L13rf9WhwIHJPQXfPEBWvnnUvtKm5KtXA35AWVx6cHPO5jLeBS/S4 avN6vkNNzR0RlhR6HQb1MMVoAwkrfYE= 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-348-bu9A-RyYOXmZLIMaFBvlzQ-1; Tue, 15 Jun 2021 04:33:23 -0400 X-MC-Unique: bu9A-RyYOXmZLIMaFBvlzQ-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 279F61937FC4; Tue, 15 Jun 2021 08:33:22 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.36.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A5F360C0F; Tue, 15 Jun 2021 08:33:20 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbo.xia@intel.com Cc: Maxime Coquelin Date: Tue, 15 Jun 2021 10:33:08 +0200 Message-Id: <20210615083308.137401-7-maxime.coquelin@redhat.com> In-Reply-To: <20210615083308.137401-1-maxime.coquelin@redhat.com> References: <20210615083308.137401-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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Subject: [dpdk-dev] [PATCH 6/6] vhost: convert inflight data to DPDK allocation API 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" Inflight metadata are allocated using glibc's calloc. This patch converts them to rte_zmalloc_socket to take care of the NUMA affinity. Signed-off-by: Maxime Coquelin --- lib/vhost/vhost.c | 4 ++-- lib/vhost/vhost_user.c | 42 +++++++++++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 0000cd3297..53a470f547 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -312,10 +312,10 @@ cleanup_vq_inflight(struct virtio_net *dev, struct vhost_virtqueue *vq) if (vq->resubmit_inflight) { if (vq->resubmit_inflight->resubmit_list) { - free(vq->resubmit_inflight->resubmit_list); + rte_free(vq->resubmit_inflight->resubmit_list); vq->resubmit_inflight->resubmit_list = NULL; } - free(vq->resubmit_inflight); + rte_free(vq->resubmit_inflight); vq->resubmit_inflight = NULL; } } diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c index 72879a36c8..5342edf769 100644 --- a/lib/vhost/vhost_user.c +++ b/lib/vhost/vhost_user.c @@ -188,7 +188,7 @@ vhost_backend_cleanup(struct virtio_net *dev) dev->inflight_info->fd = -1; } - free(dev->inflight_info); + rte_free(dev->inflight_info); dev->inflight_info = NULL; } @@ -1476,6 +1476,7 @@ vhost_user_get_inflight_fd(struct virtio_net **pdev, uint16_t num_queues, queue_size; struct virtio_net *dev = *pdev; int fd, i, j; + int numa_node = SOCKET_ID_ANY; void *addr; if (msg->size != sizeof(msg->payload.inflight)) { @@ -1485,9 +1486,16 @@ vhost_user_get_inflight_fd(struct virtio_net **pdev, return RTE_VHOST_MSG_RESULT_ERR; } + /* + * 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; + if (dev->inflight_info == NULL) { - dev->inflight_info = calloc(1, - sizeof(struct inflight_mem_info)); + dev->inflight_info = rte_zmalloc_socket("inflight_info", + sizeof(struct inflight_mem_info), 0, numa_node); if (!dev->inflight_info) { VHOST_LOG_CONFIG(ERR, "failed to alloc dev inflight area\n"); @@ -1570,6 +1578,7 @@ vhost_user_set_inflight_fd(struct virtio_net **pdev, VhostUserMsg *msg, struct vhost_virtqueue *vq; void *addr; int fd, i; + int numa_node = SOCKET_ID_ANY; fd = msg->fds[0]; if (msg->size != sizeof(msg->payload.inflight) || fd < 0) { @@ -1603,9 +1612,16 @@ vhost_user_set_inflight_fd(struct virtio_net **pdev, VhostUserMsg *msg, "set_inflight_fd pervq_inflight_size: %d\n", pervq_inflight_size); + /* + * 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; + if (!dev->inflight_info) { - dev->inflight_info = calloc(1, - sizeof(struct inflight_mem_info)); + dev->inflight_info = rte_zmalloc_socket("inflight_info", + sizeof(struct inflight_mem_info), 0, numa_node); if (dev->inflight_info == NULL) { VHOST_LOG_CONFIG(ERR, "failed to alloc dev inflight area\n"); @@ -1764,15 +1780,17 @@ vhost_check_queue_inflights_split(struct virtio_net *dev, vq->last_avail_idx += resubmit_num; if (resubmit_num) { - resubmit = calloc(1, sizeof(struct rte_vhost_resubmit_info)); + resubmit = rte_zmalloc_socket("resubmit", sizeof(struct rte_vhost_resubmit_info), + 0, vq->numa_node); if (!resubmit) { VHOST_LOG_CONFIG(ERR, "failed to allocate memory for resubmit info.\n"); return RTE_VHOST_MSG_RESULT_ERR; } - resubmit->resubmit_list = calloc(resubmit_num, - sizeof(struct rte_vhost_resubmit_desc)); + resubmit->resubmit_list = rte_zmalloc_socket("resubmit_list", + resubmit_num * sizeof(struct rte_vhost_resubmit_desc), + 0, vq->numa_node); if (!resubmit->resubmit_list) { VHOST_LOG_CONFIG(ERR, "failed to allocate memory for inflight desc.\n"); @@ -1858,15 +1876,17 @@ vhost_check_queue_inflights_packed(struct virtio_net *dev, } if (resubmit_num) { - resubmit = calloc(1, sizeof(struct rte_vhost_resubmit_info)); + resubmit = rte_zmalloc_socket("resubmit", sizeof(struct rte_vhost_resubmit_info), + 0, vq->numa_node); if (resubmit == NULL) { VHOST_LOG_CONFIG(ERR, "failed to allocate memory for resubmit info.\n"); return RTE_VHOST_MSG_RESULT_ERR; } - resubmit->resubmit_list = calloc(resubmit_num, - sizeof(struct rte_vhost_resubmit_desc)); + resubmit->resubmit_list = rte_zmalloc_socket("resubmit_list", + resubmit_num * sizeof(struct rte_vhost_resubmit_desc), + 0, vq->numa_node); if (resubmit->resubmit_list == NULL) { VHOST_LOG_CONFIG(ERR, "failed to allocate memory for resubmit desc.\n"); -- 2.31.1