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 08D0D425DC; Mon, 18 Sep 2023 18:33:10 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C96A540E36; Mon, 18 Sep 2023 18:32:22 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id D273A40E36 for ; Mon, 18 Sep 2023 18:32:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695054740; x=1726590740; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+3XBw/EDcqYLFFjUEvlZWhoBDEj51AqVv3nbKl6ztHk=; b=YwJWr2x8VnzyD55oDMryySKx92iuKIvE35w6c0QR8meLbP/0zyCFLcKo LpgiK47kiF2uok8GWlq9cYBk1eZF77SnnOEaVQ9Dvf+5bk2O/KiPhjZBC uzhAe2h4pebeORKG7tJ74ahfEO8DfDS+84zJtUCQhlY8dfXO55dWpO5WR QL5twmYrS5zRlH1nInUyTz3TOkcVLAKLw2v15eEXa3dFz/DM6f3viCAnz WMoWH/mtMqeLd8RDnPPvkP97SIAU9WRk/L1F93XO23BxVGoWkswS67Fhv KyW0zNsDZ3O4z3n4SqMgrdjkhjSnakfxgB6VpVTyDJhatNWs/9Ne8C6BQ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="443784646" X-IronPort-AV: E=Sophos;i="6.02,156,1688454000"; d="scan'208";a="443784646" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2023 09:32:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="775189365" X-IronPort-AV: E=Sophos;i="6.02,156,1688454000"; d="scan'208";a="775189365" Received: from silpixa00401385.ir.intel.com ([10.237.214.14]) by orsmga008.jf.intel.com with ESMTP; 18 Sep 2023 09:32:19 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson , Anatoly Burakov Subject: [PATCH v3 1/2] eal: add flag to indicate non-EAL malloc heaps Date: Mon, 18 Sep 2023 17:32:05 +0100 Message-Id: <20230918163206.1010611-2-bruce.richardson@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918163206.1010611-1-bruce.richardson@intel.com> References: <20230915122703.475834-1-bruce.richardson@intel.com> <20230918163206.1010611-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Rather than relying implicitly on the socket_id value to identify external heaps vs internal ones that can be expanded on demand by adding more hugepages, we add an "is_external" flag to the heap structure. As we do so, we change the heap initialization to use designated initializers to guarantee as we add new fields that they are properly zeroed on init. As it stands, many fields are not explicitly set on first init of the internal malloc heaps. Signed-off-by: Bruce Richardson --- lib/eal/common/malloc_heap.c | 22 ++++++++++++---------- lib/eal/common/malloc_heap.h | 1 + lib/eal/common/malloc_mp.c | 5 ++--- lib/eal/common/rte_malloc.c | 14 ++++++++------ 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c index 6b6cf9174c..4fa38fcd44 100644 --- a/lib/eal/common/malloc_heap.c +++ b/lib/eal/common/malloc_heap.c @@ -668,7 +668,7 @@ malloc_heap_alloc_on_heap_id(const char *type, size_t size, * we just need to request more memory first. */ - socket_id = rte_socket_id_by_idx(heap_id); + socket_id = heap->is_external ? -1 : rte_socket_id_by_idx(heap_id); /* * if socket ID is negative, we cannot find a socket ID for this heap - * which means it's an external heap. those can have unexpected page @@ -1362,19 +1362,17 @@ malloc_heap_create(struct malloc_heap *heap, const char *heap_name) } /* initialize empty heap */ - heap->alloc_count = 0; - heap->first = NULL; - heap->last = NULL; + *heap = (struct malloc_heap) { + .is_external = 1, + .socket_id = next_socket_id, + .lock = RTE_SPINLOCK_INITIALIZER, + }; LIST_INIT(heap->free_head); - rte_spinlock_init(&heap->lock); - heap->total_size = 0; - heap->socket_id = next_socket_id; + strlcpy(heap->name, heap_name, RTE_HEAP_NAME_MAX_LEN); /* we hold a global mem hotplug writelock, so it's safe to increment */ mcfg->next_socket_id++; - /* set up name */ - strlcpy(heap->name, heap_name, RTE_HEAP_NAME_MAX_LEN); return 0; } @@ -1425,8 +1423,12 @@ rte_eal_malloc_heap_init(void) snprintf(heap_name, sizeof(heap_name), "socket_%i", socket_id); + + *heap = (struct malloc_heap){ + .lock = RTE_SPINLOCK_INITIALIZER, + .socket_id = socket_id, + }; strlcpy(heap->name, heap_name, RTE_HEAP_NAME_MAX_LEN); - heap->socket_id = socket_id; } } diff --git a/lib/eal/common/malloc_heap.h b/lib/eal/common/malloc_heap.h index 8f3ab57154..e23cc01fb3 100644 --- a/lib/eal/common/malloc_heap.h +++ b/lib/eal/common/malloc_heap.h @@ -23,6 +23,7 @@ struct malloc_elem; */ struct malloc_heap { rte_spinlock_t lock; + uint32_t is_external:1; LIST_HEAD(, malloc_elem) free_head[RTE_HEAP_NUM_FREELISTS]; struct malloc_elem *volatile first; struct malloc_elem *volatile last; diff --git a/lib/eal/common/malloc_mp.c b/lib/eal/common/malloc_mp.c index 7270c2ec90..d5ab6d8351 100644 --- a/lib/eal/common/malloc_mp.c +++ b/lib/eal/common/malloc_mp.c @@ -242,10 +242,9 @@ handle_alloc_request(const struct malloc_mp_req *m, /* * for allocations, we must only use internal heaps, but since the * rte_malloc_heap_socket_is_external() is thread-safe and we're already - * read-locked, we'll have to take advantage of the fact that internal - * socket ID's are always lower than RTE_MAX_NUMA_NODES. + * read-locked, we'll check directly here. */ - if (heap->socket_id >= RTE_MAX_NUMA_NODES) { + if (heap->is_external == 1) { RTE_LOG(ERR, EAL, "Attempting to allocate from external heap\n"); return -1; } diff --git a/lib/eal/common/rte_malloc.c b/lib/eal/common/rte_malloc.c index ebafef3f6c..5f40acabee 100644 --- a/lib/eal/common/rte_malloc.c +++ b/lib/eal/common/rte_malloc.c @@ -314,7 +314,7 @@ rte_malloc_heap_socket_is_external(int socket_id) if ((int)tmp->socket_id == socket_id) { /* external memory always has large socket ID's */ - ret = tmp->socket_id >= RTE_MAX_NUMA_NODES; + ret = tmp->is_external; break; } } @@ -421,7 +421,7 @@ rte_malloc_heap_memory_add(const char *heap_name, void *va_addr, size_t len, ret = -1; goto unlock; } - if (heap->socket_id < RTE_MAX_NUMA_NODES) { + if (heap->is_external == 0) { /* cannot add memory to internal heaps */ rte_errno = EPERM; ret = -1; @@ -469,7 +469,7 @@ rte_malloc_heap_memory_remove(const char *heap_name, void *va_addr, size_t len) ret = -1; goto unlock; } - if (heap->socket_id < RTE_MAX_NUMA_NODES) { + if (heap->is_external == 0) { /* cannot remove memory from internal heaps */ rte_errno = EPERM; ret = -1; @@ -520,7 +520,7 @@ sync_memory(const char *heap_name, void *va_addr, size_t len, bool attach) goto unlock; } /* we shouldn't be able to sync to internal heaps */ - if (heap->socket_id < RTE_MAX_NUMA_NODES) { + if (heap->is_external == 0) { rte_errno = EPERM; ret = -1; goto unlock; @@ -648,8 +648,10 @@ rte_malloc_heap_destroy(const char *heap_name) ret = -1; goto unlock; } - /* we shouldn't be able to destroy internal heaps */ - if (heap->socket_id < RTE_MAX_NUMA_NODES) { + /* we shouldn't be able to destroy internal heaps, or external heaps + * configured to have an internal numa socket id + */ + if (heap->socket_id < RTE_MAX_NUMA_NODES || heap->is_external == 0) { rte_errno = EPERM; ret = -1; goto unlock; -- 2.39.2