From: Itai Handler <itai.handler@gmail.com>
To: Zdenek Kabelac <zkabelac@redhat.com>
Cc: lvm-devel@lists.linux.dev, David Teigland <teigland@redhat.com>
Subject: Re: [PATCH] label: fix writes when the logical block size is not 512 or 4096
Date: Thu, 29 Oct 2026 15:53:55 +0200 [thread overview]
Message-ID: <20261029135355.3690645-1-itai.handler@gmail.com> (raw)
In-Reply-To: <e297d16a-58e9-40b2-9f1d-8baaf29e823e@redhat.com>
Hi Zdenek,
On Thu, Oct 29, 2026 at 02:12:34PM +0100, Zdenek Kabelac wrote:
> Hmm - this thread io engine is surely a new logic we are putting in.
This is not related to the threads engine; the warning just names the
engine in use. On main, pvcreate fails the same way with io_engine
set to sync or libaio, and also with releases from before the threads
engine, such as Ubuntu's 2.03.11 and Debian's 2.03.31. Built from the
release tags, 2.03.05 works on 1024- and 2048-byte loop devices
(pvcreate, vgcreate, lvcreate, vgremove), and 2.03.06 fails on the
2048-byte one from the patch:
# pvcreate /dev/loop8
Error writing device /dev/loop8 at 4096 length 512.
bcache_invalidate: block (3, 0) still dirty
Failed to write mda header to /dev/loop8 fd -1
Failed to write physical volume "/dev/loop8".
The cause is 7f347698e3d0 ("Fix rounding writes up to sector size"),
which went into 2.03.06. Before it, writes were rounded up to the
physical block size, which is never smaller than the logical one.
Since then only 512 and 4096 are used, and when neither block size is
one of them, it falls back to 512.
> I'd like to know more details what is the scenario we are trying to
> solve - normally we expect devices to really have 512 or 4K writable
> blocks.
>
> We have some set of patches to improve support on systems with 64K
> pagesize.
>
> But I'm puzzled from where do we get 1K or 2K block sizes ??
I ran into this while testing LVM on dm-crypt with sectors larger
than 4KiB. A dm-crypt device uses its encryption sector size as its
logical block size. dm-crypt has accepted sector sizes from 512 to
4096 since Linux 4.12, and my kernel change 1acc65c30f85 ("dm-crypt:
allow encryption sector size up to PAGE_SIZE", target version 1.30.0)
raises the limit to the page size, so on kernels configured with
64KiB pages it can also be 8KiB to 64KiB. pvcreate fails on all of
these, and while looking into why, I found that 1K and 2K fail the
same way on any kernel.
1K and 2K block sizes are not common, but they are valid today:
- cryptsetup has offered --sector-size for LUKS2 and plain devices
since 2.0.0, and accepts 1024 and 2048. For example, pvcreate fails
on a LUKS2 device made with "cryptsetup luksFormat --sector-size
2048", and LVM on LUKS is a common setup.
- s390 DASDs can be formatted with 1024- or 2048-byte blocks
(dasdfmt -b), although 4096 is the recommended size.
- loop devices with --sector-size, which is the easiest way to
reproduce it.
The 64K page size changes already in main, such as 3e91a5265
("striped: allow stripe size smaller than page size"), were in the
tree I tested, and do not change this. If you have more that are not
in main yet, I'd be glad to test them on my arm64 VM with 64KiB pages.
>> Fix this by rounding up to the logical block size of the device when
>> it is neither 512 nor 4096. [...]
>
> I think we want to fully hide this in blkio - label layer should be
> above.
Agreed, blkio does the direct I/O, so it should know the alignment it
needs. For example, it could get the logical block size of each fd
it is given (BLKSSZGET) and round shortened writes up to that, so the
label layer passes only the offset. For devices with 512- or
4096-byte logical blocks this rounds exactly as today, including
those with a huge physical block size, as in
large-physical-sector-size.sh.
> So I will think more about this.
Sure. I can send a v2 along those lines, keeping the test, or test
your version if you prefer to write it.
>> Devices with other block sizes are uncommon, but easy to create: loop
>
> Can you tell why do you actually need to use this blocksize - IMHO it
> must bring some inefficiency ??
I agree that blocks smaller than the disk's sector, such as 2KiB on an
SSD with 4KiB sectors, are inefficient, since a 2KiB write makes the
disk read and rewrite a whole 4KiB sector. I don't need those myself;
I mention them only because they hit the same bug.
What I want is the opposite: larger blocks, from 8KiB up to 64KiB,
for dm-crypt on kernels configured with 64KiB pages. These are whole
multiples of the disk's sector, so they do not have that problem.
Whichever size is used, the cost to LVM is small. Only LVM's own
writes, such as metadata updates, are rounded up to whole blocks,
which adds less than one block to each, and they happen only when LVM
changes something. LV data does not go through this code, and the
default 1MiB pe_start keeps extents aligned for any of these sizes.
Thanks,
Itai
next prev parent reply other threads:[~2026-10-29 13:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 12:53 [PATCH] label: fix writes when the logical block size is not 512 or 4096 Itai Handler
2026-10-29 13:12 ` Zdenek Kabelac
2026-10-29 13:53 ` Itai Handler [this message]
2026-10-29 18:45 ` David Teigland
2026-11-01 12:19 ` Itai Handler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261029135355.3690645-1-itai.handler@gmail.com \
--to=itai.handler@gmail.com \
--cc=lvm-devel@lists.linux.dev \
--cc=teigland@redhat.com \
--cc=zkabelac@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox