Commit 45b3c401 authored by Marcin Spiewak's avatar Marcin Spiewak Committed by Konrad Sztyber
Browse files

app: add auto-calculation of msg_mempool_size



Fixes #811

Currently the message memory pool size is always
configured to the same default value, regardless
of the number of cores the SPDK application is
running on.
In some situations, the default value of 262143
would not be sufficient, especially if large
number of SPDK's threads is started.
This patch adds calculation of msg_mempool_size, if
more than 63 cores are assigned to SPDK. In such case
the size of msg_mempool_size is calculated as
core_count * 4096.
For up to 63 cores, the value of 262143 is always used.

The user can also specify size of the message
memory pool with --msg-mempool-size option.
If specified byt the user, it always overrides
default or automatically calculated size.

Change-Id: Id5c57df4dd6492dbab6d56d49ec2ebe52ee7440d
Signed-off-by: default avatarMarcin Spiewak <marcin.spiewak@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17831


Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent e9ff4753
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -171,6 +171,10 @@ typedef void (*spdk_channel_for_each_cpl)(struct spdk_io_channel_iter *i, int st

#define SPDK_IO_CHANNEL_STRUCT_SIZE	96

/**
 * Message memory pool size definitions
 */
#define SPDK_MSG_MEMPOOL_CACHE_SIZE	1024
/* Power of 2 minus 1 is optimal for memory consumption */
#define SPDK_DEFAULT_MSG_MEMPOOL_SIZE (262144 - 1)

+30 −1
Original line number Diff line number Diff line
@@ -31,6 +31,14 @@
#define SPDK_APP_DPDK_DEFAULT_BASE_VIRTADDR	0x200000000000
#define SPDK_APP_DEFAULT_CORE_LIMIT		0x140000000 /* 5 GiB */

/* For core counts <= 63, the message memory pool size is set to
 * SPDK_DEFAULT_MSG_MEMPOOL_SIZE.
 * For core counts > 63, the message memory pool size is dependend on
 * number of cores. Per core, it is calculated as SPDK_MSG_MEMPOOL_CACHE_SIZE
 * multiplied by factor of 4 to have space for multiple spdk threads running
 * on single core (e.g  iscsi + nvmf + vhost ). */
#define SPDK_APP_PER_CORE_MSG_MEMPOOL_SIZE	(4 * SPDK_MSG_MEMPOOL_CACHE_SIZE)

#define MAX_CPU_CORES				128

struct spdk_app {
@@ -179,6 +187,23 @@ app_opts_validate(const char *app_opts)
	return 0;
}

static void
calculate_mempool_size(struct spdk_app_opts *opts,
		       struct spdk_app_opts *opts_user)
{
	uint32_t core_count = spdk_env_get_core_count();

	if (!opts_user->msg_mempool_size) {
		/* The user didn't specify msg_mempool_size, so let's calculate it.
		   Set the default (SPDK_DEFAULT_MSG_MEMPOOL_SIZE) if less than
		   64 cores, and use 4k per core otherwise */
		opts->msg_mempool_size = spdk_max(SPDK_DEFAULT_MSG_MEMPOOL_SIZE,
						  core_count * SPDK_APP_PER_CORE_MSG_MEMPOOL_SIZE);
	} else {
		opts->msg_mempool_size = opts_user->msg_mempool_size;
	}
}

void
spdk_app_opts_init(struct spdk_app_opts *opts, size_t opts_size)
{
@@ -211,7 +236,7 @@ spdk_app_opts_init(struct spdk_app_opts *opts, size_t opts_size)
	SET_FIELD(num_entries, SPDK_APP_DEFAULT_NUM_TRACE_ENTRIES);
	SET_FIELD(delay_subsystem_init, false);
	SET_FIELD(disable_signal_handlers, false);
	SET_FIELD(msg_mempool_size, SPDK_DEFAULT_MSG_MEMPOOL_SIZE);
	/* Don't set msg_mempool_size here, it is set or calculated later */
	SET_FIELD(rpc_allowlist, NULL);
#undef SET_FIELD
}
@@ -719,6 +744,10 @@ spdk_app_start(struct spdk_app_opts *opts_user, spdk_msg_fn start_fn,
		return 1;
	}

	/* Calculate mempool size now that the env layer has configured the core count
	 * for the application */
	calculate_mempool_size(opts, opts_user);

	spdk_log_open(opts->log);

	/* Initialize each lock to -1 to indicate "empty" status */
+0 −1
Original line number Diff line number Diff line
@@ -276,7 +276,6 @@ struct spdk_msg {
	SLIST_ENTRY(spdk_msg)	link;
};

#define SPDK_MSG_MEMPOOL_CACHE_SIZE	1024
static struct spdk_mempool *g_spdk_msg_mempool = NULL;

static TAILQ_HEAD(, spdk_thread) g_threads = TAILQ_HEAD_INITIALIZER(g_threads);