What does sync() _really_ do?

Melinda Shore shore at mtxinu.COM
Mon Dec 17 13:29:08 AEST 1990


In article <1635 at lot.ACA.MCC.COM> ables at lot.ACA.MCC.COM (King Ables) writes:
>From article <52328 at mcdchg.chg.mcd.mot.com>, by heiby at mcdchg.chg.mcd.mot.com (Ron Heiby):
>> The theory was that by the time the operator typed the third command,
>> the disk blocks queued for writing by the first had had sufficient
>> time to actually be written to the disk.  
>The secret was supposed to be that the queue had only two slots
>it, thus a 3rd sync() call couldn't return having successfully
>put its request in the queue until the first sync request had
>been processed and removed from the queue.  So when the 3rd
>one returned, you knew the first one had actually happened.

No, Ron was correct (remember the old pop song "Sync 3 Times on the
Ceiling If You Want Me?").  The convention really was for the purpose
of allowing time for the write.

To the original poster, the reason for doing a sync even if you don't
need buffers is to ensure data integrity;  you do want to maximize the
likelihood that the cache contents are consistent with the state of the
disk in the event of a crash.  /etc/update syncs every 30 seconds, so
it's pretty unusual to need to do a sync in a user program.
-- 
               Hardware brevis, software longa
Melinda Shore                                 shore at mtxinu.com
mt Xinu                              ..!uunet!mtxinu.com!shore



More information about the Comp.unix.internals mailing list