From 1dadcd8786386adf99ec44ed01ba9c106cd17eca Mon Sep 17 00:00:00 2001 From: Artur Paszkiewicz Date: Tue, 14 Jun 2022 10:19:37 +0200 Subject: [PATCH] ftl: ftl_rq helpers for compaction Signed-off-by: Artur Paszkiewicz Signed-off-by: Kozlowski Mateusz Change-Id: I614b29e7bc7f6db20b10395bc780ff633c497b59 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13336 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- lib/ftl/Makefile | 2 +- lib/ftl/ftl_io.h | 3 ++ lib/ftl/ftl_rq.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 lib/ftl/ftl_rq.c diff --git a/lib/ftl/Makefile b/lib/ftl/Makefile index f1711b520..cadd187a1 100644 --- a/lib/ftl/Makefile +++ b/lib/ftl/Makefile @@ -22,7 +22,7 @@ CFLAGS += -I. FTL_SUBDIRS := mngt utils C_SRCS = ftl_core.c ftl_init.c ftl_layout.c ftl_debug.c ftl_io.c ftl_sb.c ftl_l2p.c ftl_l2p_flat.c -C_SRCS += ftl_nv_cache.c ftl_band.c ftl_band_ops.c ftl_writer.c +C_SRCS += ftl_nv_cache.c ftl_band.c ftl_band_ops.c ftl_writer.c ftl_rq.c C_SRCS += mngt/ftl_mngt.c mngt/ftl_mngt_bdev.c mngt/ftl_mngt_shutdown.c mngt/ftl_mngt_startup.c C_SRCS += mngt/ftl_mngt_md.c mngt/ftl_mngt_misc.c mngt/ftl_mngt_ioch.c mngt/ftl_mngt_l2p.c C_SRCS += mngt/ftl_mngt_band.c diff --git a/lib/ftl/ftl_io.h b/lib/ftl/ftl_io.h index 50aed3cc7..4375de305 100644 --- a/lib/ftl/ftl_io.h +++ b/lib/ftl/ftl_io.h @@ -299,6 +299,9 @@ int ftl_io_init(struct spdk_io_channel *ioch, struct ftl_io *io, uint64_t lba, size_t num_blocks, struct iovec *iov, size_t iov_cnt, spdk_ftl_fn cb_fn, void *cb_arg, int type); void ftl_io_complete(struct ftl_io *io); +void ftl_rq_del(struct ftl_rq *rq); +struct ftl_rq *ftl_rq_new(struct spdk_ftl_dev *dev, uint32_t io_md_size); +void ftl_rq_unpin(struct ftl_rq *rq); static inline void ftl_basic_rq_init(struct spdk_ftl_dev *dev, struct ftl_basic_rq *brq, diff --git a/lib/ftl/ftl_rq.c b/lib/ftl/ftl_rq.c new file mode 100644 index 000000000..bc1ead29e --- /dev/null +++ b/lib/ftl/ftl_rq.c @@ -0,0 +1,111 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) Intel Corporation. + * All rights reserved. + */ + +#include "spdk/ftl.h" +#include "spdk/env.h" + +#include "ftl_io.h" +#include "ftl_core.h" + +struct ftl_rq * +ftl_rq_new(struct spdk_ftl_dev *dev, uint32_t io_md_size) +{ + struct ftl_rq *rq; + struct ftl_rq_entry *entry; + struct iovec *io_vec; + void *io_payload, *io_md = NULL; + uint64_t i; + size_t size; + uint32_t num_blocks = dev->xfer_size; + + size = sizeof(*rq) + (sizeof(rq->entries[0]) * num_blocks); + rq = calloc(1, size); + if (!rq) { + return NULL; + } + rq->dev = dev; + rq->num_blocks = num_blocks; + + /* Allocate payload for IO and IO vector */ + io_payload = rq->io_payload = spdk_zmalloc(FTL_BLOCK_SIZE * num_blocks, + FTL_BLOCK_SIZE, NULL, SPDK_ENV_LCORE_ID_ANY, + SPDK_MALLOC_DMA); + if (!io_payload) { + goto error; + } + rq->io_vec = calloc(num_blocks, sizeof(rq->io_vec[0])); + if (!rq->io_vec) { + goto error; + } + rq->io_vec_size = num_blocks; + + /* Allocate extended metadata for IO */ + if (io_md_size) { + rq->io_md_size = io_md_size; + io_md = rq->io_md = spdk_zmalloc(io_md_size * num_blocks, + FTL_BLOCK_SIZE, NULL, + SPDK_ENV_LCORE_ID_ANY, + SPDK_MALLOC_DMA); + if (!io_md) { + goto error; + } + } + + entry = rq->entries; + io_vec = rq->io_vec; + for (i = 0; i < num_blocks; ++i) { + uint64_t *index = (uint64_t *)&entry->index; + *index = i; + + entry->addr = FTL_ADDR_INVALID; + entry->lba = FTL_LBA_INVALID; + entry->io_payload = io_payload; + + if (io_md_size) { + entry->io_md = io_md; + } + + io_vec->iov_base = io_payload; + io_vec->iov_len = FTL_BLOCK_SIZE; + + entry++; + io_vec++; + io_payload += FTL_BLOCK_SIZE; + io_md += io_md_size; + } + + return rq; +error: + ftl_rq_del(rq); + return NULL; +} + +void +ftl_rq_del(struct ftl_rq *rq) +{ + if (!rq) { + return; + } + + spdk_free(rq->io_payload); + spdk_free(rq->io_md); + free(rq->io_vec); + + free(rq); +} + +void +ftl_rq_unpin(struct ftl_rq *rq) +{ + struct ftl_l2p_pin_ctx *pin_ctx; + uint64_t i; + + for (i = 0; i < rq->iter.count; i++) { + pin_ctx = &rq->entries[i].l2p_pin_ctx; + if (pin_ctx->lba != FTL_LBA_INVALID) { + ftl_l2p_unpin(rq->dev, pin_ctx->lba, pin_ctx->count); + } + } +}