From 2224ff216218c856b7f06435a0e740531c407ed7 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Wed, 17 Aug 2016 13:35:18 -0700 Subject: [PATCH] env: Replace rte_malloc with spdk_zmalloc Use the env library to perform all memory allocations that previously called DPDK directly. Change-Id: I6d33e85bde99796e0c85277d6d4880521c34f10d Signed-off-by: Ben Walker --- app/iscsi_tgt/iscsi_tgt.c | 21 --------------- examples/ioat/perf/perf.c | 5 ++-- examples/ioat/verify/verify.c | 5 ++-- examples/nvme/arbitration/arbitration.c | 7 +++-- examples/nvme/fio_plugin/fio_plugin.c | 5 ++-- examples/nvme/hello_world/hello_world.c | 15 +++++------ examples/nvme/nvme_manage/nvme_manage.c | 31 +++++++++++----------- examples/nvme/perf/perf.c | 11 ++++---- lib/bdev/bdev.c | 1 - lib/bdev/malloc/blockdev_malloc.c | 23 +++++++--------- lib/bdev/nvme/blockdev_nvme.c | 1 - lib/copy/ioat/copy_engine_ioat.c | 5 ++-- lib/env/env.c | 4 ++- lib/iscsi/iscsi.c | 2 -- lib/iscsi/iscsi_subsystem.c | 6 ++--- lib/nvmf/rdma.c | 27 +++++++++---------- lib/scsi/task.c | 8 +++--- test/lib/bdev/bdevio/bdevio.c | 8 +++--- test/lib/bdev/bdevperf/bdevperf.c | 4 +-- test/lib/env/vtophys.c | 7 +++-- test/lib/event/event/event.c | 1 - test/lib/nvme/aer/aer.c | 5 ++-- test/lib/nvme/e2edp/nvme_dp.c | 35 ++++++++++++------------- test/lib/nvme/overhead/overhead.c | 7 +++-- test/lib/nvme/reset/reset.c | 5 ++-- test/lib/nvme/sgl/nvme_sgl.c | 31 +++++++++++----------- test/lib/nvmf/nvmf/nvmf_ut.c | 1 - 27 files changed, 118 insertions(+), 163 deletions(-) diff --git a/app/iscsi_tgt/iscsi_tgt.c b/app/iscsi_tgt/iscsi_tgt.c index 43b0738f0..f78e97e22 100644 --- a/app/iscsi_tgt/iscsi_tgt.c +++ b/app/iscsi_tgt/iscsi_tgt.c @@ -39,30 +39,12 @@ #include #include #include -#include -#include #include "spdk/event.h" #include "iscsi/iscsi.h" #include "spdk/log.h" #include "spdk/net.h" -static void -spdk_iscsi_dump_memory_info(void) -{ - struct rte_malloc_socket_stats stats; - int i; - - for (i = 0; i < RTE_MAX_NUMA_NODES; i++) { - rte_malloc_get_socket_stats(i, &stats); - if (stats.heap_totalsz_bytes > 0) - fprintf(stderr, "Socket %d: Total memory %"PRIu64" MB," - " Free memory %"PRIu64" MB\n", - i, stats.heap_totalsz_bytes >> 20, - stats.heap_freesz_bytes >> 20); - } -} - static void spdk_sigusr1(int signo __attribute__((__unused__))) { @@ -106,9 +88,6 @@ spdk_startup(spdk_event_t event) rte_memzone_dump(stdout); fflush(stdout); } - - /* Dump socket memory information */ - spdk_iscsi_dump_memory_info(); } int diff --git a/examples/ioat/perf/perf.c b/examples/ioat/perf/perf.c index f4b78b8f0..4219aa0c1 100644 --- a/examples/ioat/perf/perf.c +++ b/examples/ioat/perf/perf.c @@ -37,7 +37,6 @@ #include #include #include -#include #include #include #include @@ -117,7 +116,7 @@ ioat_exit(void) if (dev->ioat) { spdk_ioat_detach(dev->ioat); } - rte_free(dev); + spdk_free(dev); } } @@ -162,7 +161,7 @@ attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_ioat_chan * { struct ioat_device *dev; - dev = rte_malloc(NULL, sizeof(*dev), 0); + dev = spdk_zmalloc(sizeof(*dev), 0, NULL); if (dev == NULL) { printf("Failed to allocate device struct\n"); return; diff --git a/examples/ioat/verify/verify.c b/examples/ioat/verify/verify.c index 0b1edb5e8..89c6a3fd9 100644 --- a/examples/ioat/verify/verify.c +++ b/examples/ioat/verify/verify.c @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include @@ -367,7 +366,7 @@ init_src_buffer(void) { int i; - g_src = rte_malloc(NULL, SRC_BUFFER_SIZE, 512); + g_src = spdk_zmalloc(SRC_BUFFER_SIZE, 512, NULL); if (g_src == NULL) { fprintf(stderr, "Allocate src buffer failed\n"); return -1; @@ -487,7 +486,7 @@ main(int argc, char **argv) rc = dump_result(threads, RTE_MAX_LCORE); cleanup: - rte_free(g_src); + spdk_free(g_src); ioat_exit(); return rc; diff --git a/examples/nvme/arbitration/arbitration.c b/examples/nvme/arbitration/arbitration.c index 60ef5534c..01982de21 100644 --- a/examples/nvme/arbitration/arbitration.c +++ b/examples/nvme/arbitration/arbitration.c @@ -39,7 +39,6 @@ #include #include #include -#include #include #include "spdk/nvme.h" @@ -294,9 +293,9 @@ static void task_ctor(struct rte_mempool *mp, void *arg, void *__task, unsigned id) { struct arb_task *task = __task; - task->buf = rte_malloc(NULL, g_arbitration.io_size_bytes, 0x200); + task->buf = spdk_zmalloc(g_arbitration.io_size_bytes, 0x200, NULL); if (task->buf == NULL) { - fprintf(stderr, "task->buf rte_malloc failed\n"); + fprintf(stderr, "task->buf spdk_zmalloc failed\n"); exit(1); } } @@ -438,7 +437,7 @@ cleanup(void) } while (worker); if (rte_mempool_get(task_pool, (void **)&task) == 0) { - rte_free(task->buf); + spdk_free(task->buf); } } diff --git a/examples/nvme/fio_plugin/fio_plugin.c b/examples/nvme/fio_plugin/fio_plugin.c index 09d95e138..40a27030c 100644 --- a/examples/nvme/fio_plugin/fio_plugin.c +++ b/examples/nvme/fio_plugin/fio_plugin.c @@ -39,7 +39,6 @@ #include "rte_config.h" #include "rte_mempool.h" -#include "rte_malloc.h" #include "rte_eal.h" #include "spdk/nvme.h" @@ -219,13 +218,13 @@ static int spdk_fio_close(struct thread_data *td, struct fio_file *f) static int spdk_fio_iomem_alloc(struct thread_data *td, size_t total_mem) { - td->orig_buffer = rte_malloc(NULL, total_mem, NVME_IO_ALIGN); + td->orig_buffer = spdk_zmalloc(total_mem, NVME_IO_ALIGN, NULL); return td->orig_buffer == NULL; } static void spdk_fio_iomem_free(struct thread_data *td) { - rte_free(td->orig_buffer); + spdk_free(td->orig_buffer); } static int spdk_fio_io_u_init(struct thread_data *td, struct io_u *io_u) diff --git a/examples/nvme/hello_world/hello_world.c b/examples/nvme/hello_world/hello_world.c index 9201dca97..13fb9e6c9 100644 --- a/examples/nvme/hello_world/hello_world.c +++ b/examples/nvme/hello_world/hello_world.c @@ -37,7 +37,6 @@ #include #include -#include #include "spdk/nvme.h" #include "spdk/env.h" @@ -114,7 +113,7 @@ read_complete(void *arg, const struct spdk_nvme_cpl *completion) * to exit its polling loop. */ printf("%s", sequence->buf); - rte_free(sequence->buf); + spdk_free(sequence->buf); sequence->is_completed = 1; } @@ -130,8 +129,8 @@ write_complete(void *arg, const struct spdk_nvme_cpl *completion) * the write I/O and allocate a new zeroed buffer for reading * the data back from the NVMe namespace. */ - rte_free(sequence->buf); - sequence->buf = rte_zmalloc(NULL, 0x1000, 0x1000); + spdk_free(sequence->buf); + sequence->buf = spdk_zmalloc(0x1000, 0x1000, NULL); rc = spdk_nvme_ns_cmd_read(ns_entry->ns, ns_entry->qpair, sequence->buf, 0, /* LBA start */ @@ -171,11 +170,11 @@ hello_world(void) } /* - * Use DPDK rte_zmalloc to allocate a 4KB zeroed buffer. This memory - * will be allocated from 2MB hugepages and will be pinned. These are - * both requirements for data buffers used for SPDK NVMe I/O operations. + * Use spdk_zmalloc to allocate a 4KB zeroed buffer. This memory + * will be pinned, which is required for data buffers used for SPDK NVMe + * I/O operations. */ - sequence.buf = rte_zmalloc(NULL, 0x1000, 0x1000); + sequence.buf = spdk_zmalloc(0x1000, 0x1000, NULL); sequence.is_completed = 0; sequence.ns_entry = ns_entry; diff --git a/examples/nvme/nvme_manage/nvme_manage.c b/examples/nvme/nvme_manage/nvme_manage.c index 8fa788993..5ee4eac26 100644 --- a/examples/nvme/nvme_manage/nvme_manage.c +++ b/examples/nvme/nvme_manage/nvme_manage.c @@ -41,7 +41,6 @@ #include #include -#include #include #include @@ -111,7 +110,7 @@ identify_common_ns_cb(void *cb_arg, const struct spdk_nvme_cpl *cpl) if (cpl->status.sc != SPDK_NVME_SC_SUCCESS) { /* Identify Namespace for NSID = FFFFFFFFh is optional, so failure is not fatal. */ - rte_free(dev->common_ns_data); + spdk_free(dev->common_ns_data); dev->common_ns_data = NULL; } @@ -133,7 +132,7 @@ attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr /* Retrieve controller data */ dev->cdata = spdk_nvme_ctrlr_get_data(dev->ctrlr); - dev->common_ns_data = rte_zmalloc("common_ns_data", sizeof(struct spdk_nvme_ns_data), 4096); + dev->common_ns_data = spdk_zmalloc(sizeof(struct spdk_nvme_ns_data), 4096, NULL); if (dev->common_ns_data == NULL) { fprintf(stderr, "common_ns_data allocation failure\n"); return; @@ -149,7 +148,7 @@ attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr if (spdk_nvme_ctrlr_cmd_admin_raw(ctrlr, &cmd, dev->common_ns_data, sizeof(struct spdk_nvme_ns_data), identify_common_ns_cb, dev) != 0) { dev->outstanding_admin_cmds--; - rte_free(dev->common_ns_data); + spdk_free(dev->common_ns_data); dev->common_ns_data = NULL; } @@ -410,7 +409,7 @@ get_allocated_nsid(struct dev *dev) struct spdk_nvme_ns_list *ns_list; struct spdk_nvme_cmd cmd = {0}; - ns_list = rte_zmalloc("nvme_ns_list", sizeof(*ns_list), 4096); + ns_list = spdk_zmalloc(sizeof(*ns_list), 4096, NULL); if (ns_list == NULL) { printf("Allocation error\n"); return 0; @@ -424,7 +423,7 @@ get_allocated_nsid(struct dev *dev) if (spdk_nvme_ctrlr_cmd_admin_raw(dev->ctrlr, &cmd, ns_list, sizeof(*ns_list), identify_allocated_ns_cb, dev)) { printf("Identify command failed\n"); - rte_free(ns_list); + spdk_free(ns_list); return 0; } @@ -440,7 +439,7 @@ get_allocated_nsid(struct dev *dev) printf("%u\n", ns_list->ns_list[i]); } - rte_free(ns_list); + spdk_free(ns_list); printf("Please Input Namespace ID: \n"); if (!scanf("%u", &nsid)) { @@ -457,8 +456,8 @@ ns_attach(struct dev *device, int attachment_op, int ctrlr_id, int ns_id) int ret = 0; struct spdk_nvme_ctrlr_list *ctrlr_list; - ctrlr_list = rte_zmalloc("nvme controller list", sizeof(struct spdk_nvme_ctrlr_list), - 4096); + ctrlr_list = spdk_zmalloc(sizeof(struct spdk_nvme_ctrlr_list), + 4096, NULL); if (ctrlr_list == NULL) { printf("Allocation error (controller list)\n"); exit(1); @@ -477,7 +476,7 @@ ns_attach(struct dev *device, int attachment_op, int ctrlr_id, int ns_id) fprintf(stdout, "ns attach: Failed\n"); } - rte_free(ctrlr_list); + spdk_free(ctrlr_list); } static void @@ -487,7 +486,7 @@ ns_manage_add(struct dev *device, uint64_t ns_size, uint64_t ns_capacity, int ns uint32_t nsid; struct spdk_nvme_ns_data *ndata; - ndata = rte_zmalloc("nvme namespace data", sizeof(struct spdk_nvme_ns_data), 4096); + ndata = spdk_zmalloc(sizeof(struct spdk_nvme_ns_data), 4096, NULL); if (ndata == NULL) { printf("Allocation error (namespace data)\n"); exit(1); @@ -508,7 +507,7 @@ ns_manage_add(struct dev *device, uint64_t ns_size, uint64_t ns_capacity, int ns printf("Created namespace ID %u\n", nsid); } - rte_free(ndata); + spdk_free(ndata); } static void @@ -849,7 +848,7 @@ update_firmware_image(void) size = fw_stat.st_size; - fw_image = rte_zmalloc("firmware image", size, 4096); + fw_image = spdk_zmalloc(size, 4096, NULL); if (fw_image == NULL) { printf("Allocation error\n"); close(fd); @@ -859,7 +858,7 @@ update_firmware_image(void) if (read(fd, fw_image, size) != ((ssize_t)(size))) { printf("Read firmware image failed\n"); close(fd); - rte_free(fw_image); + spdk_free(fw_image); return; } close(fd); @@ -867,7 +866,7 @@ update_firmware_image(void) printf("Please Input Slot(0 - 7): \n"); if (!scanf("%d", &slot)) { printf("Invalid Slot\n"); - rte_free(fw_image); + spdk_free(fw_image); while (getchar() != '\n'); return; } @@ -878,7 +877,7 @@ update_firmware_image(void) } else { printf("spdk_nvme_ctrlr_update_firmware success\n"); } - rte_free(fw_image); + spdk_free(fw_image); } int main(int argc, char **argv) diff --git a/examples/nvme/perf/perf.c b/examples/nvme/perf/perf.c index 2d3ba1433..2717a4266 100644 --- a/examples/nvme/perf/perf.c +++ b/examples/nvme/perf/perf.c @@ -39,7 +39,6 @@ #include #include #include -#include #include #include "spdk/fd.h" @@ -259,8 +258,8 @@ register_ctrlr(struct spdk_nvme_ctrlr *ctrlr) exit(1); } - entry->latency_page = rte_zmalloc("nvme latency", sizeof(struct spdk_nvme_intel_rw_latency_page), - 4096); + entry->latency_page = spdk_zmalloc(sizeof(struct spdk_nvme_intel_rw_latency_page), + 4096, NULL); if (entry->latency_page == NULL) { printf("Allocation error (latency page)\n"); exit(1); @@ -388,9 +387,9 @@ aio_check_io(struct ns_worker_ctx *ns_ctx) static void task_ctor(struct rte_mempool *mp, void *arg, void *__task, unsigned id) { struct perf_task *task = __task; - task->buf = rte_malloc(NULL, g_io_size_bytes, 0x200); + task->buf = spdk_zmalloc(g_io_size_bytes, 0x200, NULL); if (task->buf == NULL) { - fprintf(stderr, "task->buf rte_malloc failed\n"); + fprintf(stderr, "task->buf spdk_zmalloc failed\n"); exit(1); } memset(task->buf, id % 8, g_io_size_bytes); @@ -1008,7 +1007,7 @@ unregister_controllers(void) while (entry) { struct ctrlr_entry *next = entry->next; - rte_free(entry->latency_page); + spdk_free(entry->latency_page); if (g_latency_tracking_enable && spdk_nvme_ctrlr_is_feature_supported(entry->ctrlr, SPDK_NVME_INTEL_FEAT_LATENCY_TRACKING)) set_latency_tracking_feature(entry->ctrlr, false); diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index f08d817b5..e0db48f0c 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -40,7 +40,6 @@ #include #include -#include #include #include #include diff --git a/lib/bdev/malloc/blockdev_malloc.c b/lib/bdev/malloc/blockdev_malloc.c index 698c0b793..deac05b7d 100644 --- a/lib/bdev/malloc/blockdev_malloc.c +++ b/lib/bdev/malloc/blockdev_malloc.c @@ -35,13 +35,13 @@ #include #include #include -#include #include #include "blockdev_malloc.h" #include "spdk/bdev.h" #include "spdk/conf.h" #include "spdk/endian.h" +#include "spdk/env.h" #include "spdk/log.h" #include "spdk/copy_engine.h" #include "spdk/io_channel.h" @@ -120,8 +120,8 @@ blockdev_malloc_destruct(struct spdk_bdev *bdev) { struct malloc_disk *malloc_disk = (struct malloc_disk *)bdev; blockdev_malloc_delete_from_list(malloc_disk); - rte_free(malloc_disk->malloc_buf); - rte_free(malloc_disk); + spdk_free(malloc_disk->malloc_buf); + spdk_free(malloc_disk); return 0; } @@ -369,25 +369,22 @@ struct malloc_disk *create_malloc_disk(uint64_t num_blocks, uint32_t block_size) return NULL; } - mdisk = rte_malloc(NULL, sizeof(*mdisk), 0); + mdisk = spdk_zmalloc(sizeof(*mdisk), 0, NULL); if (!mdisk) { perror("mdisk"); return NULL; } - memset(mdisk, 0, sizeof(*mdisk)); - /* - * Allocate the large backend memory buffer using rte_malloc(), - * so that we guarantee it is allocated from hugepage memory. + * Allocate the large backend memory buffer from pinned memory. * * TODO: need to pass a hint so we know which socket to allocate * from on multi-socket systems. */ - mdisk->malloc_buf = rte_zmalloc(NULL, num_blocks * block_size, 2 * 1024 * 1024); + mdisk->malloc_buf = spdk_zmalloc(num_blocks * block_size, 2 * 1024 * 1024, NULL); if (!mdisk->malloc_buf) { - SPDK_ERRLOG("rte_zmalloc failed\n"); - rte_free(mdisk); + SPDK_ERRLOG("spdk_zmalloc failed\n"); + spdk_free(mdisk); return NULL; } @@ -414,8 +411,8 @@ struct malloc_disk *create_malloc_disk(uint64_t num_blocks, uint32_t block_size) static void free_malloc_disk(struct malloc_disk *mdisk) { - rte_free(mdisk->malloc_buf); - rte_free(mdisk); + spdk_free(mdisk->malloc_buf); + spdk_free(mdisk); } static int blockdev_malloc_initialize(void) diff --git a/lib/bdev/nvme/blockdev_nvme.c b/lib/bdev/nvme/blockdev_nvme.c index 4ca990832..4c203dfeb 100644 --- a/lib/bdev/nvme/blockdev_nvme.c +++ b/lib/bdev/nvme/blockdev_nvme.c @@ -44,7 +44,6 @@ #include #include #include -#include #include "spdk/conf.h" #include "spdk/endian.h" diff --git a/lib/copy/ioat/copy_engine_ioat.c b/lib/copy/ioat/copy_engine_ioat.c index 1b5ac4e80..34fc7d0f8 100644 --- a/lib/copy/ioat/copy_engine_ioat.c +++ b/lib/copy/ioat/copy_engine_ioat.c @@ -36,7 +36,6 @@ #include #include -#include #include #include @@ -140,7 +139,7 @@ copy_engine_ioat_exit(void) TAILQ_REMOVE(&g_devices, dev, tailq); spdk_ioat_detach(dev->ioat); ioat_free_device(dev); - rte_free(dev); + spdk_free(dev); } return; } @@ -272,7 +271,7 @@ attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_ioat_chan * { struct ioat_device *dev; - dev = rte_malloc(NULL, sizeof(*dev), 0); + dev = spdk_zmalloc(sizeof(*dev), 0, NULL); if (dev == NULL) { SPDK_ERRLOG("Failed to allocate device struct\n"); return; diff --git a/lib/env/env.c b/lib/env/env.c index 2ba21f1b6..5a41c9234 100644 --- a/lib/env/env.c +++ b/lib/env/env.c @@ -48,7 +48,9 @@ spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr) void *buf = rte_malloc(NULL, size, align); if (buf) { memset(buf, 0, size); - *phys_addr = rte_malloc_virt2phy(buf); + if (phys_addr) { + *phys_addr = rte_malloc_virt2phy(buf); + } } return buf; } diff --git a/lib/iscsi/iscsi.c b/lib/iscsi/iscsi.c index 01aa3a6b1..9abdc3a06 100644 --- a/lib/iscsi/iscsi.c +++ b/lib/iscsi/iscsi.c @@ -53,7 +53,6 @@ #include #include #include -#include #include #include #include @@ -68,7 +67,6 @@ #include #include #include -#include #include "spdk/endian.h" #include "spdk/trace.h" diff --git a/lib/iscsi/iscsi_subsystem.c b/lib/iscsi/iscsi_subsystem.c index bfa2f75c7..360c96521 100644 --- a/lib/iscsi/iscsi_subsystem.c +++ b/lib/iscsi/iscsi_subsystem.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -50,7 +49,6 @@ #include #include #include -#include #include #include @@ -63,7 +61,9 @@ #include "iscsi/acceptor.h" #include "iscsi/conn.h" #include "iscsi/task.h" + #include "spdk/event.h" +#include "spdk/env.h" #include "spdk/log.h" #define ISCSI_CONFIG_TMPL \ @@ -613,7 +613,7 @@ spdk_iscsi_app_read_parameters(void) g_spdk_iscsi.MaxSessions = MaxSessions; SPDK_TRACELOG(SPDK_TRACE_DEBUG, "MaxSessions %d\n", g_spdk_iscsi.MaxSessions); - g_spdk_iscsi.session = rte_malloc(NULL, sizeof(void *) * g_spdk_iscsi.MaxSessions, 0); + g_spdk_iscsi.session = spdk_zmalloc(sizeof(void *) * g_spdk_iscsi.MaxSessions, 0, NULL); if (!g_spdk_iscsi.session) { perror("Unable to allocate session pointer array\n"); return -1; diff --git a/lib/nvmf/rdma.c b/lib/nvmf/rdma.c index 874de4b85..97a48e456 100644 --- a/lib/nvmf/rdma.c +++ b/lib/nvmf/rdma.c @@ -43,7 +43,6 @@ #include #include #include -#include #include "nvmf_internal.h" #include "request.h" @@ -202,9 +201,9 @@ spdk_nvmf_rdma_conn_destroy(struct spdk_nvmf_rdma_conn *rdma_conn) } /* Free all memory */ - rte_free(rdma_conn->cmds); - rte_free(rdma_conn->cpls); - rte_free(rdma_conn->bufs); + spdk_free(rdma_conn->cmds); + spdk_free(rdma_conn->cpls); + spdk_free(rdma_conn->bufs); free(rdma_conn->reqs); free(rdma_conn); } @@ -264,12 +263,12 @@ spdk_nvmf_rdma_conn_create(struct rdma_cm_id *id, struct ibv_comp_channel *chann SPDK_TRACELOG(SPDK_TRACE_RDMA, "New RDMA Connection: %p\n", conn); rdma_conn->reqs = calloc(max_queue_depth, sizeof(*rdma_conn->reqs)); - rdma_conn->cmds = rte_calloc("nvmf_rdma_cmd", max_queue_depth, - sizeof(*rdma_conn->cmds), 0x1000); - rdma_conn->cpls = rte_calloc("nvmf_rdma_cpl", max_queue_depth, - sizeof(*rdma_conn->cpls), 0x1000); - rdma_conn->bufs = rte_calloc("nvmf_rdma_buf", max_queue_depth, - g_rdma.in_capsule_data_size, 0x1000); + rdma_conn->cmds = spdk_zmalloc(max_queue_depth * sizeof(*rdma_conn->cmds), + 0x1000, NULL); + rdma_conn->cpls = spdk_zmalloc(max_queue_depth * sizeof(*rdma_conn->cpls), + 0x1000, NULL); + rdma_conn->bufs = spdk_zmalloc(max_queue_depth * g_rdma.in_capsule_data_size, + 0x1000, NULL); if (!rdma_conn->reqs || !rdma_conn->cmds || !rdma_conn->cpls || !rdma_conn->bufs) { SPDK_ERRLOG("Unable to allocate sufficient memory for RDMA queue.\n"); spdk_nvmf_rdma_conn_destroy(rdma_conn); @@ -984,8 +983,8 @@ spdk_nvmf_rdma_session_init(struct spdk_nvmf_session *session, struct spdk_nvmf_ /* TODO: Make the number of elements in this pool configurable. For now, one full queue * worth seems reasonable. */ - rdma_sess->buf = rte_calloc("large_buf_pool", g_rdma.max_queue_depth, g_rdma.max_io_size, - 0x20000); + rdma_sess->buf = spdk_zmalloc(g_rdma.max_queue_depth * g_rdma.max_io_size, + 0x20000, NULL); if (!rdma_sess->buf) { SPDK_ERRLOG("Large buffer pool allocation failed (%d x %d)\n", g_rdma.max_queue_depth, g_rdma.max_io_size); @@ -998,7 +997,7 @@ spdk_nvmf_rdma_session_init(struct spdk_nvmf_session *session, struct spdk_nvmf_ if (!rdma_sess->buf_mr) { SPDK_ERRLOG("Large buffer pool registration failed (%d x %d)\n", g_rdma.max_queue_depth, g_rdma.max_io_size); - rte_free(rdma_sess->buf); + spdk_free(rdma_sess->buf); free(rdma_sess); return -1; } @@ -1028,7 +1027,7 @@ spdk_nvmf_rdma_session_fini(struct spdk_nvmf_session *session) } rdma_dereg_mr(rdma_sess->buf_mr); - rte_free(rdma_sess->buf); + spdk_free(rdma_sess->buf); free(rdma_sess); session->trctx = NULL; } diff --git a/lib/scsi/task.c b/lib/scsi/task.c index 5ec2e3c9e..77309c97c 100644 --- a/lib/scsi/task.c +++ b/lib/scsi/task.c @@ -34,9 +34,7 @@ #include "scsi_internal.h" #include "spdk/endian.h" - -#include -#include +#include "spdk/env.h" void spdk_scsi_task_put(struct spdk_scsi_task *task) @@ -62,7 +60,7 @@ spdk_scsi_task_put(struct spdk_scsi_task *task) } spdk_bdev_free_io(bdev_io); } else { - rte_free(task->rbuf); + spdk_free(task->rbuf); } task->rbuf = NULL; @@ -127,7 +125,7 @@ spdk_scsi_task_alloc_data(struct spdk_scsi_task *task, uint32_t alloc_len, task->alloc_len = alloc_len; if (task->rbuf == NULL) { - task->rbuf = rte_malloc(NULL, alloc_len, 0); + task->rbuf = spdk_zmalloc(alloc_len, 0, NULL); } *data = task->rbuf; memset(task->rbuf, 0, task->alloc_len); diff --git a/test/lib/bdev/bdevio/bdevio.c b/test/lib/bdev/bdevio/bdevio.c index 3de231c58..602dbd699 100644 --- a/test/lib/bdev/bdevio/bdevio.c +++ b/test/lib/bdev/bdevio/bdevio.c @@ -38,11 +38,11 @@ #include #include -#include #include #include "spdk/bdev.h" #include "spdk/copy_engine.h" +#include "spdk/env.h" #include "spdk/log.h" #include "CUnit/Basic.h" @@ -93,7 +93,7 @@ static enum spdk_bdev_io_status completion_status_per_io; static void initialize_buffer(char **buf, int pattern, int size) { - *buf = rte_malloc(NULL, size, 0x1000); + *buf = spdk_zmalloc(size, 0x1000, NULL); memset(*buf, pattern, size); } @@ -174,8 +174,8 @@ blockdev_write_read_data_match(char *rx_buf, char *tx_buf, int data_length) int rc; rc = memcmp(rx_buf, tx_buf, data_length); - rte_free(rx_buf); - rte_free(tx_buf); + spdk_free(rx_buf); + spdk_free(tx_buf); return rc; } diff --git a/test/lib/bdev/bdevperf/bdevperf.c b/test/lib/bdev/bdevperf/bdevperf.c index 1ada7b4d6..08dd744a6 100644 --- a/test/lib/bdev/bdevperf/bdevperf.c +++ b/test/lib/bdev/bdevperf/bdevperf.c @@ -42,13 +42,13 @@ #include #include #include -#include #include #include #include "spdk/bdev.h" #include "spdk/copy_engine.h" #include "spdk/endian.h" +#include "spdk/env.h" #include "spdk/event.h" #include "spdk/log.h" #include "spdk/io_channel.h" @@ -288,7 +288,7 @@ task_ctor(struct rte_mempool *mp, void *arg, void *__task, unsigned id) { struct bdevperf_task *task = __task; - task->buf = rte_malloc(NULL, g_io_size, g_min_alignment); + task->buf = spdk_zmalloc(g_io_size, g_min_alignment, NULL); } static __thread unsigned int seed = 0; diff --git a/test/lib/env/vtophys.c b/test/lib/env/vtophys.c index a9dbd3db5..2c7d7094e 100644 --- a/test/lib/env/vtophys.c +++ b/test/lib/env/vtophys.c @@ -38,7 +38,6 @@ #include #include #include -#include #include "spdk/env.h" @@ -96,18 +95,18 @@ vtophys_positive_test(void) int rc = 0; for (i = 0; i < 31; i++) { - p = rte_malloc("vtophys_test", size, 512); + p = spdk_zmalloc(size, 512, NULL); if (p == NULL) continue; if (spdk_vtophys(p) == SPDK_VTOPHYS_ERROR) { rc = -1; printf("Err: VA=%p is not mapped to a huge_page,\n", p); - rte_free(p); + spdk_free(p); break; } - rte_free(p); + spdk_free(p); size = size << 1; } diff --git a/test/lib/event/event/event.c b/test/lib/event/event/event.c index 145958850..3a50bb170 100644 --- a/test/lib/event/event/event.c +++ b/test/lib/event/event/event.c @@ -41,7 +41,6 @@ #include #include #include -#include #include #include diff --git a/test/lib/nvme/aer/aer.c b/test/lib/nvme/aer/aer.c index a6d7ae817..122f6ceae 100644 --- a/test/lib/nvme/aer/aer.c +++ b/test/lib/nvme/aer/aer.c @@ -34,7 +34,6 @@ #include #include -#include #include #include @@ -158,7 +157,7 @@ cleanup(void) foreach_dev(dev) { if (dev->health_page) { - rte_free(dev->health_page); + spdk_free(dev->health_page); } } } @@ -215,7 +214,7 @@ attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr printf("Attached to %s\n", dev->name); - dev->health_page = rte_zmalloc("nvme health", sizeof(*dev->health_page), 4096); + dev->health_page = spdk_zmalloc(sizeof(*dev->health_page), 4096, NULL); if (dev->health_page == NULL) { printf("Allocation error (health page)\n"); failed = 1; diff --git a/test/lib/nvme/e2edp/nvme_dp.c b/test/lib/nvme/e2edp/nvme_dp.c index a0f426992..5393032e8 100644 --- a/test/lib/nvme/e2edp/nvme_dp.c +++ b/test/lib/nvme/e2edp/nvme_dp.c @@ -40,7 +40,6 @@ #include #include -#include #include #include @@ -181,7 +180,7 @@ static uint32_t dp_guard_check_extended_lba_test(struct spdk_nvme_ns *ns, struct sector_size = spdk_nvme_ns_get_sector_size(ns); md_size = spdk_nvme_ns_get_md_size(ns); - req->contig = rte_zmalloc(NULL, (sector_size + md_size) * req->lba_count, 0x1000); + req->contig = spdk_zmalloc((sector_size + md_size) * req->lba_count, 0x1000, NULL); if (!req->contig) return 0; @@ -217,7 +216,7 @@ static uint32_t dp_with_pract_test(struct spdk_nvme_ns *ns, struct io_request *r sector_size = spdk_nvme_ns_get_sector_size(ns); /* No additional metadata buffer provided */ - req->contig = rte_zmalloc(NULL, sector_size * req->lba_count, 0x1000); + req->contig = spdk_zmalloc(sector_size * req->lba_count, 0x1000, NULL); if (!req->contig) return 0; @@ -264,7 +263,7 @@ static uint32_t dp_without_pract_extended_lba_test(struct spdk_nvme_ns *ns, stru sector_size = spdk_nvme_ns_get_sector_size(ns); md_size = spdk_nvme_ns_get_md_size(ns); - req->contig = rte_zmalloc(NULL, (sector_size + md_size) * req->lba_count, 0x1000); + req->contig = spdk_zmalloc((sector_size + md_size) * req->lba_count, 0x1000, NULL); if (!req->contig) return 0; @@ -298,7 +297,7 @@ static uint32_t dp_without_flags_extended_lba_test(struct spdk_nvme_ns *ns, stru sector_size = spdk_nvme_ns_get_sector_size(ns); md_size = spdk_nvme_ns_get_md_size(ns); - req->contig = rte_zmalloc(NULL, (sector_size + md_size) * req->lba_count, 0x1000); + req->contig = spdk_zmalloc((sector_size + md_size) * req->lba_count, 0x1000, NULL); if (!req->contig) return 0; @@ -332,13 +331,13 @@ static uint32_t dp_without_pract_separate_meta_test(struct spdk_nvme_ns *ns, str sector_size = spdk_nvme_ns_get_sector_size(ns); md_size = spdk_nvme_ns_get_md_size(ns); - req->contig = rte_zmalloc(NULL, sector_size * req->lba_count, 0x1000); + req->contig = spdk_zmalloc(sector_size * req->lba_count, 0x1000, NULL); if (!req->contig) return 0; - req->metadata = rte_zmalloc(NULL, md_size * req->lba_count, 0x1000); + req->metadata = spdk_zmalloc(md_size * req->lba_count, 0x1000, NULL); if (!req->metadata) { - rte_free(req->contig); + spdk_free(req->contig); return 0; } @@ -375,13 +374,13 @@ static uint32_t dp_without_pract_separate_meta_apptag_test(struct spdk_nvme_ns * sector_size = spdk_nvme_ns_get_sector_size(ns); md_size = spdk_nvme_ns_get_md_size(ns); - req->contig = rte_zmalloc(NULL, sector_size * req->lba_count, 0x1000); + req->contig = spdk_zmalloc(sector_size * req->lba_count, 0x1000, NULL); if (!req->contig) return 0; - req->metadata = rte_zmalloc(NULL, md_size * req->lba_count, 0x1000); + req->metadata = spdk_zmalloc(md_size * req->lba_count, 0x1000, NULL); if (!req->metadata) { - rte_free(req->contig); + spdk_free(req->contig); return 0; } @@ -416,13 +415,13 @@ static uint32_t dp_without_flags_separate_meta_test(struct spdk_nvme_ns *ns, str sector_size = spdk_nvme_ns_get_sector_size(ns); md_size = spdk_nvme_ns_get_md_size(ns); - req->contig = rte_zmalloc(NULL, sector_size * req->lba_count, 0x1000); + req->contig = spdk_zmalloc(sector_size * req->lba_count, 0x1000, NULL); if (!req->contig) return 0; - req->metadata = rte_zmalloc(NULL, md_size * req->lba_count, 0x1000); + req->metadata = spdk_zmalloc(md_size * req->lba_count, 0x1000, NULL); if (!req->metadata) { - rte_free(req->contig); + spdk_free(req->contig); return 0; } @@ -444,12 +443,12 @@ free_req(struct io_request *req) } if (req->contig) - rte_free(req->contig); + spdk_free(req->contig); if (req->metadata) - rte_free(req->metadata); + spdk_free(req->metadata); - rte_free(req); + spdk_free(req); } static int @@ -506,7 +505,7 @@ write_read_e2e_dp_tests(struct dev *dev, nvme_build_io_req_fn_t build_io_fn, con return 0; } - req = rte_zmalloc(NULL, sizeof(*req), 0); + req = spdk_zmalloc(sizeof(*req), 0, NULL); if (!req) { fprintf(stderr, "Allocate request failed\n"); return 0; diff --git a/test/lib/nvme/overhead/overhead.c b/test/lib/nvme/overhead/overhead.c index b3a3d374c..c478cdb3a 100644 --- a/test/lib/nvme/overhead/overhead.c +++ b/test/lib/nvme/overhead/overhead.c @@ -39,7 +39,6 @@ #include #include #include -#include #include #include "spdk/fd.h" @@ -601,15 +600,15 @@ int main(int argc, char **argv) return 1; } - g_task = rte_zmalloc("task", sizeof(struct perf_task), 0); + g_task = spdk_zmalloc(sizeof(struct perf_task), 0, NULL); if (g_task == NULL) { fprintf(stderr, "g_task alloc failed\n"); exit(1); } - g_task->buf = rte_malloc(NULL, g_io_size_bytes, 0x1000); + g_task->buf = spdk_zmalloc(g_io_size_bytes, 0x1000, NULL); if (g_task->buf == NULL) { - fprintf(stderr, "g_task->buf rte_malloc failed\n"); + fprintf(stderr, "g_task->buf spdk_zmalloc failed\n"); exit(1); } diff --git a/test/lib/nvme/reset/reset.c b/test/lib/nvme/reset/reset.c index bfd1e0473..1d5612a9b 100644 --- a/test/lib/nvme/reset/reset.c +++ b/test/lib/nvme/reset/reset.c @@ -39,7 +39,6 @@ #include #include #include -#include #include #include "spdk/nvme.h" @@ -156,9 +155,9 @@ static void task_ctor(struct rte_mempool *mp, void *arg, void *__task, unsigned { struct reset_task *task = __task; - task->buf = rte_malloc(NULL, g_io_size_bytes, 0x200); + task->buf = spdk_zmalloc(g_io_size_bytes, 0x200, NULL); if (task->buf == NULL) { - fprintf(stderr, "task->buf rte_malloc failed\n"); + fprintf(stderr, "task->buf spdk_zmalloc failed\n"); exit(1); } } diff --git a/test/lib/nvme/sgl/nvme_sgl.c b/test/lib/nvme/sgl/nvme_sgl.c index 4f3d381cb..c3b32bd45 100644 --- a/test/lib/nvme/sgl/nvme_sgl.c +++ b/test/lib/nvme/sgl/nvme_sgl.c @@ -36,7 +36,6 @@ #include #include -#include #include #include @@ -136,7 +135,7 @@ static void build_io_request_0(struct io_request *req) { req->nseg = 1; - req->iovs[0].base = rte_zmalloc(NULL, 0x800, 4); + req->iovs[0].base = spdk_zmalloc(0x800, 4, NULL); req->iovs[0].len = 0x800; } @@ -145,7 +144,7 @@ static void build_io_request_1(struct io_request *req) req->nseg = 1; /* 512B for 1st sge */ - req->iovs[0].base = rte_zmalloc(NULL, 0x200, 0x200); + req->iovs[0].base = spdk_zmalloc(0x200, 0x200, NULL); req->iovs[0].len = 0x200; } @@ -154,7 +153,7 @@ static void build_io_request_2(struct io_request *req) req->nseg = 1; /* 256KB for 1st sge */ - req->iovs[0].base = rte_zmalloc(NULL, 0x40000, 0x1000); + req->iovs[0].base = spdk_zmalloc(0x40000, 0x1000, NULL); req->iovs[0].len = 0x40000; } @@ -164,16 +163,16 @@ static void build_io_request_3(struct io_request *req) /* 2KB for 1st sge, make sure the iov address start at 0x800 boundary, * and end with 0x1000 boundary */ - req->iovs[0].base = rte_zmalloc(NULL, 0x1000, 0x1000); + req->iovs[0].base = spdk_zmalloc(0x1000, 0x1000, NULL); req->iovs[0].offset = 0x800; req->iovs[0].len = 0x800; /* 4KB for 2th sge */ - req->iovs[1].base = rte_zmalloc(NULL, 0x1000, 0x1000); + req->iovs[1].base = spdk_zmalloc(0x1000, 0x1000, NULL); req->iovs[1].len = 0x1000; /* 12KB for 3th sge */ - req->iovs[2].base = rte_zmalloc(NULL, 0x3000, 0x1000); + req->iovs[2].base = spdk_zmalloc(0x3000, 0x1000, NULL); req->iovs[2].len = 0x3000; } @@ -184,12 +183,12 @@ static void build_io_request_4(struct io_request *req) req->nseg = 32; /* 4KB for 1st sge */ - req->iovs[0].base = rte_zmalloc(NULL, 0x1000, 0x1000); + req->iovs[0].base = spdk_zmalloc(0x1000, 0x1000, NULL); req->iovs[0].len = 0x1000; /* 8KB for the rest 31 sge */ for (i = 1; i < req->nseg; i++) { - req->iovs[i].base = rte_zmalloc(NULL, 0x2000, 0x1000); + req->iovs[i].base = spdk_zmalloc(0x2000, 0x1000, NULL); req->iovs[i].len = 0x2000; } } @@ -199,7 +198,7 @@ static void build_io_request_5(struct io_request *req) req->nseg = 1; /* 8KB for 1st sge */ - req->iovs[0].base = rte_zmalloc(NULL, 0x2000, 0x1000); + req->iovs[0].base = spdk_zmalloc(0x2000, 0x1000, NULL); req->iovs[0].len = 0x2000; } @@ -208,11 +207,11 @@ static void build_io_request_6(struct io_request *req) req->nseg = 2; /* 4KB for 1st sge */ - req->iovs[0].base = rte_zmalloc(NULL, 0x1000, 0x1000); + req->iovs[0].base = spdk_zmalloc(0x1000, 0x1000, NULL); req->iovs[0].len = 0x1000; /* 4KB for 2st sge */ - req->iovs[1].base = rte_zmalloc(NULL, 0x1000, 0x1000); + req->iovs[1].base = spdk_zmalloc(0x1000, 0x1000, NULL); req->iovs[1].len = 0x1000; } @@ -228,10 +227,10 @@ free_req(struct io_request *req) } for (i = 0; i < req->nseg; i++) { - rte_free(req->iovs[i].base); + spdk_free(req->iovs[i].base); } - rte_free(req); + spdk_free(req); } static int @@ -258,7 +257,7 @@ writev_readv_tests(struct dev *dev, nvme_build_io_req_fn_t build_io_fn, const ch return 0; } - req = rte_zmalloc(NULL, sizeof(*req), 0); + req = spdk_zmalloc(sizeof(*req), 0, NULL); if (!req) { fprintf(stderr, "Allocate request failed\n"); return 0; @@ -271,7 +270,7 @@ writev_readv_tests(struct dev *dev, nvme_build_io_req_fn_t build_io_fn, const ch for (i = 0; i < req->nseg; i++) { struct sgl_element *sge = &req->iovs[i]; - sge->phys_addr = rte_malloc_virt2phy(sge->base) + sge->offset; + sge->phys_addr = spdk_vtophys(sge->base) + sge->offset; len += sge->len; } diff --git a/test/lib/nvmf/nvmf/nvmf_ut.c b/test/lib/nvmf/nvmf/nvmf_ut.c index 66af34751..bad697139 100644 --- a/test/lib/nvmf/nvmf/nvmf_ut.c +++ b/test/lib/nvmf/nvmf/nvmf_ut.c @@ -37,7 +37,6 @@ #include #include -#include #include #include