Skip to contentSkip to conversation

io_opt fixups

PATCH In review Christoph Hellwig 7 participants 15 messages Jul 1, 2024

Subsystems (2)
lore
Share & tools
lore

Christoph Hellwig

author maintainer
#0 lore raw

Hi all,

I recently noticed that on my test VMs with the Qemu NVMe emulations I see a zero max_setors_kb limit in sysfs. It turns out Qemu advertises a one-LBA optimal write size, which is a bit silly.

This series handles this odd case properly both in the block layer and the nvme driver as a sort of defense in depth.

Diffstat:

 block/blk-settings.c     |    5 ++---
 drivers/nvme/host/core.c |    3 ++-
 2 files changed, 4 insertions(+), 4 deletions(-)
author maintainer
#1 lore raw

PATCH 1/3 block: remove a duplicate io_min check in blk_validate_limits

If io_min is larger than the cap, it must by definition be non-zero.

---
 block/blk-settings.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
block/blk-settings.c +1 -2
index 2e559cf97cc834..ff8bbc101fedaa 100644
@@ -279,8 +279,7 @@ static int blk_validate_limits(struct queue_limits *lim)
 	} else if (lim->io_opt) {
 		lim->max_sectors =
 			min(max_hw_sectors, lim->io_opt >> SECTOR_SHIFT);
-	} else if (lim->io_min &&
-		   lim->io_min > (BLK_DEF_MAX_SECTORS_CAP << SECTOR_SHIFT)) {
+	} else if (lim->io_min > (BLK_DEF_MAX_SECTORS_CAP << SECTOR_SHIFT)) {
 		lim->max_sectors =
 			min(max_hw_sectors, lim->io_min >> SECTOR_SHIFT);
 	} else {
Signature · 1 line
2.43.0
author maintainer
#4 lore raw

PATCH 2/3 block: don't reduce max_sectors based on io_opt

In reply to Christoph Hellwig

Don't reduce the max_sectors value below the normal cap when the driver advertsizes a very low io_opt. This restores the behavior we had before the recent changes to the max_sectors calculation.

---
 block/blk-settings.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-settings.c +1 -1
index ff8bbc101fedaa..9fa4eed4df06b0 100644
@@ -276,7 +276,7 @@ static int blk_validate_limits(struct queue_limits *lim)
 		if (lim->max_user_sectors < PAGE_SIZE / SECTOR_SIZE)
 			return -EINVAL;
 		lim->max_sectors = min(max_hw_sectors, lim->max_user_sectors);
-	} else if (lim->io_opt) {
+	} else if (lim->io_opt > (BLK_DEF_MAX_SECTORS_CAP << SECTOR_SHIFT)) {
 		lim->max_sectors =
 			min(max_hw_sectors, lim->io_opt >> SECTOR_SHIFT);
 	} else if (lim->io_min > (BLK_DEF_MAX_SECTORS_CAP << SECTOR_SHIFT)) {
Signature · 1 line
2.43.0
author maintainer
#7 lore raw

PATCH 3/3 nvme: don't set io_opt if NOWS is zero

In reply to Christoph Hellwig

NOWS is one of the annoying "0's based values" in NVMe, where 0 means one and we thus can't detect if it isn't set. Thus a NOWS value of 0 means that the Namespace Optimal Write Size is a single LBA, which is clearly bogus. Ignore the value in that case and don't propagate an io_opt value to the block layer.

---
 drivers/nvme/host/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +2 -1
index ab0429644fe378..6784fc6e95625e 100644
@@ -2025,7 +2025,8 @@ static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *id,
 		/* NPWG = Namespace Preferred Write Granularity */
 		phys_bs = bs * (1 + le16_to_cpu(id->npwg));
 		/* NOWS = Namespace Optimal Write Size */
-		io_opt = bs * (1 + le16_to_cpu(id->nows));
+		if (id->nows)
+			io_opt = bs * (1 + le16_to_cpu(id->nows));
 	}
 
 	/*
Signature · 1 line
2.43.0
Reviewed-by on v1 3/3
#8 lore raw

Re: [PATCH 3/3] nvme: don't set io_opt if NOWS is zero

Quoted 7 lines · Christoph Hellwig

NOWS is one of the annoying "0's based values" in NVMe, where 0 means one and we thus can't detect if it isn't set. Thus a NOWS value of 0 means that the Namespace Optimal Write Size is a single LBA, which is clearly bogus. Ignore the value in that case and don't propagate an io_opt value to the block layer.

indeed (Figure 97: Identify -> Namespace Optimal Write Size (NOWS)).

wonder why can't spec use 0xFFFF to indicate not supported for all zero based values to avoid this confusion ?

Looks good.

-ck

maintainer
#10 lore raw

Re: [PATCH 3/3] nvme: don't set io_opt if NOWS is zero

In reply to Christoph Hellwig
Quoted 2 lines · Christoph Hellwig

NOWS is one of the annoying "0's based values" in NVMe, where 0 means one and we thus can't detect if it isn't set.

We can detect if it is set based on the namespace features flags, though.

Quoted 4 lines

Thus a NOWS value of 0 means
that the Namespace Optimal Write Size is a single LBA, which is clearly bogus. Ignore the value in that case and don't propagate an io_opt value to the block layer.

Hm, why is that clearly bogus? Optane SSDs were optimized for single-sector writes.

author maintainer
#11 lore raw

Re: [PATCH 3/3] nvme: don't set io_opt if NOWS is zero

Quoted 6 lines · Keith Busch
Quoted 2 lines · Christoph Hellwig

NOWS is one of the annoying "0's based values" in NVMe, where 0 means one and we thus can't detect if it isn't set.

We can detect if it is set based on the namespace features flags, though.

Except that the flag covers 5 different flags, for 2 different operations.

Quoted 7 lines
Quoted 4 lines

Thus a NOWS value of 0 means
that the Namespace Optimal Write Size is a single LBA, which is clearly bogus. Ignore the value in that case and don't propagate an io_opt value to the block layer.

Hm, why is that clearly bogus? Optane SSDs were optimized for single-sector writes.

Because even if they optimize for it, the pure overhead of both the PCIe physical layer, nvme command overhead and software overhead will never make it more optimal to split a larger I/O down to this size, which the optimal write size is about.

Reviewed-by
#12 lore raw
In reply to Christoph Hellwig
Quoted 6 lines · Christoph Hellwig

Hi all,

I recently noticed that on my test VMs with the Qemu NVMe emulations I see a zero max_setors_kb limit in sysfs. It turns out Qemu advertises a one-LBA optimal write size, which is a bit silly.

Quoted 7 lines

This series handles this odd case properly both in the block layer and the nvme driver as a sort of defense in depth.

Diffstat:

block/blk-settings.c     |    5 ++---
drivers/nvme/host/core.c |    3 ++-
2 files changed, 4 insertions(+), 4 deletions(-)
maintainer Applied
#14 lore raw
In reply to Christoph Hellwig
Quoted 8 lines · Christoph Hellwig

I recently noticed that on my test VMs with the Qemu NVMe emulations I see a zero max_setors_kb limit in sysfs. It turns out Qemu advertises a one-LBA optimal write size, which is a bit silly.

This series handles this odd case properly both in the block layer and the nvme driver as a sort of defense in depth.

[...]

Applied, thanks!

[1/3] block: remove a duplicate io_min check in blk_validate_limits

      commit: f62e8edc0a9fda84fe5bf32d5f5874b489d6c301
[2/3] block: don't reduce max_sectors based on io_opt
      commit: 37105615f73125cb0466c09796f277a4c46d9295
[3/3] nvme: don't set io_opt if NOWS is zero
      commit: f3bf25d5135539603f24e377c6dec3016fbd9786

Best regards,

Signature · 1 line
Jens Axboe