From 418992173bc31494274312d92c53ce994cff4f33 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Mon, 30 Sep 2019 12:11:45 -0700 Subject: [PATCH] sock/posix: Automatically set a reasonable sndbuf size For new connections, just set the size to a good value for storage automatically. Change-Id: Ida2b21eac512a8a25ef70f486b43d5c47be16b63 Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/470510 Tested-by: SPDK CI Jenkins Reviewed-by: Alexey Marchuk Reviewed-by: Darek Stojaczyk Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- module/sock/posix/posix.c | 42 +++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/module/sock/posix/posix.c b/module/sock/posix/posix.c index d0f8c4d61..f6bb493cb 100644 --- a/module/sock/posix/posix.c +++ b/module/sock/posix/posix.c @@ -46,6 +46,7 @@ #define MAX_TMPBUF 1024 #define PORTNUMLEN 32 #define SO_RCVBUF_SIZE (2 * 1024 * 1024) +#define SO_SNDBUF_SIZE (2 * 1024 * 1024) struct spdk_posix_sock { struct spdk_sock base; @@ -185,6 +186,26 @@ spdk_posix_sock_set_recvbuf(struct spdk_sock *_sock, int sz) return 0; } +static int +spdk_posix_sock_set_sendbuf(struct spdk_sock *_sock, int sz) +{ + struct spdk_posix_sock *sock = __posix_sock(_sock); + int rc; + + assert(sock != NULL); + + if (sz < SO_SNDBUF_SIZE) { + sz = SO_SNDBUF_SIZE; + } + + rc = setsockopt(sock->fd, SOL_SOCKET, SO_SNDBUF, &sz, sizeof(sz)); + if (rc < 0) { + return rc; + } + + return 0; +} + static struct spdk_sock * spdk_posix_sock_create(const char *ip, int port, enum spdk_posix_sock_create_type type) { @@ -323,6 +344,11 @@ retry: /* Not fatal */ } + rc = spdk_posix_sock_set_sendbuf(&sock->base, SO_SNDBUF_SIZE); + if (rc) { + /* Not fatal */ + } + return &sock->base; } @@ -382,6 +408,11 @@ spdk_posix_sock_accept(struct spdk_sock *_sock) /* Not fatal */ } + rc = spdk_posix_sock_set_sendbuf(&new_sock->base, SO_SNDBUF_SIZE); + if (rc) { + /* Not fatal */ + } + return &new_sock->base; } @@ -440,17 +471,6 @@ spdk_posix_sock_set_recvlowat(struct spdk_sock *_sock, int nbytes) return 0; } -static int -spdk_posix_sock_set_sendbuf(struct spdk_sock *_sock, int sz) -{ - struct spdk_posix_sock *sock = __posix_sock(_sock); - - assert(sock != NULL); - - return setsockopt(sock->fd, SOL_SOCKET, SO_SNDBUF, - &sz, sizeof(sz)); -} - static int spdk_posix_sock_set_priority(struct spdk_sock *_sock, int priority) {