On 6/19/2012 3:11 PM, Derek Martin wrote:
On Sat, Jun 16, 2012 at 12:59:44PM -0400, MBR wrote:
On 6/12/2012 11:22 PM, Jack Coats wrote:
In old SunOS days, we could issue the 'sync' command, twice, to ensure
all system
buffers had been written to disk.  You could experiment to see if
issuing it occasionally
in your script helps.  Or issue it outside the script, even in a chron
might help.
Actually, calling 'sync' multiple times from a script really won't
help.  To the best of my knowledge, no Unix kernel has ever
contained code that counts the number of times sync() (the system
call that the 'sync' command issues) has been called.
The reason I was taught to do this differs from what you put forth,
and regardless it's certainly true that no modern Unix should ever
require a user to run sync manually, except possibly in very rare
circumstances.

I don't claim to know the veracity of this, but I was taught (by a
college professor who taught Unix system adminsistration as a course,
for whatever that's worth) that the reason to sync twice (not three
times) is that, as you say, the first call to sync schedules the
kernel to sync the buffers, but does not necessarily complete before
the system call returns; however (as I was told) a SUBSEQUENT call to
the sync() system call would block until any previously scheduled sync
had completed.  Thus, the completion of the SECOND sync command
guarantees that the FIRST sync completed flushing the buffers to disk.

Now, I certainly have not spent the time to look at the code to any
antiquated Unix kernels to confirm whether this was ever actually true,
anywhere.  And I don't intend to.  But it's at least plausible that it
was true at one point in some popular Unix.  As you yourself said, for
quite a long while now on Linux (since August of 1995), sync() actually
does wait until the buffers are flushed.  But even that is mostly
irrelevant as the kernel forces the buffers to be flushed periodically
and flushes them prior to system shutdown (assuming it can, of
course).

And even that won't guarantee that it's safe to power the disks down until you know that the data has been copied by the drive from it's cache to its platters.

_______________________________________________
Discuss mailing list
[email protected]
http://lists.blu.org/mailman/listinfo/discuss

Reply via email to