From: "Darrick J. Wong" <djwong@kernel.org>
To: Shawn <neutronsharc@gmail.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: Do I have to fsync after aio_write finishes (with fallocate preallocation) ?
Date: Tue, 29 Nov 2022 13:17:58 -0800 [thread overview]
Message-ID: <Y4Z3BiqGKdPCx9Hc@magnolia> (raw)
In-Reply-To: <CAB-bdyQVJdTcaaDLWmm+rsW_U6FLF3qCTqLEKLkM6hOgk09uZQ@mail.gmail.com>
On Tue, Nov 29, 2022 at 11:20:05AM -0800, Shawn wrote:
> Hello all,
> I implemented a write workload by sequentially appending to the file
> end using libaio aio_write in O_DIRECT mode (with proper offset and
> buffer address alignment). When I reach a 1MB boundary I call
> fallocate() to extend the file.
>
> I need to protect the write from various failures such as disk unplug
> / power failure. The bottom line is, once I ack a write-complete,
> the user must be able to read it back later after a disk/power failure
> and recovery.
>
> In my understanding, fallocate() will preallocate disk space for the
> file, and I can call fsync to make sure the file metadata about this
> new space is persisted when fallocate returns. Once aio_write returns
> the data is in the disk. So it seems I don't need fsync after
> aio-write completion, because (1) the data is in disk, and (2) the
> file metadata to address the disk blocks is in disk.
>
> On the other hand, it seems XFS always does a delayed allocation
> which might break my assumption that file=>disk space mapping is
> persisted by fallocate.
>
> I can improve the data-in-disk format to carry proper header/footer to
> detect a broken write when scanning the file after a disk/power
> failure.
>
> Given all those above, do I still need a fsync() after aio_write
> completion in XFS to protect data persistence?
Yes. The only time you don't is if you're performing an O_SYNC write
to a part of a file that you've already written (and fsync'd) that's
entirely below EOF and you've arranged that the filesystem will never
COW or otherwise require metadata updates.
Hey, at least aio_fsync works now...
--D
> Thanks all for your input!
>
> regards,
> Shawn
next prev parent reply other threads:[~2022-11-29 21:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-29 19:20 Do I have to fsync after aio_write finishes (with fallocate preallocation) ? Shawn
2022-11-29 21:17 ` Darrick J. Wong [this message]
2022-11-29 21:34 ` Dave Chinner
2023-08-21 19:01 ` Shawn
2023-08-26 3:48 ` Dave Chinner
2023-08-27 1:09 ` Shawn
2023-08-28 1:01 ` Dave Chinner
2023-09-01 1:06 ` Shawn
2023-09-01 3:47 ` Dave Chinner
2023-09-01 23:50 ` Shawn
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=Y4Z3BiqGKdPCx9Hc@magnolia \
--to=djwong@kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=neutronsharc@gmail.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