From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christoph Hellwig Subject: Re: fsync() does not flush all the file Date: Fri, 2 Sep 2011 04:13:12 -0400 Message-ID: <20110902081312.GA20157@infradead.org> References: <65CD3FC07F3BF942ABE211646D72D77001C00C@IRSMSX102.ger.corp.intel.com> <20110901215010.GA12057@infradead.org> <65CD3FC07F3BF942ABE211646D72D77001C375@IRSMSX102.ger.corp.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Christoph Hellwig , "linux-fsdevel@vger.kernel.org" To: "Berthier, Emmanuel" Return-path: Received: from 173-166-109-252-newengland.hfc.comcastbusiness.net ([173.166.109.252]:54551 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932125Ab1IBINN (ORCPT ); Fri, 2 Sep 2011 04:13:13 -0400 Content-Disposition: inline In-Reply-To: <65CD3FC07F3BF942ABE211646D72D77001C375@IRSMSX102.ger.corp.intel.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Fri, Sep 02, 2011 at 07:59:56AM +0000, Berthier, Emmanuel wrote: > > I've reproduced the issue on a PC with Ubuntu 10.04, but as the SSD drive contains cache, it's clear that this configuration can't guaranty the immediate flushing of the file on the flash memory. > > A new info of today: the issue disappears if I call fflush() before fsync(): all the file is well flushed at a time. > The problem is that this is not the behavior of Sqlite3.6.2 (I've trace sys calls with strace, no fflush() on journal) (same for last 3.7.7.1). > > Who's wrong? FS or Sqlite? Oh. that actually sounds very much like a bug in sqlite. If you use the fread/fwrite family of userspace-buffered stream I/O you do need the fflush call to actually make the written data visible to the kernel, fsync has no chance to pick it up before that. It really surprise me sqlite uses fwrite for its intent log, as loggin generall is absolutely latency an integrity critical, and the streaming I/O APIs just make that more complicated.