public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* Do I have to fsync after aio_write finishes (with fallocate preallocation) ?
@ 2022-11-29 19:20 Shawn
  2022-11-29 21:17 ` Darrick J. Wong
  2022-11-29 21:34 ` Dave Chinner
  0 siblings, 2 replies; 10+ messages in thread
From: Shawn @ 2022-11-29 19:20 UTC (permalink / raw)
  To: linux-xfs

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?

Thanks all for your input!

regards,
Shawn

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-09-01 23:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox