Toby DiPasquale on 8 Dec 2007 01:47:23 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] [plug-announce] December 5th, 2007: "What's a file?" presented by Mark Jason Dominus


On Thu, Dec 06, 2007 at 11:15:53AM -0500, Mark Dominus wrote:
> Normally, the kernel writes out the buffer in due time, and the data
> makes it to the disk, and you are happy because your process got to go
> ahead and do some more work without having to wait for the disk, which
> could take milliseconds.  ("A long time", as I so quaintly called it
> yesterday.)  If some other process reads the data before it is
> written, that is okay, because the kernel can give it the updated data
> out of the buffer.
> 
> But if there is a catastrophe, say a power failure, then this
> asynchronous writing technique has a serious problem:  you find out
> that the data, which your process thought had been written, has been
> lost.  
> 
> So there are a number of mechanisms in place to deal with this.  The
> oldest is the "sync()" system call, which marks all the kernel buffers
> to be written out ASAP.  All unix systems run a program called "init",
> and one of init's primary duties is to call sync() every thirty
> seconds or so, to make sure that the kernel buffers get flushed to
> disk at least every thirty secnods, and so no crash will lose more
> than about thirty seconds' worth of data.

An interesting aside to all of this is this little tidbit I picked up a
while back: IronPort made some modifications to their FreeBSD kernel for
their MTA appliance(s) and one of the mods was to never allow a context
switch to preempt a process' write. This was done for performance reasons,
since they are frequently writing (relatively) small data to disk (emails)
and apparently the context switching was a significant drag on throughput.
Kind of like O_SYNC on crack, I guess... Just throwing that out there for
all you wannabe email appliance creators ;-)

-- 
Toby DiPasquale
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug