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 <smatsumoto@nvidia.com>
Change-Id: Iac83a1f16b908d8b36b51d9c51782de40313b6c8
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17909
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
This commit is contained in:
Shuhei Matsumoto 2023-05-02 16:51:17 +09:00 committed by David Ko
parent 05580566e8
commit fa2c6446fa
2 changed files with 27 additions and 14 deletions

View File

@ -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;

View File

@ -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