Sujet : Re: Shutdown - 25 Years Later
De : invalid (at) *nospam* invalid.invalid (Richard Kettlewell)
Groupes : comp.os.linux.miscDate : 20. Apr 2025, 20:44:27
Autres entêtes
Organisation : terraraq NNTP server
Message-ID : <wwvh62i7h44.fsf@LkoBDZeT.terraraq.uk>
References : 1 2 3 4 5 6 7 8
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Pancho <
Pancho.Jones@protonmail.com> writes:
Richard Kettlewell wrote:
In short there’s no number of syncs that will guarantee your data is
all actually on disk.
>
Out of idle curiosity, what will guarantee all pending writes are
flushed to disk, apart from shutdown/reboot?
On Linux, see previous post. Portably (i.e. POSIX/SUS), however, there’s
no way to flush _all_ pending writes and let you know when they’re
complete.
But this rarely matters in practice. If your application needs to block
until data is written to underlying storage, there’s multiple options:
open files with O_SYNC, or add explicit flushes with fsync(2) or
fdatasync(2).
I seem to remember (from decades back) the actual advice was:
>
$ sync; sleep 10;
>
Or some suitable sleep period, rather than multiple sync;
Obviously that only works if you know how long it’ll take to flush all
pending writes, and that there won’t be any subsequent writes that you
care about before you do whatever it is you’re going to do that makes
you care about the question in the first place.
-- https://www.greenend.org.uk/rjk/