Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Zhang Yi and committed by
Christian Brauner
545fb46e 0c40d7cb

+11 -9
+11 -9
drivers/nvme/host/core.c
··· 2420 2420 else 2421 2421 lim.write_stream_granularity = 0; 2422 2422 2423 + /* 2424 + * Only set the DEAC bit if the device guarantees that reads from 2425 + * deallocated data return zeroes. While the DEAC bit does not 2426 + * require that, it must be a no-op if reads from deallocated data 2427 + * do not return zeroes. 2428 + */ 2429 + if ((id->dlfeat & 0x7) == 0x1 && (id->dlfeat & (1 << 3))) { 2430 + ns->head->features |= NVME_NS_DEAC; 2431 + lim.max_hw_wzeroes_unmap_sectors = lim.max_write_zeroes_sectors; 2432 + } 2433 + 2423 2434 ret = queue_limits_commit_update(ns->disk->queue, &lim); 2424 2435 if (ret) { 2425 2436 blk_mq_unfreeze_queue(ns->disk->queue, memflags); ··· 2438 2427 } 2439 2428 2440 2429 set_capacity_and_notify(ns->disk, capacity); 2441 - 2442 - /* 2443 - * Only set the DEAC bit if the device guarantees that reads from 2444 - * deallocated data return zeroes. While the DEAC bit does not 2445 - * require that, it must be a no-op if reads from deallocated data 2446 - * do not return zeroes. 2447 - */ 2448 - if ((id->dlfeat & 0x7) == 0x1 && (id->dlfeat & (1 << 3))) 2449 - ns->head->features |= NVME_NS_DEAC; 2450 2430 set_disk_ro(ns->disk, nvme_ns_is_readonly(ns, info)); 2451 2431 set_bit(NVME_NS_READY, &ns->flags); 2452 2432 blk_mq_unfreeze_queue(ns->disk->queue, memflags);