Commit 825fce32 authored by Ben Walker's avatar Ben Walker Committed by Jim Harris
Browse files

thread: iobuf now allocates 4k aligned buffers



The buffers returned by  the iobuf pool are now always 4k aligned.
This will reduce complexity elsewhere (lib/nvmf).

This also removes an incorrect dependency on bdev.h.

Change-Id: I1d0d9c79309f9962419d96a6a7a396108b476015
Signed-off-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16224


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
parent 90f9ccea
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -517,7 +517,9 @@ spdk_bdev_set_opts(struct spdk_bdev_opts *opts)

	spdk_iobuf_get_opts(&iobuf_opts);
	iobuf_opts.small_pool_count = opts->small_buf_pool_size;
	iobuf_opts.small_bufsize = SPDK_BDEV_BUF_SIZE_WITH_MD(SPDK_BDEV_SMALL_BUF_MAX_SIZE);
	iobuf_opts.large_pool_count = opts->large_buf_pool_size;
	iobuf_opts.large_bufsize = SPDK_BDEV_BUF_SIZE_WITH_MD(SPDK_BDEV_LARGE_BUF_MAX_SIZE);

	rc = spdk_iobuf_set_opts(&iobuf_opts);
	if (rc != 0) {
+27 −18
Original line number Diff line number Diff line
@@ -8,17 +8,20 @@
#include "spdk/likely.h"
#include "spdk/log.h"
#include "spdk/thread.h"
#include "spdk/bdev.h"

#define IOBUF_MIN_SMALL_POOL_SIZE	64
#define IOBUF_MIN_LARGE_POOL_SIZE	8
#define IOBUF_DEFAULT_SMALL_POOL_SIZE	8192
#define IOBUF_DEFAULT_LARGE_POOL_SIZE	1024
#define IOBUF_ALIGNMENT			4096
#define IOBUF_MIN_SMALL_BUFSIZE		(SPDK_BDEV_BUF_SIZE_WITH_MD(SPDK_BDEV_SMALL_BUF_MAX_SIZE) + \
					 IOBUF_ALIGNMENT)
#define IOBUF_MIN_LARGE_BUFSIZE		(SPDK_BDEV_BUF_SIZE_WITH_MD(SPDK_BDEV_LARGE_BUF_MAX_SIZE) + \
					 IOBUF_ALIGNMENT)
#define IOBUF_MIN_SMALL_BUFSIZE		4096
#define IOBUF_MIN_LARGE_BUFSIZE		8192
#define IOBUF_DEFAULT_SMALL_BUFSIZE	(8 * 1024)
/* 132k is a weird choice at first, but this needs to be large enough to accomodate
 * the default maximum size (128k) plus metadata everywhere. For code paths that
 * are explicitly configured, the math is instead done properly. This is only
 * for the default. */
#define IOBUF_DEFAULT_LARGE_BUFSIZE	(132 * 1024)

SPDK_STATIC_ASSERT(sizeof(struct spdk_iobuf_buffer) <= IOBUF_MIN_SMALL_BUFSIZE,
		   "Invalid data offset");
@@ -53,8 +56,8 @@ static struct iobuf g_iobuf = {
	.opts = {
		.small_pool_count = IOBUF_DEFAULT_SMALL_POOL_SIZE,
		.large_pool_count = IOBUF_DEFAULT_LARGE_POOL_SIZE,
		.small_bufsize = IOBUF_MIN_SMALL_BUFSIZE,
		.large_bufsize = IOBUF_MIN_LARGE_BUFSIZE,
		.small_bufsize = IOBUF_DEFAULT_SMALL_BUFSIZE,
		.large_bufsize = IOBUF_DEFAULT_LARGE_BUFSIZE,
	},
};

@@ -94,8 +97,10 @@ spdk_iobuf_initialize(void)
		goto error;
	}

	g_iobuf.small_pool_base = spdk_malloc(opts->small_bufsize * opts->small_pool_count, 0, NULL,
					      SPDK_ENV_SOCKET_ID_ANY, SPDK_MALLOC_DMA);
	/* Round up to the nearest alignment so that each element remains aligned */
	opts->small_bufsize = SPDK_ALIGN_CEIL(opts->small_bufsize, IOBUF_ALIGNMENT);
	g_iobuf.small_pool_base = spdk_malloc(opts->small_bufsize * opts->small_pool_count, IOBUF_ALIGNMENT,
					      NULL, SPDK_ENV_SOCKET_ID_ANY, SPDK_MALLOC_DMA);
	if (g_iobuf.small_pool_base == NULL) {
		SPDK_ERRLOG("Unable to allocate requested small iobuf pool size\n");
		rc = -ENOMEM;
@@ -110,8 +115,10 @@ spdk_iobuf_initialize(void)
		goto error;
	}

	g_iobuf.large_pool_base = spdk_malloc(opts->large_bufsize * opts->large_pool_count, 0, NULL,
					      SPDK_ENV_SOCKET_ID_ANY, SPDK_MALLOC_DMA);
	/* Round up to the nearest alignment so that each element remains aligned */
	opts->large_bufsize = SPDK_ALIGN_CEIL(opts->large_bufsize, IOBUF_ALIGNMENT);
	g_iobuf.large_pool_base = spdk_malloc(opts->large_bufsize * opts->large_pool_count, IOBUF_ALIGNMENT,
					      NULL, SPDK_ENV_SOCKET_ID_ANY, SPDK_MALLOC_DMA);
	if (g_iobuf.large_pool_base == NULL) {
		SPDK_ERRLOG("Unable to allocate requested large iobuf pool size\n");
		rc = -ENOMEM;
@@ -200,19 +207,21 @@ spdk_iobuf_set_opts(const struct spdk_iobuf_opts *opts)
			    IOBUF_MIN_LARGE_POOL_SIZE);
		return -EINVAL;
	}

	g_iobuf.opts = *opts;

	if (opts->small_bufsize < IOBUF_MIN_SMALL_BUFSIZE) {
		SPDK_ERRLOG("small_bufsize must be at least %" PRIu32 "\n",
		SPDK_ERRLOG("small_bufsize must be at least %" PRIu32 ". Automatically increasing.\n",
			    IOBUF_MIN_SMALL_BUFSIZE);
		return -EINVAL;
		g_iobuf.opts.large_bufsize = IOBUF_MIN_SMALL_BUFSIZE;
	}

	if (opts->large_bufsize < IOBUF_MIN_LARGE_BUFSIZE) {
		SPDK_ERRLOG("large_bufsize must be at least %" PRIu32 "\n",
		SPDK_WARNLOG("large_bufsize must be at least %" PRIu32 ". Automatically increasing.\n",
			     IOBUF_MIN_LARGE_BUFSIZE);
		return -EINVAL;
		g_iobuf.opts.large_bufsize = IOBUF_MIN_LARGE_BUFSIZE;
	}

	g_iobuf.opts = *opts;

	return 0;
}

+2 −2
Original line number Diff line number Diff line
@@ -44,8 +44,8 @@ ut_iobuf_foreach_cb(struct spdk_iobuf_channel *ch, struct spdk_iobuf_entry *entr
	return 0;
}

#define SMALL_BUFSIZE 128
#define LARGE_BUFSIZE 512
#define SMALL_BUFSIZE 4096
#define LARGE_BUFSIZE 8192

static void
iobuf(void)