fsync(2) and on-disk write-back cache

Benjamin Kaduk kaduk at MIT.EDU
Tue Aug 31 16:12:10 UTC 2010


On Tue, 31 Aug 2010, Jeremy Chadwick wrote:

> On Mon, Aug 30, 2010 at 06:58:42PM -0400, Martin Cracauer wrote:
>> I always assumed the answer to this question is "of course":
>>
>> When doing an fsync (waiting for the commit), do we actually tell the
>> disk to flush the on-disk write-back cache (if that is in use) to the
>> platters?
>>
>> I just went down some code paths in both FreeBSD and Linux and in both
>> cases the paths for fsync quickly disappear in the generic
>> block-by-block flushing code that is also used for regular (non-fsync)
>> flushing.  I didn't see anything aware of the on-disk cache.
>
> I don't have an authoritative answer to your question, but this thread
> seems to imply there's a relation between fsync() and an intentional
> disk flush (BIO_FLUSH).  I'm sure when BIO_FLUSH is called depends on
> the filesystem as well.

It is probably also worth noting that disks have been known to lie about 
having actually flushed bits from their internal cache to the platter.

-Ben Kaduk


More information about the freebsd-fs mailing list