Re: Why is one sync() not enough?

From: Denis Vlasenko
Date: Wed Jun 15 2005 - 04:29:47 EST


On Wednesday 15 June 2005 11:17, Helge Hafting wrote:
> Nico Schottelius wrote:
>
> >Hello again!
> >
> >When my system shuts down and init calls sync() and after that
> >umount and then reboot, the filesystem is left in an unclean state.
> >
> >If I do sync() two times (one before umount, one after umount) it
> >seems to work.

sync before umount is superfluous.

> >Can someboy explain that to me?
> >
> >
> You shouldn't need those syncs, as umount does its own
> syncing. There may be other explanations:
>
> * Your reboot actually powers down (or resets) the disk.
> IDE disks are known for caching stuff, they may indicate
> that data is written slightly before it actually happens.
> (The same applies to scsi - if you enable caching there for
> the little extra performance it buys.)
>
> Rebooting really quickly after umount in such a case can cut
> power to the disk before it finishes writing. If this is the case,
> then a few seconds of sleep after umount before reboot
> will work just as well as that sync. I don't recommend this
> as a solution, but it is an easy diagnostic!
>
> * Your startup script accidentally mounted the fs twice.
> (Yes - linux support that, and the first umount won't undo
> both mounts.) This simply means the fs isn't umounted
> when you reboot, but an extra sync and you might get lucky.

My reboot script is checking (/proc/mounts) for stray rw mounts on reboot,
prints a warning and waits for a keypress. This helps spot such things.
--
vda

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/