io_opt fixups
Subsystems (2)
Christoph Hellwig
maintainerHi 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(-)
Christoph Hellwig
maintainerPATCH 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
@@ -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
Re: [PATCH 1/3] block: remove a duplicate io_min check in blk_validate_limits
Quoted 3 lines · Christoph Hellwig
If
io_minis larger than the cap, it must by definition be non-zero.Signed-off-by Christoph Hellwig<[email protected]>
given that BLK_DEF_MAX_SECTORS_CAP = 2560u.
Looks good.
-ck
Re: [PATCH 1/3] block: remove a duplicate io_min check in blk_validate_limits
In reply to Christoph HellwigChristoph Hellwig
maintainerPATCH 2/3 block: don't reduce max_sectors based on io_opt
In reply to Christoph HellwigDon'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
@@ -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
Re: [PATCH 2/3] block: don't reduce max_sectors based on io_opt
Quoted 6 lines · Christoph Hellwig
Don't reduce the
max_sectorsvalue below the normal cap when the driver advertsizes a very lowio_opt. This restores the behavior we had before the recent changes to themax_sectorscalculation.Signed-off-by Christoph Hellwig<[email protected]>---
Looks good.
-ck
Re: [PATCH 2/3] block: don't reduce max_sectors based on io_opt
In reply to Christoph HellwigChristoph Hellwig
maintainerPATCH 3/3 nvme: don't set io_opt if NOWS is zero
In reply to Christoph HellwigNOWS 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
@@ -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
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_optvalue to the block layer.Signed-off-by Christoph Hellwig<[email protected]>
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
Re: [PATCH 3/3] nvme: don't set io_opt if NOWS is zero
In reply to Christoph HellwigKeith Busch
maintainerRe: [PATCH 3/3] nvme: don't set io_opt if NOWS is zero
In reply to Christoph HellwigQuoted 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 anio_optvalue to the block layer.
Hm, why is that clearly bogus? Optane SSDs were optimized for single-sector writes.
Christoph Hellwig
maintainerRe: [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 anio_optvalue 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.
Nitesh Shetty
Reviewed-byQuoted 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_kblimit 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(-)
Johannes Thumshirn
Reviewed-byLooks good,
Quoted 8 lines · Christoph Hellwig
I recently noticed that on my test VMs with the Qemu NVMe emulations I see a zero
max_setors_kblimit 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: f3bf25d5135539603f24e377c6dec3016fbd9786Best regards,
Signature · 1 line
Jens Axboe