From cb9e0db853add20471c6c4441fcf115eba0558b0 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Wed, 5 Apr 2023 13:31:47 -0700 Subject: [PATCH] sock: Do aligned allocations for the pipes Use posix_memalign to ensure aligned allocations. In reality, we'd get 64 byte alignment using even calloc, but this makes sure of it. Change-Id: I6066e57c95b0f42cff439d452e4aed853189a523 Signed-off-by: Ben Walker Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17508 Community-CI: Mellanox Build Bot Reviewed-by: Aleksey Marchuk Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris --- module/sock/posix/posix.c | 6 ++++-- module/sock/uring/uring.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/module/sock/posix/posix.c b/module/sock/posix/posix.c index 9aa5f4782..e61e4fae0 100644 --- a/module/sock/posix/posix.c +++ b/module/sock/posix/posix.c @@ -255,6 +255,7 @@ posix_sock_alloc_pipe(struct spdk_posix_sock *sock, int sz) struct iovec diov[2]; int sbytes; ssize_t bytes; + int rc; if (sock->recv_buf_sz == sz) { return 0; @@ -273,11 +274,12 @@ posix_sock_alloc_pipe(struct spdk_posix_sock *sock, int sz) } /* Round up to next 64 byte multiple */ - new_buf = calloc(SPDK_ALIGN_CEIL(sz, 64), sizeof(uint8_t)); - if (!new_buf) { + rc = posix_memalign((void **)&new_buf, 64, sz); + if (rc != 0) { SPDK_ERRLOG("socket recv buf allocation failed\n"); return -ENOMEM; } + memset(new_buf, 0, sz); new_pipe = spdk_pipe_create(new_buf, sz); if (new_pipe == NULL) { diff --git a/module/sock/uring/uring.c b/module/sock/uring/uring.c index ff0545584..7623eb708 100644 --- a/module/sock/uring/uring.c +++ b/module/sock/uring/uring.c @@ -275,6 +275,7 @@ uring_sock_alloc_pipe(struct spdk_uring_sock *sock, int sz) struct iovec diov[2]; int sbytes; ssize_t bytes; + int rc; if (sock->recv_buf_sz == sz) { return 0; @@ -293,11 +294,12 @@ uring_sock_alloc_pipe(struct spdk_uring_sock *sock, int sz) } /* Round up to next 64 byte multiple */ - new_buf = calloc(SPDK_ALIGN_CEIL(sz, 64), sizeof(uint8_t)); - if (!new_buf) { + rc = posix_memalign((void **)&new_buf, 64, sz); + if (rc != 0) { SPDK_ERRLOG("socket recv buf allocation failed\n"); return -ENOMEM; } + memset(new_buf, 0, sz); new_pipe = spdk_pipe_create(new_buf, sz); if (new_pipe == NULL) {