From patchwork Tue Apr 4 12:48:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 125753 X-Patchwork-Delegate: thomas@monjalon.net 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 5E459428CD; Tue, 4 Apr 2023 14:49:01 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4FC7041153; Tue, 4 Apr 2023 14:49:01 +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 F1E7740A7E for ; Tue, 4 Apr 2023 14:48:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680612539; 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=EhaIhl6hmC2b4yZVgLXGE3K/rq2mYCRoyh2/amsVFZQ=; b=DGxj+jjM4Tv+my6BI2AsbUysNdJf+F8RnbSjSepG+JXh9UNL3AbX08kFl8Gfwy633+VAk0 ik2RHhYs9559Rta9fbYEEeggsuy5r5hORdinBfR72zTp3FTAeDvwuMl0enYV+2+RhP9CAm BBODwxCWlsVOfQwPYov5pXVxxpCgMlw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-550-Pnbpgy5PNruxm9GgEJhgzA-1; Tue, 04 Apr 2023 08:48:56 -0400 X-MC-Unique: Pnbpgy5PNruxm9GgEJhgzA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CE268101A54F; Tue, 4 Apr 2023 12:48:55 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.225.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 183722027061; Tue, 4 Apr 2023 12:48:54 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: thomas@monjalon.net, Anatoly Burakov Subject: [PATCH v3 01/16] malloc: rework heap destroy Date: Tue, 4 Apr 2023 14:48:25 +0200 Message-Id: <20230404124840.1898-2-david.marchand@redhat.com> In-Reply-To: <20230404124840.1898-1-david.marchand@redhat.com> References: <20230224081642.2566619-1-david.marchand@redhat.com> <20230404124840.1898-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 The destroy helper has been reworked to zero all the heap object but leave the lock untouched. The heap lock is then released through the standard API. Signed-off-by: David Marchand --- Changes since v2: - shrinked the change to the required part, --- lib/eal/common/malloc_heap.c | 6 ++++-- lib/eal/common/rte_malloc.c | 5 +---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c index d7c410b786..d3c474d79c 100644 --- a/lib/eal/common/malloc_heap.c +++ b/lib/eal/common/malloc_heap.c @@ -1385,8 +1385,10 @@ malloc_heap_destroy(struct malloc_heap *heap) if (heap->total_size != 0) RTE_LOG(ERR, EAL, "Total size not zero, heap is likely corrupt\n"); - /* after this, the lock will be dropped */ - memset(heap, 0, sizeof(*heap)); + /* Reset all of the heap but the (hold) lock so caller can release it. */ + RTE_BUILD_BUG_ON(offsetof(struct malloc_heap, lock) != 0); + memset(RTE_PTR_ADD(heap, sizeof(heap->lock)), 0, + sizeof(*heap) - sizeof(heap->lock)); return 0; } diff --git a/lib/eal/common/rte_malloc.c b/lib/eal/common/rte_malloc.c index d39870bf3c..ebafef3f6c 100644 --- a/lib/eal/common/rte_malloc.c +++ b/lib/eal/common/rte_malloc.c @@ -657,10 +657,7 @@ rte_malloc_heap_destroy(const char *heap_name) /* sanity checks done, now we can destroy the heap */ rte_spinlock_lock(&heap->lock); ret = malloc_heap_destroy(heap); - - /* if we failed, lock is still active */ - if (ret < 0) - rte_spinlock_unlock(&heap->lock); + rte_spinlock_unlock(&heap->lock); unlock: rte_mcfg_mem_write_unlock();