From 955c58fa68f2f2fb4dbbb49444e9e943bcd71b83 Mon Sep 17 00:00:00 2001 From: Tomasz Zawadzki Date: Fri, 27 Mar 2020 07:22:24 -0400 Subject: [PATCH] lib/blob: change replay of extent pages to batching Before this patch reading out the extent pages during blobstore replay was serialized. Only issuing reads for next extent page when previous operation finished. This was done by continously calling _spdk_bs_load_replay_extent_page_cpl() and decreasing ctx->num_extent_pages. This patch changes spdk_bs_sequence_* to spdk_bs_batch_*. All the reads are submitted at once, and only when all of them finish we proceed to next valid md chain. Goal of this change is improving efficiency and readability. Signed-off-by: Tomasz Zawadzki Change-Id: I807cdb98166e04706fedb494363f5776e3151827 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1540 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- lib/blob/blobstore.c | 68 +++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/lib/blob/blobstore.c b/lib/blob/blobstore.c index 21a9dec17..67e58d6a4 100644 --- a/lib/blob/blobstore.c +++ b/lib/blob/blobstore.c @@ -3917,13 +3917,12 @@ _spdk_bs_load_replay_md_chain_cpl(struct spdk_bs_load_ctx *ctx) } } -static void _spdk_bs_load_replay_extent_page(spdk_bs_sequence_t *seq, uint32_t page, void *cb_arg); - static void _spdk_bs_load_replay_extent_page_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int bserrno) { struct spdk_bs_load_ctx *ctx = cb_arg; uint32_t page_num; + uint64_t i; if (bserrno != 0) { spdk_free(ctx->extent_pages); @@ -3931,53 +3930,58 @@ _spdk_bs_load_replay_extent_page_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int return; } - /* Extent pages are only read when present within in chain md. - * Integrity of md is not right if that page was not a valid extent page. */ - if (_spdk_bs_load_cur_extent_page_valid(&ctx->extent_pages[0]) != true) { - spdk_free(ctx->extent_pages); - _spdk_bs_load_ctx_fail(ctx, -EILSEQ); - return; - } + for (i = 0; i < ctx->num_extent_pages; i++) { + /* Extent pages are only read when present within in chain md. + * Integrity of md is not right if that page was not a valid extent page. */ + if (_spdk_bs_load_cur_extent_page_valid(&ctx->extent_pages[i]) != true) { + spdk_free(ctx->extent_pages); + _spdk_bs_load_ctx_fail(ctx, -EILSEQ); + return; + } - page_num = ctx->extent_page_num[ctx->num_extent_pages - 1]; - spdk_bit_array_set(ctx->bs->used_md_pages, page_num); - if (_spdk_bs_load_replay_md_parse_page(ctx, &ctx->extent_pages[0])) { - spdk_free(ctx->extent_pages); - _spdk_bs_load_ctx_fail(ctx, -EILSEQ); - return; - } - - ctx->num_extent_pages--; - if (ctx->num_extent_pages > 0) { - spdk_free(ctx->extent_pages); - _spdk_bs_load_replay_extent_page(seq, ctx->extent_page_num[ctx->num_extent_pages - 1], ctx); - return; + page_num = ctx->extent_page_num[i]; + spdk_bit_array_set(ctx->bs->used_md_pages, page_num); + if (_spdk_bs_load_replay_md_parse_page(ctx, &ctx->extent_pages[i])) { + spdk_free(ctx->extent_pages); + _spdk_bs_load_ctx_fail(ctx, -EILSEQ); + return; + } } spdk_free(ctx->extent_pages); free(ctx->extent_page_num); ctx->extent_page_num = NULL; + ctx->num_extent_pages = 0; _spdk_bs_load_replay_md_chain_cpl(ctx); } static void -_spdk_bs_load_replay_extent_page(spdk_bs_sequence_t *seq, uint32_t page, void *cb_arg) +_spdk_bs_load_replay_extent_pages(struct spdk_bs_load_ctx *ctx) { - struct spdk_bs_load_ctx *ctx = cb_arg; + spdk_bs_batch_t *batch; + uint32_t page; uint64_t lba; + uint64_t i; - ctx->extent_pages = spdk_zmalloc(SPDK_BS_PAGE_SIZE, SPDK_BS_PAGE_SIZE, + ctx->extent_pages = spdk_zmalloc(SPDK_BS_PAGE_SIZE * ctx->num_extent_pages, SPDK_BS_PAGE_SIZE, NULL, SPDK_ENV_SOCKET_ID_ANY, SPDK_MALLOC_DMA); if (!ctx->extent_pages) { _spdk_bs_load_ctx_fail(ctx, -ENOMEM); return; } - assert(page < ctx->super->md_len); - lba = _spdk_bs_md_page_to_lba(ctx->bs, page); - spdk_bs_sequence_read_dev(seq, &ctx->extent_pages[0], lba, - _spdk_bs_byte_to_lba(ctx->bs, SPDK_BS_PAGE_SIZE), - _spdk_bs_load_replay_extent_page_cpl, ctx); + + batch = spdk_bs_sequence_to_batch(ctx->seq, _spdk_bs_load_replay_extent_page_cpl, ctx); + + for (i = 0; i < ctx->num_extent_pages; i++) { + page = ctx->extent_page_num[i]; + assert(page < ctx->super->md_len); + lba = _spdk_bs_md_page_to_lba(ctx->bs, page); + spdk_bs_batch_read_dev(batch, &ctx->extent_pages[i], lba, + _spdk_bs_byte_to_lba(ctx->bs, SPDK_BS_PAGE_SIZE)); + } + + spdk_bs_batch_close(batch); } static void @@ -4011,9 +4015,7 @@ _spdk_bs_load_replay_md_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int bserrno) return; } if (ctx->num_extent_pages != 0) { - /* Extent pages are read from last to first, - * decreasing the num_extent_pages as they are read. */ - _spdk_bs_load_replay_extent_page(seq, ctx->extent_page_num[ctx->num_extent_pages - 1], ctx); + _spdk_bs_load_replay_extent_pages(ctx); return; } }