Skip to content

Commit 08095e7

Browse files
Keith Buschaxboe
authored andcommitted
NVMe: Create discard zero quirk white list
The NVMe specification does not require discarded blocks return zeroes on read, but provides that behavior as a possibility. Some applications more efficiently use an SSD if reads on discarded blocks were deterministically zero, based on the "discard_zeroes_data" queue attribute. There is no specification defined way to determine device behavior on discarded blocks, so the driver always left the queue setting disabled. We can only know behavior based on individual device models, so this patch adds a flag to the NVMe "quirk" list that vendors may set if they know their controller works that way. The patch also sets the new flag for one such known device. Signed-off-by: Keith Busch <keith.busch@intel.com> Suggested-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de> Reviewed-by: Sagi Grimberg <sagig@mellanox.com> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 5e454c6 commit 08095e7

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

drivers/nvme/host/core.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,14 @@ static void nvme_init_integrity(struct nvme_ns *ns)
582582

583583
static void nvme_config_discard(struct nvme_ns *ns)
584584
{
585+
struct nvme_ctrl *ctrl = ns->ctrl;
585586
u32 logical_block_size = queue_logical_block_size(ns->queue);
586-
ns->queue->limits.discard_zeroes_data = 0;
587+
588+
if (ctrl->quirks & NVME_QUIRK_DISCARD_ZEROES)
589+
ns->queue->limits.discard_zeroes_data = 1;
590+
else
591+
ns->queue->limits.discard_zeroes_data = 0;
592+
587593
ns->queue->limits.discard_alignment = logical_block_size;
588594
ns->queue->limits.discard_granularity = logical_block_size;
589595
blk_queue_max_discard_sectors(ns->queue, 0xffffffff);

drivers/nvme/host/nvme.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ enum nvme_quirks {
5959
* correctly.
6060
*/
6161
NVME_QUIRK_IDENTIFY_CNS = (1 << 1),
62+
63+
/*
64+
* The controller deterministically returns O's on reads to discarded
65+
* logical blocks.
66+
*/
67+
NVME_QUIRK_DISCARD_ZEROES = (1 << 2),
6268
};
6369

6470
struct nvme_ctrl {

drivers/nvme/host/pci.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,8 @@ static const struct pci_error_handlers nvme_err_handler = {
21302130

21312131
static const struct pci_device_id nvme_id_table[] = {
21322132
{ PCI_VDEVICE(INTEL, 0x0953),
2133-
.driver_data = NVME_QUIRK_STRIPE_SIZE, },
2133+
.driver_data = NVME_QUIRK_STRIPE_SIZE |
2134+
NVME_QUIRK_DISCARD_ZEROES, },
21342135
{ PCI_VDEVICE(INTEL, 0x5845), /* Qemu emulated controller */
21352136
.driver_data = NVME_QUIRK_IDENTIFY_CNS, },
21362137
{ PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_EXPRESS, 0xffffff) },

0 commit comments

Comments
 (0)