From mboxrd@z Thu Jan 1 00:00:00 1970 From: tih@hamartun.priv.no (Tom Ivar Helbekkmo) Date: Fri, 16 Jan 2015 09:40:11 +0100 Subject: [TUHS] sync; sync; sync; halt (was: Re: Illumos )) In-Reply-To: (Dave Horsfall's message of "Wed, 7 Jan 2015 12:53:46 +1100") References: <20141231062219.GA21046@mcvoy.com> <1420018115.54a3c1c32faaa@www.paradise.net.nz> <20141231131335.GA26926@mercury.ccil.org> <54A4357F.9040703@aueb.gr> <20141231203617.GB3922@mcvoy.com> <20141231224249.GA5833@mcvoy.com> Message-ID: Dave Horsfall writes: > It was drilled into us that the correct usage was: > > # sync > # sync > # sync > > This gives the disk buffers time to actually flush (the writes were merely > scheduled, and were asynchronous). There is another reason why multiple syncs before halting the system were needed. There was no fancy I/O order juggling, so everything was written in the same chronological order as it was scheduled. If you look at 6th edition source code, you'll find that a call to sync would invoke the internal routine update(), which does three things in order: 1: schedule writes of superblocks, and wait for them to complete 2: update in-memory inode time stamps wherever needed 3: schedule writes of inodes and data blocks that are now dirty What this means is that the second sync, by waiting for its own superblock writes, will wait until all the inode and file data flushes scheduled by the first one have completed. What I haven't been able to figure out from a few minutes studying the code, is whether the third sync is really needed, or just a "belt and suspenders" thing. I've heard it claimed that the flushing of inodes and/or file data going on while the second sync is waiting for its already scheduled superblock writes to complete will cause the third one to be needed. That would mean either that flushing dirty file blocks could cause inode updates, or that flushing inodes could cause superblock updates. Anyone know the internals well enough to say? -tih -- Popularity is the hallmark of mediocrity. --Niles Crane, "Frasier"