Skip to content

Commit 545fb46

Browse files
zhangyi089brauner
authored andcommitted
nvme: set max_hw_wzeroes_unmap_sectors if device supports DEAC bit
When the device supports the Write Zeroes command and the DEAC bit, it indicates that the deallocate bit in the Write Zeroes command is supported, and the bytes read from a deallocated logical block are zeroes. This means the device supports unmap Write Zeroes operation, so set the max_hw_wzeroes_unmap_sectors to max_write_zeroes_sectors on the device's queue limit. Signed-off-by: Zhang Yi <yi.zhang@huawei.com> Link: https://lore.kernel.org/20250619111806.3546162-3-yi.zhang@huaweicloud.com Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: "Martin K. Petersen" <martin.petersen@oracle.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 0c40d7c commit 545fb46

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

drivers/nvme/host/core.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,22 +2420,24 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
24202420
else
24212421
lim.write_stream_granularity = 0;
24222422

2423-
ret = queue_limits_commit_update(ns->disk->queue, &lim);
2424-
if (ret) {
2425-
blk_mq_unfreeze_queue(ns->disk->queue, memflags);
2426-
goto out;
2427-
}
2428-
2429-
set_capacity_and_notify(ns->disk, capacity);
2430-
24312423
/*
24322424
* Only set the DEAC bit if the device guarantees that reads from
24332425
* deallocated data return zeroes. While the DEAC bit does not
24342426
* require that, it must be a no-op if reads from deallocated data
24352427
* do not return zeroes.
24362428
*/
2437-
if ((id->dlfeat & 0x7) == 0x1 && (id->dlfeat & (1 << 3)))
2429+
if ((id->dlfeat & 0x7) == 0x1 && (id->dlfeat & (1 << 3))) {
24382430
ns->head->features |= NVME_NS_DEAC;
2431+
lim.max_hw_wzeroes_unmap_sectors = lim.max_write_zeroes_sectors;
2432+
}
2433+
2434+
ret = queue_limits_commit_update(ns->disk->queue, &lim);
2435+
if (ret) {
2436+
blk_mq_unfreeze_queue(ns->disk->queue, memflags);
2437+
goto out;
2438+
}
2439+
2440+
set_capacity_and_notify(ns->disk, capacity);
24392441
set_disk_ro(ns->disk, nvme_ns_is_readonly(ns, info));
24402442
set_bit(NVME_NS_READY, &ns->flags);
24412443
blk_mq_unfreeze_queue(ns->disk->queue, memflags);

0 commit comments

Comments
 (0)