From owner-freebsd-questions@FreeBSD.ORG Thu Nov 15 06:36:13 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 4A5F3FAD for ; Thu, 15 Nov 2012 06:36:13 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx02.qsc.de (mx02.qsc.de [213.148.130.14]) by mx1.freebsd.org (Postfix) with ESMTP id 060428FC13 for ; Thu, 15 Nov 2012 06:36:12 +0000 (UTC) Received: from r56.edvax.de (port-92-195-8-72.dynamic.qsc.de [92.195.8.72]) by mx02.qsc.de (Postfix) with ESMTP id 4ED2A27696; Thu, 15 Nov 2012 07:36:11 +0100 (CET) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id qAF6aBgu002063; Thu, 15 Nov 2012 07:36:11 +0100 (CET) (envelope-from freebsd@edvax.de) Date: Thu, 15 Nov 2012 07:36:11 +0100 From: Polytropon To: freebsd@dreamchaser.org Subject: Re: why sync during shutdown when sync already done? Message-Id: <20121115073611.acfe39f5.freebsd@edvax.de> In-Reply-To: <50A4544E.7030805@dreamchaser.org> References: <50A4544E.7030805@dreamchaser.org> Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: FreeBSD Mailing List X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Polytropon List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Nov 2012 06:36:13 -0000 On Wed, 14 Nov 2012 19:32:46 -0700, Gary Aitken wrote: > It's my understanding that the sequence of numbers one sees output when > shutdown is issued reflect writes of cached items. > Is that correct? > > If so, why does: > sync > shutdown -r now > still show cached items being written? Issuing the "sync" command simply tells the OS to sync any modified file I/O buffers (cache) that aren't written yet. It does not imply that the OS will do it _exactly now_, and even more, that it will _have done_ it when the command returns. So if you call sync(), the kernel will be instructed to perform the syncing operation. But keep in mind that the actual device drivers (e. g. for the hard disk in question) may delay the transfer to the disk, but tell the kernel that the operation has been completed. This minimal time window can probably be ignored, but from my understanding, syncing is a "multi-staged process". The "shutdown sync" seems to have a specific timeout that makes sure things get written definitely. That's why even the famous # sync ; sync ; sync ; reboot sequence would have the same effect. :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...