From: Jens Axboe <axboe@kernel.dk>
To: linux-kernel@vger.kernel.org
Cc: hch@infradead.org, Jens Axboe <axboe@kernel.dk>,
Al Viro <viro@zeniv.linux.org.uk>
Subject: [PATCH 05/11] direct-io: only inc/dec inode->i_dio_count for file systems
Date: Thu, 24 Oct 2013 10:25:58 +0100 [thread overview]
Message-ID: <1382606764-8309-6-git-send-email-axboe@kernel.dk> (raw)
In-Reply-To: <1382606764-8309-1-git-send-email-axboe@kernel.dk>
We don't need truncate protection for block devices, so add a flag
bypassing this cache line dirtying twice for every IO. This easily
contributes to 5-10% of the CPU time on high IOPS O_DIRECT testing.
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
fs/block_dev.c | 3 ++-
fs/direct-io.c | 14 +++++++++++++-
fs/inode.c | 7 ++++++-
include/linux/fs.h | 4 ++++
4 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 1e86823..e20b7c1 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -172,7 +172,8 @@ blkdev_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
struct inode *inode = file->f_mapping->host;
return __blockdev_direct_IO(rw, iocb, inode, I_BDEV(inode), iov, offset,
- nr_segs, blkdev_get_block, NULL, NULL, 0);
+ nr_segs, blkdev_get_block, NULL, NULL,
+ DIO_IGNORE_TRUNCATE);
}
int __sync_blockdev(struct block_device *bdev, int wait)
diff --git a/fs/direct-io.c b/fs/direct-io.c
index 0e04142..3c96479 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -265,7 +265,11 @@ static ssize_t dio_complete(struct dio *dio, loff_t offset, ssize_t ret,
if (dio->end_io && dio->result)
dio->end_io(dio->iocb, offset, transferred, dio->private);
- inode_dio_done(dio->inode);
+ if (dio->flags & DIO_IGNORE_TRUNCATE)
+ __inode_dio_done(dio->inode);
+ else
+ inode_dio_done(dio->inode);
+
if (is_async) {
if (dio->rw & WRITE) {
int err;
@@ -1194,6 +1198,14 @@ do_blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
}
/*
+ * Will be decremented at I/O completion time. For a block device
+ * we don't need to protect against truncate, so don't increment
+ * the inode direct IO count.
+ */
+ if (!(dio->flags & DIO_IGNORE_TRUNCATE))
+ atomic_inc(&inode->i_dio_count);
+
+ /*
* For file extending writes updating i_size before data
* writeouts complete can expose uninitialized blocks. So
* even for AIO, we need to wait for i/o to complete before
diff --git a/fs/inode.c b/fs/inode.c
index b33ba8e..22319db 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1854,6 +1854,11 @@ void inode_dio_wait(struct inode *inode)
}
EXPORT_SYMBOL(inode_dio_wait);
+void __inode_dio_done(struct inode *inode)
+{
+ wake_up_bit(&inode->i_state, __I_DIO_WAKEUP);
+}
+
/*
* inode_dio_done - signal finish of a direct I/O requests
* @inode: inode the direct I/O happens on
@@ -1864,6 +1869,6 @@ EXPORT_SYMBOL(inode_dio_wait);
void inode_dio_done(struct inode *inode)
{
if (atomic_dec_and_test(&inode->i_dio_count))
- wake_up_bit(&inode->i_state, __I_DIO_WAKEUP);
+ __inode_dio_done(inode);
}
EXPORT_SYMBOL(inode_dio_done);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 3f40547..d90a688 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2468,6 +2468,9 @@ enum {
/* filesystem does not support filling holes */
DIO_SKIP_HOLES = 0x02,
+
+ /* inode/fs/bdev does not need truncate protection */
+ DIO_IGNORE_TRUNCATE = 0x04,
};
void dio_end_io(struct bio *bio, int error);
@@ -2488,6 +2491,7 @@ static inline ssize_t blockdev_direct_IO(int rw, struct kiocb *iocb,
#endif
void inode_dio_wait(struct inode *inode);
+void __inode_dio_done(struct inode *inode);
void inode_dio_done(struct inode *inode);
extern const struct file_operations generic_ro_fops;
--
1.8.1.2
next prev parent reply other threads:[~2013-10-24 9:28 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-24 9:25 Jens Axboe
2013-10-24 9:25 ` [PATCH 01/11] Export __smp_call_function_single() Jens Axboe
2013-10-24 9:50 ` Christoph Hellwig
2013-10-24 10:16 ` Jens Axboe
2013-10-24 12:50 ` Christoph Hellwig
2013-10-25 10:21 ` Ingo Molnar
2013-10-25 10:44 ` Jens Axboe
2013-10-25 10:45 ` Ingo Molnar
2013-10-24 9:25 ` [PATCH 02/11] smp: don't warn about csd->flags having CSD_FLAG_LOCK cleared for !wait Jens Axboe
2013-10-24 9:39 ` Christoph Hellwig
2013-10-24 9:25 ` [PATCH 03/11] block: make rq->cmd_flags be 64-bit Jens Axboe
2013-10-24 9:40 ` Christoph Hellwig
2013-10-24 9:25 ` [PATCH 04/11] block: remove request ref_count Jens Axboe
2013-10-24 9:25 ` Jens Axboe [this message]
2013-10-24 9:46 ` [PATCH 05/11] direct-io: only inc/dec inode->i_dio_count for file systems Jens Axboe
2013-10-24 9:47 ` Christoph Hellwig
2013-10-24 9:49 ` Jens Axboe
2015-02-05 16:54 ` Mike Snitzer
2013-10-24 9:25 ` [PATCH 06/11] percpu_counter: make APIs irq safe Jens Axboe
2013-10-24 9:26 ` [PATCH 07/11] percpu_ida: make percpu_ida percpu size/batch configurable Jens Axboe
2013-10-24 9:26 ` [PATCH 08/11] percpu_ida: add percpu_ida_for_each_free Jens Axboe
2013-10-24 9:26 ` [PATCH 09/11] percpu_ida: add an API to return free tags Jens Axboe
2013-10-24 9:26 ` [PATCH 10/11] blk-mq: new multi-queue block IO queueing mechanism Jens Axboe
2013-10-24 9:39 ` Dave Jones
2013-10-24 9:50 ` Jens Axboe
2013-10-24 9:51 ` Christoph Hellwig
2013-10-24 9:26 ` [PATCH 11/11] null_blk: multi queue aware block test driver Jens Axboe
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=1382606764-8309-6-git-send-email-axboe@kernel.dk \
--to=axboe@kernel.dk \
--cc=hch@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox