From: Nir Soffer <nirsof@gmail.com>
To: Max Reitz <mreitz@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>, Nir Soffer <nsoffer@redhat.com>,
QEMU Developers <qemu-devel@nongnu.org>,
qemu-block <qemu-block@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH v2 1/2] block: posix: Always allocate the first block
Date: Mon, 26 Aug 2019 18:41:59 +0300 [thread overview]
Message-ID: <CAMr-obvF9d=ed0hxa0FRCqFU93U8Mi21nZ6zoraYm2EfpgpQag@mail.gmail.com> (raw)
In-Reply-To: <e4e45496-b867-4e57-5b25-d0f1425d4824@redhat.com>
On Mon, Aug 26, 2019 at 3:31 PM Max Reitz <mreitz@redhat.com> wrote:
>
> On 26.08.19 00:03, Nir Soffer wrote:
...
> > +/*
> > + * Help alignment probing by allocating the first block.
> > + *
> > + * When reading with direct I/O from unallocated area on Gluster backed by XFS,
> > + * reading succeeds regardless of request length. In this case we fallback to
> > + * safe alignment which is not optimal. Allocating the first block avoids this
> > + * fallback.
> > + *
> > + * fd may be opened with O_DIRECT, but we don't know the buffer alignment or
> > + * request alignment, so we use safe values.
> > + *
> > + * Returns: 0 on success, -errno on failure. Since this is an optimization,
> > + * caller may ignore failures.
> > + */
> > +static int allocate_first_block(int fd, size_t max_size)
> > +{
> > + size_t write_size = MIN(MAX_BLOCKSIZE, max_size);
>
> Hm, well, there was a reason why I proposed rounding this down to the
> next power of two. If max_size is not a power of two but below
> MAX_BLOCKSIZE, write_size will not be a power of two, and thus the write
> below may fail even if write_size exceeds the physical block size.
>
> You can see that in the test case you add by using e.g. 768 as the
> destination size (provided your test filesystem has a block size of 512).
>
> Now I would like to say that it’s stupid to resize an O_DIRECT file to a
> size that is not a multiple of the block size; but I’ve had a bug
> assigned to me before because that didn’t work.
>
> But maybe it’s actually better if it doesn’t work. I don’t know.
I tried to avoid complexity that is unlikely to help anyone, but we
can make the (typical)
case of 512 bytes sector size work with this:
size_t write_size = (max_size < MAX_BLOCKSIZE)
? BDRV_SECTOR_SIZE
: MAX_BLOCKSIZE;
Unfortunately testing max_size < 4096 will not be reliable since we don't know
that underlying storage sector size.
...
next prev parent reply other threads:[~2019-08-26 15:43 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-25 22:03 [Qemu-devel] [PATCH v2 0/2] Optimize alignment probing Nir Soffer
2019-08-25 22:03 ` [Qemu-devel] [PATCH v2 1/2] block: posix: Always allocate the first block Nir Soffer
2019-08-26 12:31 ` Max Reitz
2019-08-26 13:49 ` Eric Blake
2019-08-26 15:23 ` Nir Soffer
2019-08-26 15:41 ` Nir Soffer [this message]
2019-08-26 16:20 ` Max Reitz
2019-08-26 13:46 ` Eric Blake
2019-08-26 15:19 ` Nir Soffer
2019-08-25 22:03 ` [Qemu-devel] [PATCH v2 2/2] iotests: Test allocate_first_block() with O_DIRECT Nir Soffer
2019-08-25 22:41 ` Nir Soffer
2019-08-26 12:38 ` Max Reitz
2019-08-25 22:19 ` [Qemu-devel] [PATCH v2 0/2] Optimize alignment probing no-reply
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='CAMr-obvF9d=ed0hxa0FRCqFU93U8Mi21nZ6zoraYm2EfpgpQag@mail.gmail.com' \
--to=nirsof@gmail.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=nsoffer@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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;
as well as URLs for NNTP newsgroup(s).