From fa2c6446fadbb3acd91115b31c461719e9b856fc Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Tue, 2 May 2023 16:51:17 +0900 Subject: [PATCH] bdev: Calculate max_copy once at bdev registration for fallback case Calculation of max copy size for fallback case includes division and is costly. The result is constant for each bdev. Hence we can calculate it only once and store it into bdev->max_copy at bdev registration. Calculation of max copy size for fallback case is almost same as calculation of max write zero size for fallback case. To reuse the calculation, the helper function is named as bdev_get_max_write() and has a num_bytes parameter. Signed-off-by: Shuhei Matsumoto Change-Id: Iac83a1f16b908d8b36b51d9c51782de40313b6c8 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17909 Reviewed-by: Aleksey Marchuk Reviewed-by: Jim Harris Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot --- lib/bdev/bdev.c | 33 +++++++++++++++++------------ test/unit/lib/bdev/part.c/part_ut.c | 8 +++++++ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index 50c08fffa..a03706ba8 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -4704,23 +4704,22 @@ spdk_bdev_is_dif_check_enabled(const struct spdk_bdev *bdev, } } +static uint32_t +bdev_get_max_write(const struct spdk_bdev *bdev, uint64_t num_bytes) +{ + uint64_t aligned_length, max_write_blocks; + + aligned_length = num_bytes - (spdk_bdev_get_buf_align(bdev) - 1); + max_write_blocks = aligned_length / _bdev_get_block_size_with_md(bdev); + max_write_blocks -= max_write_blocks % bdev->write_unit_size; + + return max_write_blocks; +} + uint32_t spdk_bdev_get_max_copy(const struct spdk_bdev *bdev) { - uint64_t aligned_length; - uint64_t max_copy_blocks; - struct spdk_iobuf_opts opts; - - if (spdk_bdev_io_type_supported((struct spdk_bdev *)bdev, SPDK_BDEV_IO_TYPE_COPY)) { - return bdev->max_copy; - } else { - spdk_iobuf_get_opts(&opts); - aligned_length = opts.large_bufsize - (spdk_bdev_get_buf_align(bdev) - 1); - max_copy_blocks = aligned_length / _bdev_get_block_size_with_md(bdev); - max_copy_blocks -= max_copy_blocks % bdev->write_unit_size; - - return max_copy_blocks; - } + return bdev->max_copy; } uint64_t @@ -7321,6 +7320,7 @@ bdev_register(struct spdk_bdev *bdev) { char *bdev_name; char uuid[SPDK_UUID_STRING_LEN]; + struct spdk_iobuf_opts iobuf_opts; int ret, i; assert(bdev->module != NULL); @@ -7434,6 +7434,11 @@ bdev_register(struct spdk_bdev *bdev) bdev->phys_blocklen = spdk_bdev_get_data_block_size(bdev); } + if (!bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_COPY)) { + spdk_iobuf_get_opts(&iobuf_opts); + bdev->max_copy = bdev_get_max_write(bdev, iobuf_opts.large_bufsize); + } + bdev->internal.reset_in_progress = NULL; bdev->internal.qd_poll_in_progress = false; bdev->internal.period = 0; diff --git a/test/unit/lib/bdev/part.c/part_ut.c b/test/unit/lib/bdev/part.c/part_ut.c index f84f5c152..36dc766e8 100644 --- a/test/unit/lib/bdev/part.c/part_ut.c +++ b/test/unit/lib/bdev/part.c/part_ut.c @@ -205,12 +205,20 @@ __destruct(void *ctx) return 0; } +static bool +__io_type_supported(void *ctx, enum spdk_bdev_io_type type) +{ + return true; +} + static struct spdk_bdev_fn_table base_fn_table = { .destruct = __destruct, .get_io_channel = part_ut_get_io_channel, + .io_type_supported = __io_type_supported, }; static struct spdk_bdev_fn_table part_fn_table = { .destruct = __destruct, + .io_type_supported = __io_type_supported, }; static void