All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: "Denis V. Lunev" <den@openvz.org>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
	qemu-stable@nongnu.org, Hanna Reitz <hreitz@redhat.com>,
	Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>,
	Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Subject: Re: [PATCH 05/13] block/preallocate: hold back writes into a preallocation in flight
Date: Tue, 3 Nov 2026 14:01:36 +0100	[thread overview]
Message-ID: <aunbMKIJAaKpoB5Y@redhat.com> (raw)
In-Reply-To: <20260930165000.303236-6-den@openvz.org>

Am 30.09.2026 um 18:49 hat Denis V. Lunev geschrieben:
> From: Denis V. Lunev <den@openvz.org>
> 
> The previous patch holds the mutex across all of handle_write(),
> including the preallocating write zeroes. That is correct and far too
> coarse: the fallocate takes as long as it takes, and every writer that
> extends the file waits for it.
> 
> Reserve the range instead of holding the lock over it. file_end moves
> to the end of the preallocated range before the request is issued, so
> a writer arriving while it is in flight works from a length that
> already covers the range being zeroed.
> 
> That leaves it going straight into the range, and BDRV_REQ_SERIALISING
> cannot stop it. Serialisation orders a request against the ones in
> bs->tracked_requests, and the zeroing request is not there yet: the
> filter runs above bdrv_co_pwritev_part(), which is what tracks it.
> Whatever the filter lets through in that window is unordered by
> construction, so the filter has to hold it back itself.

If I understand correctly, the problem isn't that the zeroing request
isn't there yet, but will be later, but that it operates on bs->file
while you want to serialise requests against it on bs.

I wonder if the easier solution for this wouldn't be what you removed
from file-posix in the first patch: Get the current request and widen it
so that it covers the area that gets preallocated and then mark it
serialising.

> safe_end trails file_end, standing at the lowest start of a
> preallocation in flight and reaching file_end once none is left. A
> write above it waits on a queue and re-reads the state when the
> preallocations drain. A write zeroes merged into a preallocation
> starts it below file_end, so safe_end has to move down as well as up.
> 
> Below safe_end nothing can be zeroed any more, so those writes do not
> queue, and below zero_start there is nothing to record either, so
> those take no mutex at all. The stores are qatomic_set() because that
> path reads them without it.
> 
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> Cc: qemu-stable@nongnu.org
> CC: Kevin Wolf <kwolf@redhat.com>
> CC: Hanna Reitz <hreitz@redhat.com>
> CC: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> CC: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
> ---
>  block/preallocate.c | 95 ++++++++++++++++++++++++++++++++++++---------
>  1 file changed, 76 insertions(+), 19 deletions(-)
> 
> diff --git a/block/preallocate.c b/block/preallocate.c
> index 442cdb0176..128f1da014 100644
> --- a/block/preallocate.c
> +++ b/block/preallocate.c
> @@ -32,6 +32,7 @@
>  #include "qemu/units.h"
>  #include "block/block-io.h"
>  #include "block/block_int.h"
> +#include "qemu/atomic.h"

Please also add comments to those struct fields that are supposed to be
accessed with atomics.

I see that data_end, safe_end and zero_start are accessed inconsistently
with and without atomics, sometimes even within the same function.

Kevin



  parent reply	other threads:[~2026-11-03 13:02 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 16:49 [PATCH 00/13] block: fix data loss in the preallocate filter Denis V. Lunev
2026-09-30 16:49 ` [PATCH 01/13] block/file-posix: drop the XFS workaround for post-EOF fallocate Denis V. Lunev
2026-10-02 16:16   ` Andrey Drobyshev
2026-09-30 16:49 ` [PATCH 02/13] block/preallocate: keep zero_start above written data Denis V. Lunev
2026-10-02 16:16   ` Andrey Drobyshev
2026-09-30 16:49 ` [PATCH 03/13] block/preallocate: collect the state assignments in one place Denis V. Lunev
2026-10-02 16:16   ` Andrey Drobyshev
2026-09-30 16:49 ` [PATCH 04/13] block/preallocate: serialise the filter state Denis V. Lunev
2026-10-02 16:16   ` Andrey Drobyshev
2026-11-03 12:45   ` Kevin Wolf
2026-09-30 16:49 ` [PATCH 05/13] block/preallocate: hold back writes into a preallocation in flight Denis V. Lunev
2026-10-02 16:16   ` Andrey Drobyshev
2026-11-03 13:01   ` Kevin Wolf [this message]
2026-09-30 16:49 ` [PATCH 06/13] iotests/298: add testcase for async writes with preallocation filter Denis V. Lunev
2026-11-03 13:16   ` Kevin Wolf
2026-09-30 16:49 ` [PATCH 07/13] tests/unit: prefix the iothread test helper Denis V. Lunev
2026-10-05 20:06   ` Eric Blake
2026-09-30 16:49 ` [PATCH 08/13] qemu-io: accept --object iothread Denis V. Lunev
2026-10-05 20:11   ` Eric Blake
2026-09-30 16:49 ` [PATCH 09/13] qemu-io: add -t to run an aio request in a named iothread Denis V. Lunev
2026-10-05 20:28   ` Eric Blake
2026-09-30 16:49 ` [PATCH 10/13] qemu-io: add -g to write past the end of the image Denis V. Lunev
2026-10-05 20:36   ` Eric Blake
2026-11-03 13:25   ` Kevin Wolf
2026-09-30 16:49 ` [PATCH 11/13] block/blkdebug: make a breakpoint work across AioContexts Denis V. Lunev
2026-10-05 20:42   ` Eric Blake
2026-11-03 13:32   ` Kevin Wolf
2026-09-30 16:49 ` [PATCH 12/13] block: add blkdebug events for a write before it is tracked Denis V. Lunev
2026-10-05 20:45   ` Eric Blake
2026-09-30 16:49 ` [PATCH 13/13] iotests/298: cover the preallocation races Denis V. Lunev
2026-10-05 21:06   ` Eric Blake
2026-11-03 13:48   ` Kevin Wolf
2026-10-30 11:12 ` [PATCH 00/13] block: fix data loss in the preallocate filter Denis V. Lunev
2026-11-03 13:49   ` Kevin Wolf

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=aunbMKIJAaKpoB5Y@redhat.com \
    --to=kwolf@redhat.com \
    --cc=andrey.drobyshev@virtuozzo.com \
    --cc=den@openvz.org \
    --cc=hreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    --cc=vsementsov@yandex-team.ru \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.