From dd54dff78bfe667cb840773d46e7760400a128c6 Mon Sep 17 00:00:00 2001 From: Wojciech Malikowski Date: Wed, 27 Mar 2019 11:23:53 -0400 Subject: [PATCH] lib/ftl: Keep DMA buffer for metadata as part of ftl_md structure This patch is starting point for metadata refactor which is needed for efficient ANM events support. Change-Id: I81d864605e69008d8e3922fb61adf504187447a1 Signed-off-by: Wojciech Malikowski Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/449328 Tested-by: SPDK CI Jenkins Reviewed-by: Konrad Sztyber Reviewed-by: Darek Stojaczyk Reviewed-by: Shuhei Matsumoto --- lib/ftl/ftl_band.c | 9 +++++++++ lib/ftl/ftl_band.h | 5 ++++- lib/ftl/ftl_core.c | 15 ++------------- lib/ftl/ftl_reloc.c | 12 +----------- test/unit/lib/ftl/common/utils.c | 1 + test/unit/lib/ftl/ftl_md/ftl_md_ut.c | 2 +- 6 files changed, 18 insertions(+), 26 deletions(-) diff --git a/lib/ftl/ftl_band.c b/lib/ftl/ftl_band.c index 6654bafa8..ee52354f7 100644 --- a/lib/ftl/ftl_band.c +++ b/lib/ftl/ftl_band.c @@ -174,7 +174,9 @@ ftl_band_free_md(struct ftl_band *band) } spdk_mempool_put(dev->lba_pool, md->lba_map); + spdk_dma_free(md->dma_buf); md->lba_map = NULL; + md->dma_buf = NULL; } static void @@ -660,6 +662,13 @@ ftl_band_alloc_md(struct ftl_band *band) return -1; } + md->dma_buf = spdk_dma_zmalloc(ftl_tail_md_num_lbks(dev) * FTL_BLOCK_SIZE, + FTL_BLOCK_SIZE, NULL); + if (!md->dma_buf) { + spdk_mempool_put(dev->lba_pool, md->lba_map); + return -1; + } + ftl_band_acquire_md(band); return 0; } diff --git a/lib/ftl/ftl_band.h b/lib/ftl/ftl_band.h index 4a9788511..a8bf2ee9a 100644 --- a/lib/ftl/ftl_band.h +++ b/lib/ftl/ftl_band.h @@ -100,8 +100,11 @@ struct ftl_md { /* Bitmap of valid LBAs */ struct spdk_bit_array *vld_map; - /* LBA map (only valid for open bands) */ + /* LBA map (only valid for open/relocating bands) */ uint64_t *lba_map; + + /* Metadata DMA buffer (only valid for open/relocating bands) */ + void *dma_buf; }; enum ftl_band_state { diff --git a/lib/ftl/ftl_core.c b/lib/ftl/ftl_core.c index e7be9a34e..b099fafc5 100644 --- a/lib/ftl/ftl_core.c +++ b/lib/ftl/ftl_core.c @@ -66,9 +66,6 @@ struct ftl_wptr { /* Current erase block */ struct ftl_chunk *chunk; - /* Metadata DMA buffer */ - void *md_buf; - /* List link */ LIST_ENTRY(ftl_wptr) list_entry; }; @@ -114,7 +111,6 @@ ftl_wptr_free(struct ftl_wptr *wptr) return; } - spdk_dma_free(wptr->md_buf); free(wptr); } @@ -253,7 +249,7 @@ ftl_wptr_close_band(struct ftl_wptr *wptr) ftl_band_set_state(band, FTL_BAND_STATE_CLOSING); band->tail_md_ppa = wptr->ppa; - return ftl_band_write_tail_md(band, wptr->md_buf, ftl_md_write_cb); + return ftl_band_write_tail_md(band, band->md.dma_buf, ftl_md_write_cb); } static int @@ -269,7 +265,7 @@ ftl_wptr_open_band(struct ftl_wptr *wptr) assert(band->state == FTL_BAND_STATE_PREP); ftl_band_set_state(band, FTL_BAND_STATE_OPENING); - return ftl_band_write_head_md(band, wptr->md_buf, ftl_md_write_cb); + return ftl_band_write_head_md(band, band->md.dma_buf, ftl_md_write_cb); } static int @@ -390,13 +386,6 @@ ftl_wptr_init(struct ftl_band *band) return NULL; } - wptr->md_buf = spdk_dma_zmalloc(ftl_tail_md_num_lbks(dev) * FTL_BLOCK_SIZE, - FTL_BLOCK_SIZE, NULL); - if (!wptr->md_buf) { - ftl_wptr_free(wptr); - return NULL; - } - wptr->dev = dev; wptr->band = band; wptr->chunk = CIRCLEQ_FIRST(&band->chunks); diff --git a/lib/ftl/ftl_reloc.c b/lib/ftl/ftl_reloc.c index 1d5648aed..412de3d9d 100644 --- a/lib/ftl/ftl_reloc.c +++ b/lib/ftl/ftl_reloc.c @@ -77,9 +77,6 @@ struct ftl_band_reloc { struct spdk_ring *write_queue; TAILQ_ENTRY(ftl_band_reloc) entry; - - /* TODO: get rid of md_buf */ - void *md_buf; }; struct ftl_reloc { @@ -172,7 +169,6 @@ ftl_reloc_read_lba_map_cb(void *arg, int status) struct ftl_band_reloc *breloc = ftl_io_get_band_reloc(io); assert(status == 0); - spdk_dma_free(breloc->md_buf); ftl_io_free(io); _ftl_reloc_prep(breloc); } @@ -189,17 +185,11 @@ ftl_reloc_read_lba_map(struct ftl_band_reloc *breloc) io->cb.ctx = io; io->cb.fn = ftl_reloc_read_lba_map_cb; - breloc->md_buf = spdk_dma_zmalloc(ftl_lba_map_num_lbks(dev) * FTL_BLOCK_SIZE, - FTL_BLOCK_SIZE, NULL); - if (!breloc->md_buf) { - return -1; - } - if (ftl_band_alloc_md(band)) { assert(false); } - return ftl_band_read_lba_map(band, &band->md, breloc->md_buf, &io->cb); + return ftl_band_read_lba_map(band, &band->md, band->md.dma_buf, &io->cb); } static void diff --git a/test/unit/lib/ftl/common/utils.c b/test/unit/lib/ftl/common/utils.c index 975c5527b..840071a6c 100644 --- a/test/unit/lib/ftl/common/utils.c +++ b/test/unit/lib/ftl/common/utils.c @@ -133,6 +133,7 @@ test_free_ftl_band(struct ftl_band *band) spdk_bit_array_free(&band->md.vld_map); free(band->chunk_buf); free(band->md.lba_map); + spdk_dma_free(band->md.dma_buf); } uint64_t diff --git a/test/unit/lib/ftl/ftl_md/ftl_md_ut.c b/test/unit/lib/ftl/ftl_md/ftl_md_ut.c index 0b03f194c..53e634328 100644 --- a/test/unit/lib/ftl/ftl_md/ftl_md_ut.c +++ b/test/unit/lib/ftl/ftl_md/ftl_md_ut.c @@ -63,7 +63,7 @@ setup_band(struct ftl_band **band, const struct spdk_ocssd_geometry_data *geo, dev = test_init_ftl_dev(geo, range); *band = test_init_ftl_band(dev, 0); rc = ftl_band_alloc_md(*band); - CU_ASSERT_EQUAL_FATAL(rc, 0); + SPDK_CU_ASSERT_FATAL(rc == 0); ftl_band_clear_md(*band); }