From d20f41881b35b13959692b3c37522860277e2d52 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Thu, 11 Mar 2021 13:35:04 +0100 Subject: [PATCH] spdk_zmalloc: Remove unnecessary memset() Normally, unless RTE_MALLOC_DEBUG is set, DPDK zeroes memory in rte_free(). If RTE_MALLOC_DEBUG rte_free() fills memory with poison pattern, but then (and only then) the memory is zeroed in rte_zmalloc_socket(). Relying on this behavior allows to avoid unnecessary memset() in spdk_zmalloc() path. Signed-off-by: Robert Baldyga Change-Id: If3efa4dd22f1568949c3fb529b604bd597ceb32f Signed-off-by: Rafal Stefanowski Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6975 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Aleksey Marchuk Reviewed-by: Shuhei Matsumoto Reviewed-by: Tomasz Zawadzki --- lib/env_dpdk/env.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/env_dpdk/env.c b/lib/env_dpdk/env.c index c2801da2ec..b51020c7e5 100644 --- a/lib/env_dpdk/env.c +++ b/lib/env_dpdk/env.c @@ -71,7 +71,7 @@ spdk_malloc(size_t size, size_t align, uint64_t *phys_addr, int socket_id, uint3 buf = rte_malloc_socket(NULL, size, align, socket_id); if (buf && phys_addr) { #ifdef DEBUG - SPDK_ERRLOG("phys_addr param in spdk_*malloc() is deprecated\n"); + SPDK_ERRLOG("phys_addr param in spdk_malloc() is deprecated\n"); #endif *phys_addr = virt_to_phys(buf); } @@ -81,9 +81,19 @@ spdk_malloc(size_t size, size_t align, uint64_t *phys_addr, int socket_id, uint3 void * spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr, int socket_id, uint32_t flags) { - void *buf = spdk_malloc(size, align, phys_addr, socket_id, flags); - if (buf) { - memset(buf, 0, size); + void *buf; + + if (flags == 0) { + return NULL; + } + + align = spdk_max(align, RTE_CACHE_LINE_SIZE); + buf = rte_zmalloc_socket(NULL, size, align, socket_id); + if (buf && phys_addr) { +#ifdef DEBUG + SPDK_ERRLOG("phys_addr param in spdk_zmalloc() is deprecated\n"); +#endif + *phys_addr = virt_to_phys(buf); } return buf; }