Re: Why is one sync() not enough?

From: Valdis . Kletnieks
Date: Tue Jun 14 2005 - 13:37:48 EST


On Tue, 14 Jun 2005 17:58:36 +0200, Jesper Juhl said:

> actually written. Thus it was common in ages past to run sync ; sync
> ; halt when shutting down a system since even though the first sync
> might return before writing was done

Actually, it was:

# sync
# sync
# sync
# halt

If you enter 'sync;sync;sync' all 3 will get scheduled almost on top of each
other when you hit return. If you hit return on each one, the first one starts
running when you hit return, and hopefully completes while you're typing the second
and third ones.....

'sync' on recent Linux kernels appears to be synchronous and not return until
the data is out the door. If you're seeing 'sync; unmount; sync' being needed,
the most likely cause is that the *first* sync is bogus (as unmount will flush
the buffers too) - and the *second* sync is flushing out blocks from some file
that was opened in the directory *before you did the mount*:

# cd /usr/local (with nothing mounted on it, so it's an empty dir in /usr)
# touch foo
# tail -f foo &
# mount /usr/local

Now that 'foo' is an open but unreachable file on the /usr filesystem, and will
likely cause the need for a sync *for /usr* after unmounting /usr/local at system
shutdown.

Attachment: pgp00000.pgp
Description: PGP signature