dm-ebs: Mark full buffer dirty even on partial write
PATCH RESEND 1/1 dm-ebs: Mark full buffer dirty even on partial write
When performing a read-modify-write(RMW) operation, any modification to a buffered block must cause the entire buffer to be marked dirty.
Marking only a subrange as dirty is incorrect because the underlying device block size(ubs) defines the minimum read/write granularity. A lower device can perform I/O only on regions which are fully aligned and sized to ubs.
This change ensures that write-back operations always occur in full ubs-sized chunks, matching the intended emulation semantics of the EBS target.
As for user space visible impact, submitting sub-ubs and misaligned I/O for devices which are tuned to ubs sizes only, will reject such requests, therefore it can lead to losing data. Example:
1) Create a 8K nvme device in qemu by adding
-device nvme,drive=drv0,serial=foo,logical_block_size=8192,physical_block_size=8192
2) Setup dm-ebs to emulate 512B to 8K mapping
urezki@pc638:~/bin$ cat dmsetup.sh
lower=/dev/nvme0n1
len=$(blockdev --getsz "$lower")
echo "0 $len ebs $lower 0 1 16" | dmsetup create nvme-8k urezki@pc638:~/bin$
offset 0, ebs=1 and ubs=16(in sectors).
3) Create an ext4 filesystem(default 4K block size)
urezki@pc638:~/bin$ sudo mkfs.ext4 -F /dev/dm-0
mke2fs 1.47.0 (5-Feb-2023)
Discarding device blocks: done
Creating filesystem with 2072576 4k blocks and 518144 inodes
Filesystem UUID: bd0b6ca6-0506-4e31-86da-8d22c9d50b63
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: mkfs.ext4: Input/output error while writing out and closing file system
urezki@pc638:~/bin$ dmesg
<snip>
[ 1618.875449] buffer_io_error: 1028 callbacks suppressed [ 1618.875456] Buffer I/O error on dev dm-0, logical block 0, lost async page write [ 1618.875527] Buffer I/O error on dev dm-0, logical block 1, lost async page write [ 1618.875602] Buffer I/O error on dev dm-0, logical block 2, lost async page write [ 1618.875620] Buffer I/O error on dev dm-0, logical block 3, lost async page write [ 1618.875639] Buffer I/O error on dev dm-0, logical block 4, lost async page write [ 1618.894316] Buffer I/O error on dev dm-0, logical block 5, lost async page write [ 1618.894358] Buffer I/O error on dev dm-0, logical block 6, lost async page write [ 1618.894380] Buffer I/O error on dev dm-0, logical block 7, lost async page write [ 1618.894405] Buffer I/O error on dev dm-0, logical block 8, lost async page write [ 1618.894427] Buffer I/O error on dev dm-0, logical block 9, lost async page write
<snip>
Many I/O errors because the lower 8K device rejects sub-ubs/misaligned requests.
with a patch:
urezki@pc638:~/bin$ sudo mkfs.ext4 -F /dev/dm-0
mke2fs 1.47.0 (5-Feb-2023)
Discarding device blocks: done
Creating filesystem with 2072576 4k blocks and 518144 inodes
Filesystem UUID: 9b54f44f-ef55-4bd4-9e40-c8b775a616ac
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
urezki@pc638:~/bin$ sudo mount /dev/dm-0 /mnt/ urezki@pc638:~/bin$ ls -al /mnt/ total 24 drwxr-xr-x 3 root root 4096 Oct 17 15:13 . drwxr-xr-x 19 root root 4096 Jul 10 19:42 .. drwx------ 2 root root 16384 Oct 17 15:13 lost+found urezki@pc638:~/bin$
After this change: mkfs completes; mount succeeds.
v1 -> v2:
- reflect a user space visible impact in the commit message.
--- drivers/md/dm-ebs-target.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-ebs-target.c +1 -1
@@ -103,7 +103,7 @@ static int __ebs_rw_bvec(struct ebs_c *ec, enum req_op op, struct bio_vec *bv, }else {flush_dcache_page (bv->bv_page);memcpy (ba, pa, cur_len); -dm_bufio_mark_partial_buffer_dirty (b, buf_off, buf_off + cur_len); +dm_bufio_mark_buffer_dirty (b); }dm_bufio_release (b);
Signature · 1 line
2.47.3
Mikulas Patocka
maintainerHi
What is the logical_block_size of the underlying nvme device? - i.e. what's the content of this file /sys/block/nvme0n1/queue/logical_block_size in the virtual machine?
Mikulas
Quoted 114 lines · Uladzislau Rezki (Sony)
When performing a read-modify-write(RMW) operation, any modification to a buffered block must cause the entire buffer to be marked dirty.
Marking only a subrange as dirty is incorrect because the underlying device block size(ubs) defines the minimum read/write granularity. A lower device can perform I/O only on regions which are fully aligned and sized to ubs.
This change ensures that write-back operations always occur in full ubs-sized chunks, matching the intended emulation semantics of the EBS target.
As for user space visible impact, submitting sub-ubs and misaligned I/O for devices which are tuned to ubs sizes only, will reject such requests, therefore it can lead to losing data. Example:
1) Create a 8K nvme device in qemu by adding
-device nvme,drive=drv0,serial=foo,logical_block_size=8192,physical_block_size=8192
2) Setup dm-ebs to emulate 512B to 8K mapping
urezki@pc638:~/bin$ cat dmsetup.shlower=/dev/nvme0n1
len=$(blockdev --getsz "$lower")echo "0 $len ebs $lower 0 1 16" | dmsetup create nvme-8k urezki@pc638:~/bin$
offset 0, ebs=1 and ubs=16(in sectors).
3) Create an ext4 filesystem(default 4K block size)
urezki@pc638:~/bin$ sudo mkfs.ext4 -F /dev/dm-0 mke2fs 1.47.0 (5-Feb-2023) Discarding device blocks: done Creating filesystem with 2072576 4k blocks and 518144 inodes Filesystem UUID: bd0b6ca6-0506-4e31-86da-8d22c9d50b63 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: mkfs.ext4: Input/output error while writing out and closing file systemurezki@pc638:~/bin$ dmesg<snip>
[ 1618.875449] buffer_io_error: 1028 callbacks suppressed [ 1618.875456] Buffer I/O error on dev dm-0, logical block 0, lost async page write [ 1618.875527] Buffer I/O error on dev dm-0, logical block 1, lost async page write [ 1618.875602] Buffer I/O error on dev dm-0, logical block 2, lost async page write [ 1618.875620] Buffer I/O error on dev dm-0, logical block 3, lost async page write [ 1618.875639] Buffer I/O error on dev dm-0, logical block 4, lost async page write [ 1618.894316] Buffer I/O error on dev dm-0, logical block 5, lost async page write [ 1618.894358] Buffer I/O error on dev dm-0, logical block 6, lost async page write [ 1618.894380] Buffer I/O error on dev dm-0, logical block 7, lost async page write [ 1618.894405] Buffer I/O error on dev dm-0, logical block 8, lost async page write [ 1618.894427] Buffer I/O error on dev dm-0, logical block 9, lost async page write<snip>
Many I/O errors because the lower 8K device rejects sub-ubs/misaligned requests.
with a patch:
urezki@pc638:~/bin$ sudo mkfs.ext4 -F /dev/dm-0 mke2fs 1.47.0 (5-Feb-2023) Discarding device blocks: done Creating filesystem with 2072576 4k blocks and 518144 inodes Filesystem UUID: 9b54f44f-ef55-4bd4-9e40-c8b775a616ac Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: doneurezki@pc638:~/bin$ sudo mount /dev/dm-0 /mnt/ urezki@pc638:~/bin$ ls -al /mnt/ total 24 drwxr-xr-x 3 root root 4096 Oct 17 15:13 . drwxr-xr-x 19 root root 4096 Jul 10 19:42 .. drwx------ 2 root root 16384 Oct 17 15:13 lost+found urezki@pc638:~/bin$After this change: mkfs completes; mount succeeds.
v1 -> v2:
- reflect a user space visible impact in the commit message.Signed-off-by Uladzislau Rezki (Sony) <[email protected]>--- drivers/md/dm-ebs-target.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/md/dm-ebs-target.c +1
-1@@ -103,7 +103,7 @@ static int __ebs_rw_bvec(struct ebs_c *ec, enum req_op op, struct bio_vec *bv, }else {flush_dcache_page (bv->bv_page);memcpy (ba, pa, cur_len); -dm_bufio_mark_partial_buffer_dirty (b, buf_off, buf_off + cur_len); +dm_bufio_mark_buffer_dirty (b); }dm_bufio_release (b);Signature · 1 line
2.47.3
Hello, Mikulas!
Quoted 6 lines
Hi
What is the
logical_block_sizeof the underlying nvme device? - i.e. what's the content of this file/sys/block/nvme0n1/queue/logical_block_sizein the virtual machine?
It is 512. Whereas a physical is bigger, i.e. my device can not perform I/O by 512 granularity.
As for virtual machine, i just simulated the problem so people can set it up and check. The commit message describes how it can be reproduced.
The dm-ebs target which i setup does ebs to ubs conversion, so the NVME driver gets BIOs are in size and aligned to ubs size. The ubs size corresponds to the underlying physical device I/O size.
So your patch does not work if logical < physical. Therefore it does not help my project.
--
Uladzislau Rezki
Mikulas Patocka
maintainerQuoted 10 lines · Uladzislau Rezki
Hello, Mikulas!
Quoted 6 lines
Hi
What is the
logical_block_sizeof the underlying nvme device? - i.e. what's the content of this file/sys/block/nvme0n1/queue/logical_block_sizein the virtual machine?It is 512. Whereas a physical is bigger, i.e. my device can not perform I/O by 512 granularity.
And what is physical block size? Is it 8192?
Quoted 9 lines
As for virtual machine, i just simulated the problem so people can set it up and check. The commit message describes how it can be reproduced.
The dm-ebs target which i setup does ebs to ubs conversion, so the NVME driver gets BIOs are in size and aligned to ubs size. The ubs size corresponds to the underlying physical device I/O size.
So your patch does not work if logical < physical. Therefore it does not help my project.
Logical block size is the granularity at which the device can accept I/O. Physical block size is the block size on the medium.
If logical < physical, then the device performs read-modify-write cycle when writing blocks that are not aligned at physical block size.
So, your setup is broken, because it advertises logical block size 512, but it is not able to perform I/O at this granularity.
There is this piece of code in include/linux/blkdev.h:
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
/*
* We should strive for 1 << (PAGE_SHIFT + MAX_PAGECACHE_ORDER)
* however we constrain this to what we can validate and test. */
#define BLK_MAX_BLOCK_SIZE SZ_64K
#else
#define BLK_MAX_BLOCK_SIZE PAGE_SIZE
#endif
/* blk_validate_limits() validates bsize, so drivers don't usually need to */ static inline int blk_validate_block_size(unsigned long bsize)
{
if (bsize < 512 || bsize > BLK_MAX_BLOCK_SIZE || !is_power_of_2(bsize))
return -EINVAL;
return 0;
}What happens when you define CONFIG_TRANSPARENT_HUGEPAGE in your .config? Does it fix the problem with small logical block size for you?
Mikulas
Quoted 3 lines
--
Uladzislau Rezki
Quoted 8 lines · Mikulas Patocka
Quoted 4 lines · Uladzislau Rezki
Hello, Mikulas!
Quoted 2 lines
Hi
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
What is the
logical_block_sizeof the underlying nvme device? - i.e. what's the content of this file/sys/block/nvme0n1/queue/logical_block_sizein the virtual machine?It is 512. Whereas a physical is bigger, i.e. my device can not perform I/O by 512 granularity.
And what is physical block size? Is it 8192?
Bigger then logical.
Quoted 7 lines
Quoted 7 lines
As for virtual machine, i just simulated the problem so people can set it up and check. The commit message describes how it can be reproduced.
The dm-ebs target which i setup does ebs to ubs conversion, so the NVME driver gets BIOs are in size and aligned to ubs size. The ubs size corresponds to the underlying physical device I/O size.
Quoted 9 lines
Quoted 2 lines
So your patch does not work if logical < physical. Therefore it does not help my project.
Logical block size is the granularity at which the device can accept I/O. Physical block size is the block size on the medium.
If logical < physical, then the device performs read-modify-write cycle when writing blocks that are not aligned at physical block size.
This is not true. It depends on your device and specification. If it can't there is the dm-ebs that does the job.
Quoted 3 lines
So, your setup is broken, because it advertises logical block size 512, but it is not able to perform I/O at this granularity.
I posted the workflow how to reproduce the problem. See the commit messages. But as i noted it is for people so they can simulate it.
But in my case, real one, logical < pysical.
Quoted 7 lines
There is this piece of code in
include/linux/blkdev.h:
#ifdefCONFIG_TRANSPARENT_HUGEPAGE
/*
* We should strive for 1 << (PAGE_SHIFT+MAX_PAGECACHE_ORDER)
* however we constrain this to what we can validate and test. */
#defineBLK_MAX_BLOCK_SIZESZ_64K
:wq
Quoted 13 lines
#else
#defineBLK_MAX_BLOCK_SIZEPAGE_SIZE
#endif/*
blk_validate_limits()validates bsize, so drivers don't usually need to */ static inline intblk_validate_block_size(unsigned long bsize){ if (bsize < 512 || bsize > BLK_MAX_BLOCK_SIZE || !is_power_of_2(bsize)) return -EINVAL; return 0; }
Quoted 3 lines
What happens when you define
CONFIG_TRANSPARENT_HUGEPAGEin your .config? Does it fix the problem with small logical block size for you?
TRANSPARENT stuff allows you to work with PS < BS. I have it enabled in my case.
Just to repeat, the device can not do I/O with logical bs only physical.
--
Uladzislau Rezki
Quoted 5 lines · Uladzislau Rezki
Quoted 3 lines
If logical < physical, then the device performs read-modify-write cycle when writing blocks that are not aligned at physical block size.
This is not true. It depends on your device and specification. If it can't there is the dm-ebs that does the job.
Logical blocks size is the access unit. Physical block size is a hint that the device might be doing RWF and thus be slow. What driver/device are using? Whatever it is doing is completely broken.
(that being said aligning things to the physical block size as much as possible is usually still a good optimization, that's why the value exists).
Benjamin Marzinski
maintainerQuoted 27 lines · Mikulas Patocka
Quoted 10 lines · Uladzislau Rezki
Hello, Mikulas!
Quoted 6 lines
Hi
What is the
logical_block_sizeof the underlying nvme device? - i.e. what's the content of this file/sys/block/nvme0n1/queue/logical_block_sizein the virtual machine?It is 512. Whereas a physical is bigger, i.e. my device can not perform I/O by 512 granularity.
And what is physical block size? Is it 8192?
Quoted 9 lines
As for virtual machine, i just simulated the problem so people can set it up and check. The commit message describes how it can be reproduced.
The dm-ebs target which i setup does ebs to ubs conversion, so the NVME driver gets BIOs are in size and aligned to ubs size. The ubs size corresponds to the underlying physical device I/O size.
So your patch does not work if logical < physical. Therefore it does not help my project.
Quoted 8 lines
Logical block size is the granularity at which the device can accept I/O. Physical block size is the block size on the medium.
If logical < physical, then the device performs read-modify-write cycle when writing blocks that are not aligned at physical block size.
So, your setup is broken, because it advertises logical block size 512, but it is not able to perform I/O at this granularity.
This emulated nvme device is broken, but the question still remains, "should dm-ebs enfore writing at the alignment that was specified in its table line?" If you don't specify a ubs in the table line, it defaults to the logical block size. So, if you do specify a ubs, it stands to reason that you want IO at that alignment, instead of the logical-block size (perhaps because your device is broken, and advertises the wrong logical block size).
So, I think that Uladzislau's patch makes sense, in addition to your own.
-Ben
Quoted 29 lines
There is this piece of code in
include/linux/blkdev.h:
#ifdefCONFIG_TRANSPARENT_HUGEPAGE
/*
* We should strive for 1 << (PAGE_SHIFT+MAX_PAGECACHE_ORDER)
* however we constrain this to what we can validate and test. */
#defineBLK_MAX_BLOCK_SIZESZ_64K
#else
#defineBLK_MAX_BLOCK_SIZEPAGE_SIZE
#endif/*
blk_validate_limits()validates bsize, so drivers don't usually need to */ static inline intblk_validate_block_size(unsigned long bsize){ if (bsize < 512 || bsize > BLK_MAX_BLOCK_SIZE || !is_power_of_2(bsize)) return -EINVAL; return 0; }What happens when you define
CONFIG_TRANSPARENT_HUGEPAGEin your .config? Does it fix the problem with small logical block size for you?Mikulas
Quoted 3 lines
--
Uladzislau Rezki
Mikulas Patocka
maintainerQuoted 45 lines · Benjamin Marzinski
Quoted 27 lines · Mikulas Patocka
Quoted 10 lines · Uladzislau Rezki
Hello, Mikulas!
Quoted 6 lines
Hi
What is the
logical_block_sizeof the underlying nvme device? - i.e. what's the content of this file/sys/block/nvme0n1/queue/logical_block_sizein the virtual machine?It is 512. Whereas a physical is bigger, i.e. my device can not perform I/O by 512 granularity.
And what is physical block size? Is it 8192?
Quoted 9 lines
As for virtual machine, i just simulated the problem so people can set it up and check. The commit message describes how it can be reproduced.
The dm-ebs target which i setup does ebs to ubs conversion, so the NVME driver gets BIOs are in size and aligned to ubs size. The ubs size corresponds to the underlying physical device I/O size.
So your patch does not work if logical < physical. Therefore it does not help my project.
Quoted 8 lines
Logical block size is the granularity at which the device can accept I/O. Physical block size is the block size on the medium.
If logical < physical, then the device performs read-modify-write cycle when writing blocks that are not aligned at physical block size.
So, your setup is broken, because it advertises logical block size 512, but it is not able to perform I/O at this granularity.
This emulated nvme device is broken, but the question still remains, "should dm-ebs enfore writing at the alignment that was specified in its table line?" If you don't specify a ubs in the table line, it defaults to the logical block size. So, if you do specify a ubs, it stands to reason that you want IO at that alignment, instead of the logical-block size (perhaps because your device is broken, and advertises the wrong logical block size).
Quoted 4 lines
So, I think that Uladzislau's patch makes sense, in addition to your own.
-Ben
OK - I accepted Uladzislau's patch. As logical block size and physical block size seem to be unreliable, it's better to set the size in dm-ebs.
Mikulas
Quoted 2 lines · Mikulas Patocka
OK - I accepted Uladzislau's patch. As logical block size and physical block size seem to be unreliable, it's better to set the size in dm-ebs.
logical and physical block size are reliable. Uladzislau just seems to have a completely broken device that needs fixing, because it will run into all kinds of other problems otherwise.
Quoted 8 lines · Christoph Hellwig
Quoted 2 lines · Mikulas Patocka
OK - I accepted Uladzislau's patch. As logical block size and physical block size seem to be unreliable, it's better to set the size in dm-ebs.
logical and physical block size are reliable. Uladzislau just seems to have a completely broken device that needs fixing, because it will run into all kinds of other problems otherwise.
Well. LBA is fixed in my case. Just only one format which is 512B.
Whereas the I/O can not be performed by using LBAs sizes. It is fixed and bigger.
I rely on this:
<snip>
/*
* Construct an emulated block size mapping: <dev_path> <offset> <ebs> [<ubs>] *
* <dev_path>: path of the underlying device
* <offset>: offset in 512 bytes sectors into <dev_path>
* <ebs>: emulated block size in units of 512 bytes exposed to the upper layer
* [<ubs>]: underlying block size in units of 512 bytes imposed on the lower layer;
* optional, if not supplied, retrieve logical block size from underlying device
*/
static int ebs_ctr(struct dm_target *ti, unsigned int argc, char **argv) {
...
<snip>
to do RMW. It says if UBS is set, data has to impose to lower layer in sizes of UBS and aligned to UBS. I specify the UBS what my device is capable of reading/writing.
The buffer is correctly updated in terms of RMW in UBS window. But it flushes partly leading to I/O errors. I find it wrong. Because i set the desired underlying block size.
That is my concern.
--
Uladzislau Rezki
Quoted 4 lines · Uladzislau Rezki
Well. LBA is fixed in my case. Just only one format which is 512B.
Whereas the I/O can not be performed by using LBAs sizes. It is fixed and bigger.
Then it is not an LBA. The LBA is defined as the minimum block size you can do I/O on. Aka your device is really gravely broken. What device is this and who is selling it?
Quoted 10 lines · Christoph Hellwig
Quoted 4 lines · Uladzislau Rezki
Well. LBA is fixed in my case. Just only one format which is 512B.
Whereas the I/O can not be performed by using LBAs sizes. It is fixed and bigger.
Then it is not an LBA. The LBA is defined as the minimum block size you can do I/O on. Aka your device is really gravely broken. What device is this and who is selling it?
I define UBS - underlying block size. The lower layer expects BIOs in that sizes but this is not true.
I am not allowed to disclose and answer your last question.
--
Uladzislau Rezki
Quoted 7 lines · Uladzislau Rezki
Quoted 6 lines · Christoph Hellwig
Quoted 4 lines · Uladzislau Rezki
Well. LBA is fixed in my case. Just only one format which is 512B.
Whereas the I/O can not be performed by using LBAs sizes. It is fixed and bigger.
Quoted 8 lines
Quoted 4 lines
Then it is not an LBA. The LBA is defined as the minimum block size you can do I/O on. Aka your device is really gravely broken. What device is this and who is selling it?
I define UBS - underlying block size. The lower layer expects BIOs in that sizes but this is not true.
I am not allowed to disclose and answer your last question.
Well. Let's frame it differently: this device is just to broken to be used with Linux. In theory we could quirk based on the vendor ID to correctly report the logical block size, but for that we'd need the information.
Quoted 15 lines · Christoph Hellwig
Quoted 14 lines · Uladzislau Rezki
Quoted 10 lines · Christoph Hellwig
Quoted 4 lines · Uladzislau Rezki
Well. LBA is fixed in my case. Just only one format which is 512B.
Whereas the I/O can not be performed by using LBAs sizes. It is fixed and bigger.
Then it is not an LBA. The LBA is defined as the minimum block size you can do I/O on. Aka your device is really gravely broken. What device is this and who is selling it?
I define UBS - underlying block size. The lower layer expects BIOs in that sizes but this is not true.
Quoted 7 lines
Quoted 1 line
I am not allowed to disclose and answer your last question.
Well. Let's frame it differently: this device is just to broken to be used with Linux. In theory we could quirk based on the vendor ID to correctly report the logical block size, but for that we'd need the information.
/*
* Construct an emulated block size mapping: <dev_path> <offset> <ebs> [<ubs>] *
* <dev_path>: path of the underlying device
* <offset>: offset in 512 bytes sectors into <dev_path>
* <ebs>: emulated block size in units of 512 bytes exposed to the upper layer
* [<ubs>]: underlying block size in units of 512 bytes imposed on the lower layer;
* optional, if not supplied, retrieve logical block size from underlying device
*/
static int ebs_ctr(struct dm_target *ti, unsigned int argc, char **argv) {
Again i rely on this.
--
Uladzislau Rezki
Quoted 1 line · Uladzislau Rezki
Again i rely on this.
I'm not sure what your random quoting of low-quality comments in kernel code is trying to prove here.
Any device that does not support the LBA/sector size correctly is not support by Linux. We could in theory quirk it in the driver, but for that we'd need to known the vendor/model and a good argument why we can't fix the device reporting, as this should just be firmware.
Secrecy is not going to help with that.
Quoted 6 lines · Christoph Hellwig
Quoted 1 line · Uladzislau Rezki
Again i rely on this.
I'm not sure what your random quoting of low-quality comments in kernel code is trying to prove here.
Quoted 7 lines
Any device that does not support the LBA/sector size correctly is not support by Linux. We could in theory quirk it in the driver, but for that we'd need to known the vendor/model and a good argument why we can't fix the device reporting, as this should just be firmware.
Secrecy is not going to help with that.
I will not resist.
I tried my best to explain the problem including description and steps how to reproduce it in the commit message if someone wants to repeat it in qemu with virtual nvme device.
--
Uladzisual Rezki
Quoted 12 lines · Uladzislau Rezki
Quoted 11 lines · Christoph Hellwig
Quoted 1 line · Uladzislau Rezki
Again i rely on this.
I'm not sure what your random quoting of low-quality comments in kernel code is trying to prove here.
Any device that does not support the LBA/sector size correctly is not support by Linux. We could in theory quirk it in the driver, but for that we'd need to known the vendor/model and a good argument why we can't fix the device reporting, as this should just be firmware.
Quoted 7 lines
Quoted 2 lines
Secrecy is not going to help with that.
I will not resist.
I tried my best to explain the problem including description and steps how to reproduce it in the commit message if someone wants to repeat it in qemu with virtual nvme device.
Again, the problem is that your device reports an incorrect block size.
And you're being a complete dick ignoring this and not even telling us anything about the device.
Mikulas Patocka
maintainerQuoted 6 lines · Christoph Hellwig
Quoted 2 lines · Mikulas Patocka
OK - I accepted Uladzislau's patch. As logical block size and physical block size seem to be unreliable, it's better to set the size in dm-ebs.
logical and physical block size are reliable. Uladzislau just seems to have a completely broken device that needs fixing, because it will
He created a qemu-emulated NVMe device with physical and logical block size 8192 in a virtual machine. And logical block size was reported as 512 in the guest kernel - so it is either a qemu bug or a kernel bug.
Quoted 1 line
run into all kinds of other problems otherwise.
Hmm, Linux may get it wrong too. See this piece of code in include/linux/blkdev.h:
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
/*
* We should strive for 1 << (PAGE_SHIFT + MAX_PAGECACHE_ORDER)
* however we constrain this to what we can validate and test. */
#define BLK_MAX_BLOCK_SIZE SZ_64K
#else
#define BLK_MAX_BLOCK_SIZE PAGE_SIZE
#endif
/* blk_validate_limits() validates bsize, so drivers don't usually need to */ static inline int blk_validate_block_size(unsigned long bsize)
{
if (bsize < 512 || bsize > BLK_MAX_BLOCK_SIZE || !is_power_of_2(bsize))
return -EINVAL;
return 0;
}in nvme_update_disk_info there is this piece of code:
if (blk_validate_block_size(bs)) {
bs = (1 << 9);
valid = false;
}So, the valid block size depends on whether CONFIG_TRANSPARENT_HUGEPAGE is defined, which is quite weird.
Mikulas
Quoted 8 lines · Mikulas Patocka
Quoted 4 lines · Christoph Hellwig
Quoted 2 lines · Mikulas Patocka
OK - I accepted Uladzislau's patch. As logical block size and physical block size seem to be unreliable, it's better to set the size in dm-ebs.
Quoted 6 lines
Quoted 2 lines
logical and physical block size are reliable. Uladzislau just seems to have a completely broken device that needs fixing, because it will
He created a qemu-emulated NVMe device with physical and logical block size 8192 in a virtual machine. And logical block size was reported as 512 in the guest kernel - so it is either a qemu bug or a kernel bug.
No, that's not the case. If you use his command line you'll see a qemu device with 8192 logical blocks assuming you have support for large folios, or a completely unusuable device that claims to have 512 byte blocks for compatibility, but also a capacity of zero so that no one can use it for anything but passthrough.
Quoted 5 lines
in
nvme_update_disk_infothere is this piece of code:if (blk_validate_block_size(bs)) { bs = (1 << 9); valid = false; }
Yes, that's what I mentioned above. The valid=false sets the capacity to zero, so you're not actually going to be able to use this device.
Quoted 2 lines
So, the valid block size depends on whether
CONFIG_TRANSPARENT_HUGEPAGEis defined, which is quite weird.
And also the page size, and none of that is too weird. You need support efficiently allocating large order folios to support a
block size > PAGE_SIZE and currently CONFIG_TRANSPARENT_HUGEPAGE is the guard for that. There was some talk of lifting that, but that requires a bit of work.
Quoted 31 lines · Christoph Hellwig
Quoted 8 lines · Mikulas Patocka
Quoted 4 lines · Christoph Hellwig
Quoted 2 lines · Mikulas Patocka
OK - I accepted Uladzislau's patch. As logical block size and physical block size seem to be unreliable, it's better to set the size in dm-ebs.
Quoted 6 lines
Quoted 2 lines
logical and physical block size are reliable. Uladzislau just seems to have a completely broken device that needs fixing, because it will
He created a qemu-emulated NVMe device with physical and logical block size 8192 in a virtual machine. And logical block size was reported as 512 in the guest kernel - so it is either a qemu bug or a kernel bug.
No, that's not the case. If you use his command line you'll see a qemu device with 8192 logical blocks assuming you have support for large folios, or a completely unusuable device that claims to have 512 byte blocks for compatibility, but also a capacity of zero so that no one can use it for anything but passthrough.
Quoted 5 lines
in
nvme_update_disk_infothere is this piece of code:if (blk_validate_block_size(bs)) { bs = (1 << 9); valid = false; }Yes, that's what I mentioned above. The valid=false sets the capacity to zero, so you're not actually going to be able to use this device.
Quoted 9 lines
Quoted 2 lines
So, the valid block size depends on whether
CONFIG_TRANSPARENT_HUGEPAGEis defined, which is quite weird.And also the page size, and none of that is too weird. You need support efficiently allocating large order folios to support a
block size >PAGE_SIZEand currentlyCONFIG_TRANSPARENT_HUGEPAGEis the guard for that. There was some talk of lifting that, but that requires a bit of work.
Could you please check below? Is the last one is correctly reported? I have enabled the CONFIG_TRANSPARENT_HUGEPAGE option. If i specify, 8192, 8192 first case, reports are what i set. Second variant 512, 8129 shows 512, 512:
CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE=yCONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD=yCONFIG_TRANSPARENT_HUGEPAGE=yCONFIG_TRANSPARENT_HUGEPAGE_ALWAYS=y
# CONFIG_TRANSPARENT_HUGEPAGE_MADVISE is not set
# CONFIG_TRANSPARENT_HUGEPAGE_NEVER is not set
-device nvme,drive=drv0,serial=foo,logical_block_size=8192,physical_block_size=8192
urezki@pc638:~$ sudo nvme list Node Generic SN Model Namespace Usage Format FW Rev --------------------- --------------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- -------- /dev/nvme0n1 /dev/ng0n1 foo QEMU NVMe Ctrl 1 8.49 GB / 8.49 GB 8 KiB + 0 B 10.0.6 urezki@pc638:~$ sudo cat /sys/block/nvme0n1/queue/logical_block_size 8192 urezki@pc638:~$ sudo cat /sys/block/nvme0n1/queue/physical_block_size 8192 urezki@pc638:~$
-device nvme,drive=drv0,serial=foo,logical_block_size=512,physical_block_size=8192
urezki@pc638:~$ sudo nvme list Node Generic SN Model Namespace Usage Format FW Rev --------------------- --------------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- -------- /dev/nvme0n1 /dev/ng0n1 foo QEMU NVMe Ctrl 1 8.49 GB / 8.49 GB 512 B + 0 B 10.0.6 urezki@pc638:~$ sudo cat /sys/block/nvme0n1/queue/physical_block_size 512 urezki@pc638:~$ sudo cat /sys/block/nvme0n1/queue/logical_block_size 512 urezki@pc638:~$
Is that what should be reported?
--
Uladzislau Rezki
Quoted 66 lines · Uladzislau Rezki
Quoted 31 lines · Christoph Hellwig
Quoted 8 lines · Mikulas Patocka
Quoted 4 lines · Christoph Hellwig
Quoted 2 lines · Mikulas Patocka
OK - I accepted Uladzislau's patch. As logical block size and physical block size seem to be unreliable, it's better to set the size in dm-ebs.
Quoted 6 lines
Quoted 2 lines
logical and physical block size are reliable. Uladzislau just seems to have a completely broken device that needs fixing, because it will
He created a qemu-emulated NVMe device with physical and logical block size 8192 in a virtual machine. And logical block size was reported as 512 in the guest kernel - so it is either a qemu bug or a kernel bug.
No, that's not the case. If you use his command line you'll see a qemu device with 8192 logical blocks assuming you have support for large folios, or a completely unusuable device that claims to have 512 byte blocks for compatibility, but also a capacity of zero so that no one can use it for anything but passthrough.
Quoted 5 lines
in
nvme_update_disk_infothere is this piece of code:if (blk_validate_block_size(bs)) { bs = (1 << 9); valid = false; }Yes, that's what I mentioned above. The valid=false sets the capacity to zero, so you're not actually going to be able to use this device.
Quoted 9 lines
Quoted 2 lines
So, the valid block size depends on whether
CONFIG_TRANSPARENT_HUGEPAGEis defined, which is quite weird.And also the page size, and none of that is too weird. You need support efficiently allocating large order folios to support a
block size >PAGE_SIZEand currentlyCONFIG_TRANSPARENT_HUGEPAGEis the guard for that. There was some talk of lifting that, but that requires a bit of work.Could you please check below? Is the last one is correctly reported? I have enabled the
CONFIG_TRANSPARENT_HUGEPAGEoption. If i specify, 8192, 8192 first case, reports are what i set. Second variant 512, 8129 shows 512, 512:
CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE=yCONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD=yCONFIG_TRANSPARENT_HUGEPAGE=yCONFIG_TRANSPARENT_HUGEPAGE_ALWAYS=y
#CONFIG_TRANSPARENT_HUGEPAGE_MADVISEis not set
#CONFIG_TRANSPARENT_HUGEPAGE_NEVERis not set-device nvme,drive=drv0,serial=foo,logical_block_size=8192,physical_block_size=8192
urezki@pc638:~$ sudo nvme list Node Generic SN Model Namespace Usage Format FW Rev --------------------- --------------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- -------- /dev/nvme0n1 /dev/ng0n1 foo QEMU NVMe Ctrl 1 8.49 GB / 8.49 GB 8 KiB + 0 B 10.0.6 urezki@pc638:~$ sudo cat /sys/block/nvme0n1/queue/logical_block_size 8192 urezki@pc638:~$ sudo cat /sys/block/nvme0n1/queue/physical_block_size 8192 urezki@pc638:~$-device nvme,drive=drv0,serial=foo,logical_block_size=512,physical_block_size=8192
Quoted 10 lines
urezki@pc638:~$ sudo nvme list Node Generic SN Model Namespace Usage Format FW Rev --------------------- --------------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- -------- /dev/nvme0n1 /dev/ng0n1 foo QEMU NVMe Ctrl 1 8.49 GB / 8.49 GB 512 B + 0 B 10.0.6 urezki@pc638:~$ sudo cat /sys/block/nvme0n1/queue/physical_block_size 512 urezki@pc638:~$ sudo cat /sys/block/nvme0n1/queue/logical_block_size 512 urezki@pc638:~$
It might be that qemu changes this, i will check.
Christoph, but i assume it is valid case: logical=512B, physical=8192K. Could you please confirm?
Thanks!
--
Uladzislau Rezki
Quoted 2 lines · Uladzislau Rezki
Christoph, but i assume it is valid case: logical=512B, physical=8192K. Could you please confirm?
That is a valid configuration. One that must accept I/O at 512 byte granularity.
Quoted 1 line · Uladzislau Rezki
Could you please check below? Is the last one is correctly reported?
The latter looks unexpected, but is is becase qemu is not passing through the qemu physical_block_size attribute to any of the nvme settings Linux interprets as such for NVMe (NVMe doesn't actually have the concept of a physical block size, unlike SCSI/ATA):
root@testvm:~# nvme id-ns -H /dev/nvme0n1 | grep npw npwg : 0 npwa : 0 root@testvm:~# nvme id-ns -H /dev/nvme0n1 | grep naw nawun : 0 nawupf : 0 root@testvm:~# nvme id-ctrl -H /dev/nvme0 | grep awupf awupf : 0
but as said multiple times, that should not really matter - the logical block size is the granularity of I/O, the physical block size is just a performance hint.
Quoted 8 lines · Christoph Hellwig
Quoted 1 line · Uladzislau Rezki
Could you please check below? Is the last one is correctly reported?
The latter looks unexpected, but is is becase qemu is not passing through the qemu
physical_block_sizeattribute to any of the nvme settings Linux interprets as such for NVMe (NVMe doesn't actually have the concept of a physical block size, unlike SCSI/ATA):
OK, understood and thank you for checking this.
Quoted 10 lines
root@testvm:~# nvme id-ns -H /dev/nvme0n1 | grep npw npwg : 0 npwa : 0 root@testvm:~# nvme id-ns -H /dev/nvme0n1 | grep naw nawun : 0 nawupf : 0 root@testvm:~# nvme id-ctrl -H /dev/nvme0 | grep awupf awupf : 0
Quoted 4 lines
but as said multiple times, that should not really matter - the logical block size is the granularity of I/O, the physical block size is just a performance hint.
Right.
As stated in commit message of the patch which is in question. 8K emulated in qemu device with CONFIG_TRANSPARENT_HUGEPAGE=y:
urezki@pc638:~$ sudo nvme list Node Generic SN Model Namespace Usage Format FW Rev --------------------- --------------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- -------- /dev/nvme0n1 /dev/ng0n1 foo QEMU NVMe Ctrl 1 8.49 GB / 8.49 GB 8 KiB + 0 B 10.0.6 urezki@pc638:~$ cat bin/dmsetup.sh #!/bin/bash
lower=/dev/nvme0n1
len=$(blockdev --getsz "$lower")
echo "0 $len ebs $lower 0 1 16" | dmsetup create nvme-8k
urezki@pc638:~$ sudo bin/dmsetup.sh
urezki@pc638:~$ sudo cat /sys/block/nvme0n1/queue/logical_block_size
8192
urezki@pc638:~$ sudo cat /sys/block/nvme0n1/queue/physical_block_size
8192
urezki@pc638:~$ sudo cat /sys/block/dm-0/queue/logical_block_size
512
urezki@pc638:~$ sudo cat /sys/block/dm-0/queue/physical_block_size
8192
urezki@pc638:~$ sudo mkfs.ext4 -F /dev/dm-0
mke2fs 1.47.0 (5-Feb-2023)
/dev/dm-0 contains a ext4 file system
last mounted on Fri Nov 21 12:22:55 2025
Discarding device blocks: done
Creating filesystem with 2072576 4k blocks and 518144 inodes
Filesystem UUID: f71adb05-c020-4406-bc0d-bdb9e5c29af7
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: mkfs.ext4: Input/output error while writing out and closing file system
urezki@pc638:~$ sudo dmesg | grep -i "i/o" [ 71.813322] Buffer I/O error on dev dm-0, logical block 10, lost async page write [ 71.813373] Buffer I/O error on dev dm-0, logical block 11, lost async page write [ 71.813395] Buffer I/O error on dev dm-0, logical block 12, lost async page write [ 71.813415] Buffer I/O error on dev dm-0, logical block 13, lost async page write [ 71.813433] Buffer I/O error on dev dm-0, logical block 14, lost async page write [ 71.813451] Buffer I/O error on dev dm-0, logical block 15, lost async page write [ 71.813475] Buffer I/O error on dev dm-0, logical block 16, lost async page write [ 71.813493] Buffer I/O error on dev dm-0, logical block 17, lost async page write [ 71.813516] Buffer I/O error on dev dm-0, logical block 18, lost async page write [ 71.813537] Buffer I/O error on dev dm-0, logical block 19, lost async page write urezki@pc638:~$
with the patch:
urezki@pc638:~$ sudo nvme list Node Generic SN Model Namespace Usage Format FW Rev --------------------- --------------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- -------- /dev/nvme0n1 /dev/ng0n1 foo QEMU NVMe Ctrl 1 8.49 GB / 8.49 GB 8 KiB + 0 B 10.0.6 urezki@pc638:~$ cat bin/dmsetup.sh #!/bin/bash
lower=/dev/nvme0n1
len=$(blockdev --getsz "$lower")
echo "0 $len ebs $lower 0 1 16" | dmsetup create nvme-8k
urezki@pc638:~$ sudo bin/dmsetup.sh
urezki@pc638:~$ sudo cat /sys/block/nvme0n1/queue/logical_block_size
8192
urezki@pc638:~$ sudo cat /sys/block/nvme0n1/queue/physical_block_size
8192
urezki@pc638:~$ sudo cat /sys/block/dm-0/queue/logical_block_size
512
urezki@pc638:~$ sudo cat /sys/block/dm-0/queue/physical_block_size
8192
urezki@pc638:~$ sudo mkfs.ext4 -F /dev/dm-0
mke2fs 1.47.0 (5-Feb-2023)
Discarding device blocks: done
Creating filesystem with 2072576 4k blocks and 518144 inodes
Filesystem UUID: c7dff4c7-aa7e-4c94-98ee-f9ea2da92a06
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
urezki@pc638:~$ sudo mount /dev/dm-0 /mnt/ urezki@pc638:~$ ls -al /mnt/ total 24 drwxr-xr-x 3 root root 4096 Nov 21 12:22 . drwxr-xr-x 19 root root 4096 Jul 10 19:42 .. drwx------ 2 root root 16384 Nov 21 12:22 lost+found urezki@pc638:~$
How do we solve this?
Mikulas proposed to use below patch:
<snip>
drivers/md/dm-bufio.c 2025-10-20 14:40:32.000000000 +0200 renamed from drivers/md/dm-bufio.c 2025-10-13 21:42:47.000000000 +0200 +5 -4
@@ -1374,7 +1374,7 @@ static void submit_io(struct dm_buffer * { unsigned int n_sectors; sector_t sector; - unsigned int offset, end; + unsigned int offset, end, align; b->end_io = end_io;
@@ -1388,9 +1388,10 @@ static void submit_io(struct dm_buffer * b->c->write_callback(b); offset = b->write_start; end = b->write_end; - offset &= -DM_BUFIO_WRITE_ALIGN; - end += DM_BUFIO_WRITE_ALIGN - 1; - end &= -DM_BUFIO_WRITE_ALIGN; + align = max(DM_BUFIO_WRITE_ALIGN, bdev_logical_block_size(b->c->bdev)); + offset &= -align; + end += align - 1; + end &= -align; if (unlikely(end > b->c->block_size)) end = b->c->block_size;
<snip>
and it fixes the setup which i described in the commit message, but i have question.
Why in dm-ebs we need to offload partial buffer < ubf size?
Thank you for answers!
--
Uladzislau Rezki
Benjamin Marzinski
maintainerQuoted 153 lines · Uladzislau Rezki
Quoted 8 lines · Christoph Hellwig
Quoted 1 line · Uladzislau Rezki
Could you please check below? Is the last one is correctly reported?
The latter looks unexpected, but is is becase qemu is not passing through the qemu
physical_block_sizeattribute to any of the nvme settings Linux interprets as such for NVMe (NVMe doesn't actually have the concept of a physical block size, unlike SCSI/ATA):OK, understood and thank you for checking this.
Quoted 10 lines
root@testvm:~# nvme id-ns -H /dev/nvme0n1 | grep npw npwg : 0 npwa : 0 root@testvm:~# nvme id-ns -H /dev/nvme0n1 | grep naw nawun : 0 nawupf : 0 root@testvm:~# nvme id-ctrl -H /dev/nvme0 | grep awupf awupf : 0Quoted 4 lines
but as said multiple times, that should not really matter - the logical block size is the granularity of I/O, the physical block size is just a performance hint.
Right.
As stated in commit message of the patch which is in question. 8K emulated in qemu device with
CONFIG_TRANSPARENT_HUGEPAGE=y:urezki@pc638:~$ sudo nvme list Node Generic SN Model Namespace Usage Format FW Rev --------------------- --------------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- -------- /dev/nvme0n1 /dev/ng0n1 foo QEMU NVMe Ctrl 1 8.49 GB / 8.49 GB 8 KiB + 0 B 10.0.6 urezki@pc638:~$ cat bin/dmsetup.sh #!/bin/bashlower=/dev/nvme0n1
len=$(blockdev --getsz "$lower")echo "0 $len ebs $lower 0 1 16" | dmsetup create nvme-8k
urezki@pc638:~$ sudo bin/dmsetup.sh urezki@pc638:~$ sudo cat /sys/block/nvme0n1/queue/logical_block_size 8192 urezki@pc638:~$ sudo cat /sys/block/nvme0n1/queue/physical_block_size 8192 urezki@pc638:~$ sudo cat /sys/block/dm-0/queue/logical_block_size 512 urezki@pc638:~$ sudo cat /sys/block/dm-0/queue/physical_block_size 8192 urezki@pc638:~$ sudo mkfs.ext4 -F /dev/dm-0 mke2fs 1.47.0 (5-Feb-2023) /dev/dm-0 contains a ext4 file system last mounted on Fri Nov 21 12:22:55 2025 Discarding device blocks: done Creating filesystem with 2072576 4k blocks and 518144 inodes Filesystem UUID: f71adb05-c020-4406-bc0d-bdb9e5c29af7 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: mkfs.ext4: Input/output error while writing out and closing file systemurezki@pc638:~$ sudo dmesg | grep -i "i/o" [ 71.813322] Buffer I/O error on dev dm-0, logical block 10, lost async page write [ 71.813373] Buffer I/O error on dev dm-0, logical block 11, lost async page write [ 71.813395] Buffer I/O error on dev dm-0, logical block 12, lost async page write [ 71.813415] Buffer I/O error on dev dm-0, logical block 13, lost async page write [ 71.813433] Buffer I/O error on dev dm-0, logical block 14, lost async page write [ 71.813451] Buffer I/O error on dev dm-0, logical block 15, lost async page write [ 71.813475] Buffer I/O error on dev dm-0, logical block 16, lost async page write [ 71.813493] Buffer I/O error on dev dm-0, logical block 17, lost async page write [ 71.813516] Buffer I/O error on dev dm-0, logical block 18, lost async page write [ 71.813537] Buffer I/O error on dev dm-0, logical block 19, lost async page write urezki@pc638:~$with the patch:
urezki@pc638:~$ sudo nvme list Node Generic SN Model Namespace Usage Format FW Rev --------------------- --------------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- -------- /dev/nvme0n1 /dev/ng0n1 foo QEMU NVMe Ctrl 1 8.49 GB / 8.49 GB 8 KiB + 0 B 10.0.6 urezki@pc638:~$ cat bin/dmsetup.sh #!/bin/bashlower=/dev/nvme0n1
len=$(blockdev --getsz "$lower")echo "0 $len ebs $lower 0 1 16" | dmsetup create nvme-8k
urezki@pc638:~$ sudo bin/dmsetup.sh urezki@pc638:~$ sudo cat /sys/block/nvme0n1/queue/logical_block_size 8192 urezki@pc638:~$ sudo cat /sys/block/nvme0n1/queue/physical_block_size 8192 urezki@pc638:~$ sudo cat /sys/block/dm-0/queue/logical_block_size 512 urezki@pc638:~$ sudo cat /sys/block/dm-0/queue/physical_block_size 8192 urezki@pc638:~$ sudo mkfs.ext4 -F /dev/dm-0 mke2fs 1.47.0 (5-Feb-2023) Discarding device blocks: done Creating filesystem with 2072576 4k blocks and 518144 inodes Filesystem UUID: c7dff4c7-aa7e-4c94-98ee-f9ea2da92a06 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: doneurezki@pc638:~$ sudo mount /dev/dm-0 /mnt/ urezki@pc638:~$ ls -al /mnt/ total 24 drwxr-xr-x 3 root root 4096 Nov 21 12:22 . drwxr-xr-x 19 root root 4096 Jul 10 19:42 .. drwx------ 2 root root 16384 Nov 21 12:22 lost+found urezki@pc638:~$How do we solve this?
Mikulas proposed to use below patch:
<snip>
Index:linux-2.6/drivers/md/dm-bufio.c
===================================================================drivers/md/dm-bufio.c 2025-10-20 14:40:32.000000000 +0200 renamed from drivers/md/dm-bufio.c 2025-10-13 21:42:47.000000000 +0200 +5
-4@@ -1374,7 +1374,7 @@ static void submit_io(struct dm_buffer * { unsigned int n_sectors; sector_t sector; - unsigned int offset, end; + unsigned int offset, end, align; b->end_io = end_io;@@ -1388,9 +1388,10 @@ static void submit_io(struct dm_buffer * b->c->write_callback(b); offset = b->write_start; end = b->write_end; - offset &= -DM_BUFIO_WRITE_ALIGN; - end += DM_BUFIO_WRITE_ALIGN - 1; - end &= -DM_BUFIO_WRITE_ALIGN; + align = max(DM_BUFIO_WRITE_ALIGN, bdev_logical_block_size(b->c->bdev)); + offset &= -align; + end += align - 1; + end &= -align; if (unlikely(end > b->c->block_size)) end = b->c->block_size;
Quoted 4 lines
and it fixes the setup which i described in the commit message, but i have question.
Why in dm-ebs we need to offload partial buffer < ubf size?
Um, did you notice that Mikulas accepted your patch?
Quoted 5 lines
Thank you for answers!
--
Uladzislau Rezki
Quoted 154 lines · Uladzislau Rezki
Quoted 153 lines · Christoph Hellwig
Quoted 8 lines · Uladzislau Rezki
Quoted 1 line
Could you please check below? Is the last one is correctly reported?
The latter looks unexpected, but is is becase qemu is not passing through the qemu
physical_block_sizeattribute to any of the nvme settings Linux interprets as such for NVMe (NVMe doesn't actually have the concept of a physical block size, unlike SCSI/ATA):OK, understood and thank you for checking this.
Quoted 10 lines
root@testvm:~# nvme id-ns -H /dev/nvme0n1 | grep npw npwg : 0 npwa : 0 root@testvm:~# nvme id-ns -H /dev/nvme0n1 | grep naw nawun : 0 nawupf : 0 root@testvm:~# nvme id-ctrl -H /dev/nvme0 | grep awupf awupf : 0Quoted 4 lines
but as said multiple times, that should not really matter - the logical block size is the granularity of I/O, the physical block size is just a performance hint.
Right.
As stated in commit message of the patch which is in question. 8K emulated in qemu device with
CONFIG_TRANSPARENT_HUGEPAGE=y:urezki@pc638:~$ sudo nvme list Node Generic SN Model Namespace Usage Format FW Rev --------------------- --------------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- -------- /dev/nvme0n1 /dev/ng0n1 foo QEMU NVMe Ctrl 1 8.49 GB / 8.49 GB 8 KiB + 0 B 10.0.6 urezki@pc638:~$ cat bin/dmsetup.sh #!/bin/bashlower=/dev/nvme0n1
len=$(blockdev --getsz "$lower")echo "0 $len ebs $lower 0 1 16" | dmsetup create nvme-8k
urezki@pc638:~$ sudo bin/dmsetup.sh urezki@pc638:~$ sudo cat /sys/block/nvme0n1/queue/logical_block_size 8192 urezki@pc638:~$ sudo cat /sys/block/nvme0n1/queue/physical_block_size 8192 urezki@pc638:~$ sudo cat /sys/block/dm-0/queue/logical_block_size 512 urezki@pc638:~$ sudo cat /sys/block/dm-0/queue/physical_block_size 8192 urezki@pc638:~$ sudo mkfs.ext4 -F /dev/dm-0 mke2fs 1.47.0 (5-Feb-2023) /dev/dm-0 contains a ext4 file system last mounted on Fri Nov 21 12:22:55 2025 Discarding device blocks: done Creating filesystem with 2072576 4k blocks and 518144 inodes Filesystem UUID: f71adb05-c020-4406-bc0d-bdb9e5c29af7 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: mkfs.ext4: Input/output error while writing out and closing file systemurezki@pc638:~$ sudo dmesg | grep -i "i/o" [ 71.813322] Buffer I/O error on dev dm-0, logical block 10, lost async page write [ 71.813373] Buffer I/O error on dev dm-0, logical block 11, lost async page write [ 71.813395] Buffer I/O error on dev dm-0, logical block 12, lost async page write [ 71.813415] Buffer I/O error on dev dm-0, logical block 13, lost async page write [ 71.813433] Buffer I/O error on dev dm-0, logical block 14, lost async page write [ 71.813451] Buffer I/O error on dev dm-0, logical block 15, lost async page write [ 71.813475] Buffer I/O error on dev dm-0, logical block 16, lost async page write [ 71.813493] Buffer I/O error on dev dm-0, logical block 17, lost async page write [ 71.813516] Buffer I/O error on dev dm-0, logical block 18, lost async page write [ 71.813537] Buffer I/O error on dev dm-0, logical block 19, lost async page write urezki@pc638:~$with the patch:
urezki@pc638:~$ sudo nvme list Node Generic SN Model Namespace Usage Format FW Rev --------------------- --------------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- -------- /dev/nvme0n1 /dev/ng0n1 foo QEMU NVMe Ctrl 1 8.49 GB / 8.49 GB 8 KiB + 0 B 10.0.6 urezki@pc638:~$ cat bin/dmsetup.sh #!/bin/bashlower=/dev/nvme0n1
len=$(blockdev --getsz "$lower")echo "0 $len ebs $lower 0 1 16" | dmsetup create nvme-8k
urezki@pc638:~$ sudo bin/dmsetup.sh urezki@pc638:~$ sudo cat /sys/block/nvme0n1/queue/logical_block_size 8192 urezki@pc638:~$ sudo cat /sys/block/nvme0n1/queue/physical_block_size 8192 urezki@pc638:~$ sudo cat /sys/block/dm-0/queue/logical_block_size 512 urezki@pc638:~$ sudo cat /sys/block/dm-0/queue/physical_block_size 8192 urezki@pc638:~$ sudo mkfs.ext4 -F /dev/dm-0 mke2fs 1.47.0 (5-Feb-2023) Discarding device blocks: done Creating filesystem with 2072576 4k blocks and 518144 inodes Filesystem UUID: c7dff4c7-aa7e-4c94-98ee-f9ea2da92a06 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: doneurezki@pc638:~$ sudo mount /dev/dm-0 /mnt/ urezki@pc638:~$ ls -al /mnt/ total 24 drwxr-xr-x 3 root root 4096 Nov 21 12:22 . drwxr-xr-x 19 root root 4096 Jul 10 19:42 .. drwx------ 2 root root 16384 Nov 21 12:22 lost+found urezki@pc638:~$How do we solve this?
Mikulas proposed to use below patch:
<snip>
Index:linux-2.6/drivers/md/dm-bufio.c
===================================================================drivers/md/dm-bufio.c 2025-10-20 14:40:32.000000000 +0200 renamed from drivers/md/dm-bufio.c 2025-10-13 21:42:47.000000000 +0200 +5
-4@@ -1374,7 +1374,7 @@ static void submit_io(struct dm_buffer * { unsigned int n_sectors; sector_t sector; - unsigned int offset, end; + unsigned int offset, end, align; b->end_io = end_io;@@ -1388,9 +1388,10 @@ static void submit_io(struct dm_buffer * b->c->write_callback(b); offset = b->write_start; end = b->write_end; - offset &= -DM_BUFIO_WRITE_ALIGN; - end += DM_BUFIO_WRITE_ALIGN - 1; - end &= -DM_BUFIO_WRITE_ALIGN; + align = max(DM_BUFIO_WRITE_ALIGN, bdev_logical_block_size(b->c->bdev)); + offset &= -align; + end += align - 1; + end &= -align; if (unlikely(end > b->c->block_size)) end = b->c->block_size;
Quoted 7 lines
Quoted 4 lines
and it fixes the setup which i described in the commit message, but i have question.
Why in dm-ebs we need to offload partial buffer < ubf size?
Um, did you notice that Mikulas accepted your patch?
I saw, he mentioned that and i am glad that during this discussion we came to one more extra patch. I got the feeling that there were misunderstanding between us, so i decided to make it more clear that is it.
Thank you.
--
Uladzislau Rezki
Quoted 11 lines · Uladzislau Rezki
drivers/md/dm-bufio.c 2025-10-20 14:40:32.000000000 +0200 renamed from drivers/md/dm-bufio.c 2025-10-13 21:42:47.000000000 +0200 +4
-3- offset &= -DM_BUFIO_WRITE_ALIGN; - end += DM_BUFIO_WRITE_ALIGN - 1; - end &= -DM_BUFIO_WRITE_ALIGN; + align = max(DM_BUFIO_WRITE_ALIGN, bdev_logical_block_size(b->c->bdev)); + offset &= -align; + end += align - 1; + end &= -align; if (unlikely(end > b->c->block_size)) end = b->c->block_size;
Quoted 2 lines
and it fixes the setup which i described in the commit message, but i have question.
And this patch, using bdev_logical_block_size looks correct.
Quoted 2 lines
Why in dm-ebs we need to offload partial buffer < ubf size?
I don't understand this question. What is ubf? What does partial buffer mean in this context, and what does offload mean?
Quoted 15 lines · Christoph Hellwig
Quoted 11 lines · Uladzislau Rezki
drivers/md/dm-bufio.c 2025-10-20 14:40:32.000000000 +0200 renamed from drivers/md/dm-bufio.c 2025-10-13 21:42:47.000000000 +0200 +4
-3- offset &= -DM_BUFIO_WRITE_ALIGN; - end += DM_BUFIO_WRITE_ALIGN - 1; - end &= -DM_BUFIO_WRITE_ALIGN; + align = max(DM_BUFIO_WRITE_ALIGN, bdev_logical_block_size(b->c->bdev)); + offset &= -align; + end += align - 1; + end &= -align; if (unlikely(end > b->c->block_size)) end = b->c->block_size;Quoted 2 lines
and it fixes the setup which i described in the commit message, but i have question.
Quoted 8 lines
And this patch, using
bdev_logical_block_sizelooks correct.Quoted 2 lines
Why in dm-ebs we need to offload partial buffer < ubf size?
I don't understand this question. What is ubf? What does partial buffer mean in this context, and what does offload mean?
That was a typo :) i meant ubs - which is underlying block size or number of sectors which define the logical block size of the device. In our case it is 8K thus is 16 = 512 * 16 = 8K.
Partial buffer means, in context of dm-ebs, that within 8K buffer only part of it can be modified. For example, since we emulate 512B to 8K from upper layer to the device, a file system can write for example just first 4K within 8K window buffer and only that part is marked as dirty.
offloading or imposing the data to the lower layer. i.e. writing dirty buffers to the device calling submit_io().
Is it better? It might be that i missed something, feel free to correct.
--
Uladzislau Rezki
Quoted 17 lines · Uladzislau Rezki
Quoted 7 lines
Quoted 3 lines
Why in dm-ebs we need to offload partial buffer < ubf size?
I don't understand this question. What is ubf? What does partial buffer mean in this context, and what does offload mean?
That was a typo :) i meant ubs - which is underlying block size or number of sectors which define the logical block size of the device. In our case it is 8K thus is 16 = 512 * 16 = 8K.
Partial buffer means, in context of dm-ebs, that within 8K buffer only part of it can be modified. For example, since we emulate 512B to 8K from upper layer to the device, a file system can write for example just first 4K within 8K window buffer and only that part is marked as dirty.
Quoted 4 lines
offloading or imposing the data to the lower layer. i.e. writing dirty buffers to the device calling
submit_io().Is it better? It might be that i missed something, feel free to correct.
I'm still lost what the question is, sorry.
Quoted 18 lines · Christoph Hellwig
Quoted 17 lines · Uladzislau Rezki
Quoted 7 lines
Quoted 3 lines
Why in dm-ebs we need to offload partial buffer < ubf size?
I don't understand this question. What is ubf? What does partial buffer mean in this context, and what does offload mean?
That was a typo :) i meant ubs - which is underlying block size or number of sectors which define the logical block size of the device. In our case it is 8K thus is 16 = 512 * 16 = 8K.
Partial buffer means, in context of dm-ebs, that within 8K buffer only part of it can be modified. For example, since we emulate 512B to 8K from upper layer to the device, a file system can write for example just first 4K within 8K window buffer and only that part is marked as dirty.
Quoted 7 lines
Quoted 4 lines
offloading or imposing the data to the lower layer. i.e. writing dirty buffers to the device calling
submit_io().Is it better? It might be that i missed something, feel free to correct.
I'm still lost what the question is, sorry.
No problem, i am fine with it.
Thank you for your input especially explaining the difference between logical_block_size and physical_block_size for nvme device.
Appreciate it!
--
Uladzislau Rezki