lib/blob: chunk spdk_bs_init to exact multiple of sector size

During spdk_bs_init() data present on the device can be cleared
depending on the clear_method used.

Picking BS_CLEAR_WITH_UNMAP results in deallocate command sent
when NVMe device is used.

The size of logical blocks do not have to match the indirection unit
size (IU) of the device. The SSDs can only unmap full physical blocks.
Since the deallocate command is advisory, the controller can complete
the command without deallocating any blocks.

In practice this results in some controllers not deallocating any blocks
if number of logical blocks is not aligned to the IU size.

Make sure that spdk_bs_init() handles this case.
The size of the unmap is now chunked at UINT32_MAX - 127,
which is an even multiple of 512B blocks with a 64KiB IU.

This is already addressed with an API change in SPDK 21.10:
(f01146ae)blob: use uint64_t for unmap and write_zeroes lba count

Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: Ie00bd5ae7cdaec4f1486f16fceb6cb18e30bf563
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9970
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Tomasz Zawadzki 2021-10-22 10:23:33 +02:00
parent 10807f35f9
commit ca470ff844

View File

@ -4917,7 +4917,7 @@ spdk_bs_init(struct spdk_bs_dev *dev, struct spdk_bs_opts *o,
lba = num_md_lba;
while (lba < ctx->bs->dev->blockcnt) {
lba_count = spdk_min(UINT32_MAX, ctx->bs->dev->blockcnt - lba);
lba_count = spdk_min(UINT32_MAX - 127, ctx->bs->dev->blockcnt - lba);
switch (opts.clear_method) {
case BS_CLEAR_WITH_UNMAP:
/* Trim data clusters */