From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-we0-f177.google.com (mail-we0-f177.google.com [74.125.82.177]) by dpdk.org (Postfix) with ESMTP id EB0945953 for ; Fri, 26 Jul 2013 16:54:41 +0200 (CEST) Received: by mail-we0-f177.google.com with SMTP id m46so1902835wev.8 for ; Fri, 26 Jul 2013 07:55:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:date:message-id:x-mailer:x-gm-message-state; bh=WDZcxmNT2EAoaPUVrS+7gKfkDX4QMn7TbQnzwzhXGv4=; b=RRyCtQs6q01MR40/R8v/td5LOdGKz39WTyWrJdlcNN5ruZ+pG27KI6fBQwLag0m2bw sjmhd6aB4hH7PW1WlmvFLWsWFXPDPkRMtW3F9Mrz8zSigpaWHRAr/so+8o90T4co92Za lP30HbT5wUOi6wDG2cEhkqZTIdMnr+GBkvtsXbJtw0WpGh5+76ozBK+ni1xcLEQB+BII 7CEHkT7OnIVoA3zMeVsGWFVbSGzNjniqb1FerwIBNRxPy+P3PsUbl/dpIsYllh2RAibG LvA0Uru5QQrbJXXecZR+k6Ow5m3f3OHe43+76htESXG6H05NLhAVZKF+fYXB6hOwZC5v sspA== X-Received: by 10.194.170.131 with SMTP id am3mr2209499wjc.83.1374850504848; Fri, 26 Jul 2013 07:55:04 -0700 (PDT) Received: from 6wind.com (6wind.net2.nerim.net. [213.41.180.237]) by mx.google.com with ESMTPSA id a6sm5233756wib.10.2013.07.26.07.55.02 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 26 Jul 2013 07:55:04 -0700 (PDT) Received: by 6wind.com (sSMTP sendmail emulation); Fri, 26 Jul 2013 16:55:01 +0200 From: Thomas Monjalon To: dev@dpdk.org Date: Fri, 26 Jul 2013 16:55:01 +0200 Message-Id: <1374850501-9253-1-git-send-email-thomas.monjalon@6wind.com> X-Mailer: git-send-email 1.7.10.4 X-Gm-Message-State: ALoCoQnurEsm4xMtlFTyBtdNeZX1bSOscWNPGp2UdqoS3CpO7hbFyYC0rMAl2eAEnJEgGSgaF6Lg Subject: [dpdk-dev] [PATCH] mem: fix rte_malloc(SOCKET_ID_ANY), try to allocate on other nodes X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Jul 2013 14:54:42 -0000 From: Olivier Matz Before this patch, rte_malloc(SOCKET_ID_ANY) was equivalent to rte_malloc(this_socket). If the user specifies SOCKET_ID_ANY, it means that memory can be allocated on any socket. So fix the behavior of rte_malloc() in order to do that. The current CPU socket is still the default, but if it fails, other sockets are tested. Signed-off-by: Olivier Matz Acked-by: Thomas Monjalon --- lib/librte_malloc/rte_malloc.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/librte_malloc/rte_malloc.c b/lib/librte_malloc/rte_malloc.c index a70a6b0..3a9edb1 100644 --- a/lib/librte_malloc/rte_malloc.c +++ b/lib/librte_malloc/rte_malloc.c @@ -69,23 +69,43 @@ void rte_free(void *addr) * Allocate memory on specified heap. */ void * -rte_malloc_socket(const char *type, size_t size, unsigned align, int socket) +rte_malloc_socket(const char *type, size_t size, unsigned align, int socket_arg) { struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; + int socket, i; + void *ret; /* return NULL if size is 0 or alignment is not power-of-2 */ if (size == 0 || !rte_is_power_of_2(align)) return NULL; - if (socket == SOCKET_ID_ANY) + if (socket_arg == SOCKET_ID_ANY) socket = malloc_get_numa_socket(); + else + socket = socket_arg; /* Check socket parameter */ if (socket >= RTE_MAX_NUMA_NODES) return NULL; - return malloc_heap_alloc(&mcfg->malloc_heaps[socket], type, - size, align == 0 ? 1 : align); + ret = malloc_heap_alloc(&mcfg->malloc_heaps[socket], type, + size, align == 0 ? 1 : align); + if (ret != NULL || socket_arg != SOCKET_ID_ANY) + return ret; + + /* try other heaps */ + for (i = 0; i < RTE_MAX_NUMA_NODES; i++) { + /* we already tried this one */ + if (i == socket) + continue; + + ret = malloc_heap_alloc(&mcfg->malloc_heaps[i], type, + size, align == 0 ? 1 : align); + if (ret != NULL) + return ret; + } + + return NULL; } /* -- 1.7.10.4