diff --git a/include/spdk/env.h b/include/spdk/env.h index a25098517..306819695 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -2,6 +2,7 @@ * BSD LICENSE * * Copyright (c) Intel Corporation. + * Copyright (c) NetApp, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -165,6 +166,11 @@ void spdk_mempool_put(struct spdk_mempool *mp, void *ele); */ void spdk_mempool_put_bulk(struct spdk_mempool *mp, void *const *ele_arr, size_t count); +/** + * Return the number of entries in the mempool. + */ +size_t spdk_mempool_count(const struct spdk_mempool *pool); + /** * \brief Return the number of dedicated CPU cores utilized by * this env abstraction diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index a5bb7a178..6c5132d7e 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -37,9 +37,7 @@ #include "spdk/bdev.h" #include -#include -#include - +#include #include "spdk/env.h" #include "spdk/io_channel.h" #include "spdk/queue.h" @@ -54,9 +52,9 @@ #define BUF_SMALL_POOL_SIZE 8192 #define BUF_LARGE_POOL_SIZE 1024 -static struct rte_mempool *spdk_bdev_g_io_pool = NULL; -static struct rte_mempool *g_buf_small_pool = NULL; -static struct rte_mempool *g_buf_large_pool = NULL; +static struct spdk_mempool *spdk_bdev_g_io_pool = NULL; +static struct spdk_mempool *g_buf_small_pool = NULL; +static struct spdk_mempool *g_buf_large_pool = NULL; typedef TAILQ_HEAD(, spdk_bdev_io) need_buf_tailq_t; static need_buf_tailq_t g_need_buf_small[RTE_MAX_LCORE]; @@ -132,7 +130,7 @@ spdk_bdev_io_set_buf(struct spdk_bdev_io *bdev_io, void *buf) static void spdk_bdev_io_put_buf(struct spdk_bdev_io *bdev_io) { - struct rte_mempool *pool; + struct spdk_mempool *pool; struct spdk_bdev_io *tmp; void *buf; need_buf_tailq_t *tailq; @@ -152,7 +150,7 @@ spdk_bdev_io_put_buf(struct spdk_bdev_io *bdev_io) } if (TAILQ_EMPTY(tailq)) { - rte_mempool_put(pool, buf); + spdk_mempool_put(pool, buf); } else { tmp = TAILQ_FIRST(tailq); TAILQ_REMOVE(tailq, tmp, buf_link); @@ -170,28 +168,24 @@ static int spdk_initialize_buf_pool(void) * to account for. */ cache_size = BUF_SMALL_POOL_SIZE / (2 * spdk_env_get_core_count()); - if (cache_size > RTE_MEMPOOL_CACHE_MAX_SIZE) - cache_size = RTE_MEMPOOL_CACHE_MAX_SIZE; - g_buf_small_pool = rte_mempool_create("buf_small_pool", - BUF_SMALL_POOL_SIZE, - SPDK_BDEV_SMALL_BUF_MAX_SIZE + 512, - cache_size, 0, NULL, NULL, NULL, NULL, - SOCKET_ID_ANY, 0); + g_buf_small_pool = spdk_mempool_create("buf_small_pool", + BUF_SMALL_POOL_SIZE, + SPDK_BDEV_SMALL_BUF_MAX_SIZE + 512, + cache_size, + SPDK_ENV_SOCKET_ID_ANY); if (!g_buf_small_pool) { - SPDK_ERRLOG("create buf small pool failed\n"); + SPDK_ERRLOG("create rbuf small pool failed\n"); return -1; } cache_size = BUF_LARGE_POOL_SIZE / (2 * spdk_env_get_core_count()); - if (cache_size > RTE_MEMPOOL_CACHE_MAX_SIZE) - cache_size = RTE_MEMPOOL_CACHE_MAX_SIZE; - g_buf_large_pool = rte_mempool_create("buf_large_pool", - BUF_LARGE_POOL_SIZE, - SPDK_BDEV_LARGE_BUF_MAX_SIZE + 512, - cache_size, 0, NULL, NULL, NULL, NULL, - SOCKET_ID_ANY, 0); + g_buf_large_pool = spdk_mempool_create("buf_large_pool", + BUF_LARGE_POOL_SIZE, + SPDK_BDEV_LARGE_BUF_MAX_SIZE + 512, + cache_size, + SPDK_ENV_SOCKET_ID_ANY); if (!g_buf_large_pool) { - SPDK_ERRLOG("create buf large pool failed\n"); + SPDK_ERRLOG("create rbuf large pool failed\n"); return -1; } @@ -283,13 +277,12 @@ spdk_bdev_initialize(void) return -1; } - spdk_bdev_g_io_pool = rte_mempool_create("blockdev_io", + spdk_bdev_g_io_pool = spdk_mempool_create("blockdev_io", SPDK_BDEV_IO_POOL_SIZE, sizeof(struct spdk_bdev_io) + spdk_bdev_module_get_max_ctx_size(), - 64, 0, - NULL, NULL, NULL, NULL, - SOCKET_ID_ANY, 0); + 64, + SPDK_ENV_SOCKET_ID_ANY); if (spdk_bdev_g_io_pool == NULL) { SPDK_ERRLOG("could not allocate spdk_bdev_io pool"); @@ -304,23 +297,12 @@ spdk_bdev_initialize(void) return spdk_initialize_buf_pool(); } -/* - * Wrapper to provide rte_mempool_avail_count() on older DPDK versions. - * Drop this if the minimum DPDK version is raised to at least 16.07. - */ -#if RTE_VERSION < RTE_VERSION_NUM(16, 7, 0, 1) -static unsigned rte_mempool_avail_count(const struct rte_mempool *pool) -{ - return rte_mempool_count(pool); -} -#endif - static int -spdk_bdev_check_pool(struct rte_mempool *pool, uint32_t count) +spdk_bdev_check_pool(struct spdk_mempool *pool, uint32_t count) { - if (rte_mempool_avail_count(pool) != count) { - SPDK_ERRLOG("rte_mempool_avail_count(%s) == %d, should be %d\n", - pool->name, rte_mempool_avail_count(pool), count); + if (spdk_mempool_count(pool) != count) { + SPDK_ERRLOG("spdk_mempool_count(%p) == %zu, should be %u\n", + pool, spdk_mempool_count(pool), count); return -1; } else { return 0; @@ -343,10 +325,9 @@ spdk_bdev_finish(void) struct spdk_bdev_io *spdk_bdev_get_io(void) { struct spdk_bdev_io *bdev_io; - int rc; - rc = rte_mempool_get(spdk_bdev_g_io_pool, (void **)&bdev_io); - if (rc < 0 || !bdev_io) { + bdev_io = spdk_mempool_get(spdk_bdev_g_io_pool); + if (!bdev_io) { SPDK_ERRLOG("Unable to get spdk_bdev_io\n"); abort(); } @@ -367,16 +348,15 @@ spdk_bdev_put_io(struct spdk_bdev_io *bdev_io) spdk_bdev_io_put_buf(bdev_io); } - rte_mempool_put(spdk_bdev_g_io_pool, bdev_io); + spdk_mempool_put(spdk_bdev_g_io_pool, (void *)bdev_io); } static void _spdk_bdev_io_get_buf(struct spdk_bdev_io *bdev_io) { uint64_t len = bdev_io->u.read.len; - struct rte_mempool *pool; + struct spdk_mempool *pool; need_buf_tailq_t *tailq; - int rc; void *buf = NULL; if (len <= SPDK_BDEV_SMALL_BUF_MAX_SIZE) { @@ -387,8 +367,9 @@ _spdk_bdev_io_get_buf(struct spdk_bdev_io *bdev_io) tailq = &g_need_buf_large[rte_lcore_id()]; } - rc = rte_mempool_get(pool, (void **)&buf); - if (rc < 0 || !buf) { + buf = spdk_mempool_get(pool); + + if (!buf) { TAILQ_INSERT_TAIL(tailq, bdev_io, buf_link); } else { spdk_bdev_io_set_buf(bdev_io, buf); diff --git a/lib/env_dpdk/env.c b/lib/env_dpdk/env.c index 99a9b18f2..f7ec704e9 100644 --- a/lib/env_dpdk/env.c +++ b/lib/env_dpdk/env.c @@ -197,6 +197,16 @@ spdk_mempool_put_bulk(struct spdk_mempool *mp, void *const *ele_arr, size_t coun rte_mempool_put_bulk((struct rte_mempool *)mp, ele_arr, count); } +size_t +spdk_mempool_count(const struct spdk_mempool *pool) +{ +#if RTE_VERSION < RTE_VERSION_NUM(16, 7, 0, 1) + return rte_mempool_count((struct rte_mempool *)pool); +#else + return rte_mempool_avail_count((struct rte_mempool *)pool); +#endif +} + bool spdk_process_is_primary(void) {