env_dpdk: tell spdk_mem_map_init whether legacy_mem was specified

We will use this in a future patch to determine whether it's safe
to use DPDK allocated memory when allocating new 1gb page entries.

We could use it in this patch to decide whether or not to register
the memory hotplug handler, but there's really no harm registering
it even when it's not needed.

Ideally DPDK would provide some kind of API to query how DPDK was
configured.  In the normal case we know whether legacy-mem was
specified, but if users initialize DPDK themselves and then call
spdk_env_dpdk_post_init(), we won't know if legacy-mem was specified.
So in that case, we will just assume that it wasn't specified.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: Ied0e5ff777c8ee651043f46a37ce62e44bfcc5fe

Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/477086
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Community-CI: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Jim Harris 2019-12-06 16:26:49 -07:00 committed by Tomasz Zawadzki
parent 7561d1b5c2
commit 396c445cb1
6 changed files with 20 additions and 8 deletions

View File

@ -48,9 +48,11 @@ extern "C" {
* instead of spdk_env_init, prior to using any other functions in SPDK
* env library.
*
* \param legacy_mem Indicates whether DPDK was initialized with --legacy-mem
* eal parameter.
* \return 0 on success, or negative errno on failure.
*/
int spdk_env_dpdk_post_init(void);
int spdk_env_dpdk_post_init(bool legacy_mem);
/**
* Release any resources of the environment library that were alllocated with

View File

@ -79,7 +79,7 @@ int spdk_pci_device_fini(struct rte_pci_device *device);
void spdk_pci_init(void);
void spdk_pci_fini(void);
int spdk_mem_map_init(void);
int spdk_mem_map_init(bool legacy_mem);
int spdk_vtophys_init(void);
/**

View File

@ -480,13 +480,13 @@ spdk_build_eal_cmdline(const struct spdk_env_opts *opts)
}
int
spdk_env_dpdk_post_init(void)
spdk_env_dpdk_post_init(bool legacy_mem)
{
int rc;
spdk_pci_init();
rc = spdk_mem_map_init();
rc = spdk_mem_map_init(legacy_mem);
if (rc < 0) {
fprintf(stderr, "Failed to allocate mem_map\n");
return rc;
@ -515,6 +515,7 @@ spdk_env_init(const struct spdk_env_opts *opts)
char **dpdk_args = NULL;
int i, rc;
int orig_optind;
bool legacy_mem;
g_external_init = false;
@ -570,7 +571,12 @@ spdk_env_init(const struct spdk_env_opts *opts)
spdk_env_unlink_shared_files();
}
return spdk_env_dpdk_post_init();
legacy_mem = false;
if (opts->env_context && strstr(opts->env_context, "--legacy-mem") != NULL) {
legacy_mem = true;
}
return spdk_env_dpdk_post_init(legacy_mem);
}
void

View File

@ -146,6 +146,8 @@ static struct spdk_mem_map *g_mem_reg_map;
static TAILQ_HEAD(, spdk_mem_map) g_spdk_mem_maps = TAILQ_HEAD_INITIALIZER(g_spdk_mem_maps);
static pthread_mutex_t g_spdk_mem_map_mutex = PTHREAD_MUTEX_INITIALIZER;
static bool g_legacy_mem;
/*
* Walk the currently registered memory via the main memory registration map
* and call the new map's notify callback for each virtually contiguous region.
@ -700,8 +702,10 @@ memory_iter_cb(const struct rte_memseg_list *msl,
#endif
int
spdk_mem_map_init(void)
spdk_mem_map_init(bool legacy_mem)
{
g_legacy_mem = legacy_mem;
g_mem_reg_map = spdk_mem_map_alloc(0, NULL, NULL);
if (g_mem_reg_map == NULL) {
DEBUG_PRINT("memory registration map allocation failed\n");

View File

@ -104,7 +104,7 @@ main(int argc, char **argv)
}
printf("Starting SPDK post initialization...\n");
ret = spdk_env_dpdk_post_init();
ret = spdk_env_dpdk_post_init(false);
if (ret < 0) {
fprintf(stderr, "Failed to initialize SPDK\n");
return -1;

View File

@ -489,7 +489,7 @@ main(int argc, char **argv)
g_page_array = spdk_bit_array_create(PAGE_ARRAY_SIZE);
/* Initialize the memory map */
if (spdk_mem_map_init() < 0) {
if (spdk_mem_map_init(false) < 0) {
return CUE_NOMEMORY;
}