Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753231AbbG3Qmg (ORCPT ); Thu, 30 Jul 2015 12:42:36 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:46739 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752783AbbG3Qmf (ORCPT ); Thu, 30 Jul 2015 12:42:35 -0400 Date: Thu, 30 Jul 2015 09:42:33 -0700 From: Christoph Hellwig To: Ming Lei Cc: Jens Axboe , linux-kernel@vger.kernel.org, Dave Kleikamp , Zach Brown , Christoph Hellwig , Maxim Patlasov , Andrew Morton , Alexander Viro , Tejun Heo , Dave Chinner Subject: Re: [PATCH v8 6/6] block: loop: support DIO & AIO Message-ID: <20150730164233.GA14158@infradead.org> References: <1438256184-23645-1-git-send-email-ming.lei@canonical.com> <1438256184-23645-7-git-send-email-ming.lei@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1438256184-23645-7-git-send-email-ming.lei@canonical.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1734 Lines: 47 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. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/