All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Ming Lei <ming.lei@canonical.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	linux-kernel@vger.kernel.org,
	Dave Kleikamp <dave.kleikamp@oracle.com>,
	Zach Brown <zab@zabbo.net>, Christoph Hellwig <hch@infradead.org>,
	Maxim Patlasov <mpatlasov@parallels.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Tejun Heo <tj@kernel.org>, Dave Chinner <david@fromorbit.com>
Subject: Re: [PATCH v8 6/6] block: loop: support DIO & AIO
Date: Thu, 30 Jul 2015 09:42:33 -0700	[thread overview]
Message-ID: <20150730164233.GA14158@infradead.org> (raw)
In-Reply-To: <1438256184-23645-7-git-send-email-ming.lei@canonical.com>

On Thu, Jul 30, 2015 at 07:36:24AM -0400, Ming Lei wrote:
> +	/*
> +	 * When working at direct I/O, under very unusual cases,
> +	 * such as unaligned direct I/O from application and
> +	 * access to loop block device with 'unaligned' offset & size,
> +	 * we have to fallback to non-dio mode.
> +	 *
> +	 * During the switch between dio and non-dio, page cache
> +	 * has to be flushed to the backing file.
> +	 */
> +	if (unlikely(lo->use_dio && lo->last_use_dio != cmd->use_aio))
> +		vfs_fsync(lo->lo_backing_file, 0);

Filesystems do the cache flushing for you.

> +static inline bool req_dio_aligned(struct loop_device *lo,
> +		const struct request *rq)
> +{
> +	return !((blk_rq_pos(rq) << 9) & lo->dio_align) &&
> +		!(blk_rq_bytes(rq) & lo->dio_align);
> +}
> +
>  static int loop_queue_rq(struct blk_mq_hw_ctx *hctx,
>  		const struct blk_mq_queue_data *bd)
>  {
> @@ -1554,6 +1658,13 @@ static int loop_queue_rq(struct blk_mq_hw_ctx *hctx,
>  	if (lo->lo_state != Lo_bound)
>  		return -EIO;
>  
> +	if (lo->use_dio && !lo->transfer &&
> +			req_dio_aligned(lo, bd->rq) &&
> +			!(cmd->rq->cmd_flags & (REQ_FLUSH | REQ_DISCARD)))
> +		cmd->use_aio = true;
> +	else
> +		cmd->use_aio = false;

But honestly run time switching between buffered I/O and direct I/O from
the same I/O stream is almost asking for triggering every possible
race in the dio vs buffered I/O synchronization.  And there have been
a lot of those..

I'd feel much more comfortable with a setup time check.

  reply	other threads:[~2015-07-30 16:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-30 11:36 [PATCH v8 0/6] block: loop: improve loop with AIO Ming Lei
2015-07-30 11:36 ` [PATCH v8 1/6] fs: direct-io: don't dirtying pages for ITER_BVEC/ITER_KVEC direct read Ming Lei
2015-07-30 11:36 ` [PATCH v8 2/6] block: loop: set QUEUE_FLAG_NOMERGES for request queue of loop Ming Lei
2015-07-30 11:36 ` [PATCH v8 3/6] block: loop: use kthread_work Ming Lei
2015-07-30 11:36 ` [PATCH v8 4/6] block: loop: prepare for supporing direct IO Ming Lei
     [not found]   ` <1438256184-23645-5-git-send-email-ming.lei-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
2015-07-30 15:09     ` Christoph Hellwig
2015-07-30 15:09       ` Christoph Hellwig
2015-07-30 15:21       ` Ming Lei
2015-07-30 15:30     ` Dave Kleikamp
2015-07-30 15:30       ` Dave Kleikamp
     [not found]       ` <55BA432F.3050603-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2015-07-30 15:45         ` Ming Lei
2015-07-30 15:45           ` Ming Lei
2015-07-30 11:36 ` [PATCH v8 5/6] block: loop: introduce ioctl command of LOOP_SET_DIRECT_IO Ming Lei
2015-07-30 11:36 ` [PATCH v8 6/6] block: loop: support DIO & AIO Ming Lei
2015-07-30 16:42   ` Christoph Hellwig [this message]
2015-07-31  3:13     ` Ming Lei

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=20150730164233.GA14158@infradead.org \
    --to=hch@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=dave.kleikamp@oracle.com \
    --cc=david@fromorbit.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.lei@canonical.com \
    --cc=mpatlasov@parallels.com \
    --cc=tj@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=zab@zabbo.net \
    /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.