diff --git a/lib/ftl/ftl_core.c b/lib/ftl/ftl_core.c index c5dda3f77..3c9de5ba3 100644 --- a/lib/ftl/ftl_core.c +++ b/lib/ftl/ftl_core.c @@ -216,6 +216,7 @@ ftl_get_next_batch(struct spdk_ftl_dev *dev) struct ftl_wbuf_entry *entries[FTL_DEQUEUE_ENTRIES]; TAILQ_HEAD(, ftl_io_channel) ioch_queue; size_t i, num_dequeued, num_remaining; + uint64_t *metadata; if (batch == NULL) { batch = TAILQ_FIRST(&dev->free_batches); @@ -251,6 +252,13 @@ ftl_get_next_batch(struct spdk_ftl_dev *dev) for (i = 0; i < num_dequeued; ++i) { batch->iov[batch->num_entries + i].iov_base = entries[i]->payload; batch->iov[batch->num_entries + i].iov_len = FTL_BLOCK_SIZE; + + if (batch->metadata != NULL) { + metadata = (uint64_t *)((char *)batch->metadata + + i * dev->md_size); + *metadata = entries[i]->lba; + } + TAILQ_INSERT_TAIL(&batch->entries, entries[i], tailq); } diff --git a/lib/ftl/ftl_core.h b/lib/ftl/ftl_core.h index aed7353e5..e02689dae 100644 --- a/lib/ftl/ftl_core.h +++ b/lib/ftl/ftl_core.h @@ -115,6 +115,7 @@ struct ftl_batch { /* Index within spdk_ftl_dev.batch_array */ uint32_t index; struct iovec *iov; + void *metadata; TAILQ_ENTRY(ftl_batch) tailq; }; @@ -188,6 +189,7 @@ struct spdk_ftl_dev { /* Metadata size */ size_t md_size; + void *md_buf; /* Transfer unit size */ size_t xfer_size; diff --git a/lib/ftl/ftl_init.c b/lib/ftl/ftl_init.c index 7386c687e..e5e9237eb 100644 --- a/lib/ftl/ftl_init.c +++ b/lib/ftl/ftl_init.c @@ -1208,6 +1208,16 @@ ftl_dev_init_io_channel(struct spdk_ftl_dev *dev) return -1; } + if (dev->md_size > 0) { + dev->md_buf = spdk_zmalloc(dev->md_size * dev->xfer_size * FTL_BATCH_COUNT, + dev->md_size, NULL, SPDK_ENV_LCORE_ID_ANY, + SPDK_MALLOC_DMA); + if (dev->md_buf == NULL) { + SPDK_ERRLOG("Failed to allocate metadata buffer\n"); + return -1; + } + } + dev->iov_buf = calloc(FTL_BATCH_COUNT, dev->xfer_size * sizeof(struct iovec)); if (!dev->iov_buf) { SPDK_ERRLOG("Failed to allocate iovec buffer\n"); @@ -1223,6 +1233,10 @@ ftl_dev_init_io_channel(struct spdk_ftl_dev *dev) batch->num_entries = 0; batch->index = i; TAILQ_INIT(&batch->entries); + if (dev->md_buf != NULL) { + batch->metadata = (char *)dev->md_buf + i * dev->xfer_size * dev->md_size; + } + TAILQ_INSERT_TAIL(&dev->free_batches, batch, tailq); } @@ -1367,6 +1381,8 @@ ftl_dev_free_sync(struct spdk_ftl_dev *dev) ftl_release_bdev(dev->nv_cache.bdev_desc); ftl_release_bdev(dev->base_bdev_desc); + spdk_free(dev->md_buf); + assert(dev->num_io_channels == 0); free(dev->ioch_array); free(dev->iov_buf);