All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alberto Faria <albertofaria2@gmail.com>
To: Stephen Warren <swarren@wwwdotorg.org>
Cc: Christoph Hellwig <hch@infradead.org>,
	Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, Simon Glass <sjg@chromium.org>
Subject: Re: dd, close(), sync, and the Linux disk cache
Date: Wed, 19 Feb 2020 17:13:24 +0000	[thread overview]
Message-ID: <CAHB4L8htX_dsr01qegp4nOKk-_krVLSjLWJCv8LiobcmQZ+qgA@mail.gmail.com> (raw)
In-Reply-To: <dfff89c0-d3cf-96a0-7f44-4d2256a3aba3@wwwdotorg.org>

Hi,

> Can you explain further why it's necessary given that the kernel
> explicitly blocks execution of close() to flush buffers to disk,
> assuming the process is the last one with the device open? Am I
> misinterpreting the code path I mentioned later in my email? In
> practice, I can see this happening when I use dd.

From what I could gather empirically, close() does write dirty pages
from the block device's page cache to disk but does not submit a
"flush" request to the device driver. Depending on the driver and
device, this may be necessary to ensure that data is persistently
stored (e.g., if the device features an internal write-back cache).
Performing a sync command with the block device as an argument, or
reopening the device and invoking fsync() or fdatasync(), submits
and awaits that request.

The existence or non-existence of a device-internal write-back
cache, and differences in the timing and policies of such a cache,
may explain why in some cases the sync appears necessary and in
others it doesn't.

Alberto Faria

      reply	other threads:[~2020-02-19 17:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-13  0:02 dd, close(), sync, and the Linux disk cache Stephen Warren
2020-02-19 16:32 ` Christoph Hellwig
2020-02-19 17:01   ` Stephen Warren
2020-02-19 17:13     ` Alberto Faria [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHB4L8htX_dsr01qegp4nOKk-_krVLSjLWJCv8LiobcmQZ+qgA@mail.gmail.com \
    --to=albertofaria2@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=hch@infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=sjg@chromium.org \
    --cc=swarren@wwwdotorg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.