From: Jeff Moyer <jmoyer@redhat.com>
To: Ming Lei <ming.lei@canonical.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fs: direct-io: increase bio refcount as batch
Date: Tue, 31 Mar 2015 10:02:41 -0400 [thread overview]
Message-ID: <x497ftxz2m6.fsf@segfault.boston.devel.redhat.com> (raw)
In-Reply-To: <1427802746-30432-1-git-send-email-ming.lei@canonical.com> (Ming Lei's message of "Tue, 31 Mar 2015 19:52:26 +0800")
Ming Lei <ming.lei@canonical.com> writes:
> Each bio is always submitted to block device one by one,
> so it isn't necessary to increase the bio refcount by one
> each time with holding dio->bio_lock.
This patch opens up a race where a completion event can come in before
the refcount for the dio is incremented, resulting in refcount going
negative. I don't think that will actually cause problems, but it
certainly is ugly, and I doubt it was the intended design.
Before I dig into this any further, would you care to comment on why you
went down this path? Did you see spinlock contention here? And was
there a resultant performance improvement for some benchmark with the
patch applied?
Cheers,
Jeff
> Signed-off-by: Ming Lei <ming.lei@canonical.com>
> ---
> fs/direct-io.c | 27 +++++++++++++++++----------
> 1 file changed, 17 insertions(+), 10 deletions(-)
>
> diff --git a/fs/direct-io.c b/fs/direct-io.c
> index 6fb00e3..57b8e73 100644
> --- a/fs/direct-io.c
> +++ b/fs/direct-io.c
> @@ -79,6 +79,8 @@ struct dio_submit {
> get_block_t *get_block; /* block mapping function */
> dio_submit_t *submit_io; /* IO submition function */
>
> + long submitted_bio;
> +
> loff_t logical_offset_in_bio; /* current first logical block in bio */
> sector_t final_block_in_bio; /* current final block in bio + 1 */
> sector_t next_block_for_io; /* next block to be put under IO,
> @@ -121,7 +123,7 @@ struct dio {
> int is_async; /* is IO async ? */
> bool defer_completion; /* defer AIO completion to workqueue? */
> int io_error; /* IO error in completion path */
> - unsigned long refcount; /* direct_io_worker() and bios */
> + long refcount; /* direct_io_worker() and bios */
> struct bio *bio_list; /* singly linked via bi_private */
> struct task_struct *waiter; /* waiting task (NULL if none) */
>
> @@ -383,14 +385,9 @@ dio_bio_alloc(struct dio *dio, struct dio_submit *sdio,
> static inline void dio_bio_submit(struct dio *dio, struct dio_submit *sdio)
> {
> struct bio *bio = sdio->bio;
> - unsigned long flags;
>
> bio->bi_private = dio;
>
> - spin_lock_irqsave(&dio->bio_lock, flags);
> - dio->refcount++;
> - spin_unlock_irqrestore(&dio->bio_lock, flags);
> -
> if (dio->is_async && dio->rw == READ)
> bio_set_pages_dirty(bio);
>
> @@ -403,15 +400,26 @@ static inline void dio_bio_submit(struct dio *dio, struct dio_submit *sdio)
> sdio->bio = NULL;
> sdio->boundary = 0;
> sdio->logical_offset_in_bio = 0;
> + sdio->submitted_bio++;
> }
>
> /*
> * Release any resources in case of a failure
> */
> -static inline void dio_cleanup(struct dio *dio, struct dio_submit *sdio)
> +static inline void dio_cleanup(struct dio *dio, struct dio_submit *sdio,
> + bool commit_refcount)
> {
> + unsigned long flags;
> +
> while (sdio->head < sdio->tail)
> page_cache_release(dio->pages[sdio->head++]);
> +
> + if (!commit_refcount)
> + return;
> +
> + spin_lock_irqsave(&dio->bio_lock, flags);
> + dio->refcount += (sdio->submitted_bio + 1);
> + spin_unlock_irqrestore(&dio->bio_lock, flags);
> }
>
> /*
> @@ -1215,7 +1223,6 @@ do_blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
> dio->i_size = i_size_read(inode);
>
> spin_lock_init(&dio->bio_lock);
> - dio->refcount = 1;
>
> sdio.iter = iter;
> sdio.final_block_in_request =
> @@ -1234,7 +1241,7 @@ do_blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
>
> retval = do_direct_IO(dio, &sdio, &map_bh);
> if (retval)
> - dio_cleanup(dio, &sdio);
> + dio_cleanup(dio, &sdio, false);
>
> if (retval == -ENOTBLK) {
> /*
> @@ -1267,7 +1274,7 @@ do_blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
> * It is possible that, we return short IO due to end of file.
> * In that case, we need to release all the pages we got hold on.
> */
> - dio_cleanup(dio, &sdio);
> + dio_cleanup(dio, &sdio, true);
>
> /*
> * All block lookups have been performed. For READ requests
next prev parent reply other threads:[~2015-03-31 14:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-31 11:52 [PATCH] fs: direct-io: increase bio refcount as batch Ming Lei
2015-03-31 14:02 ` Jeff Moyer [this message]
2015-04-01 2:04 ` Ming Lei
2015-04-02 13:39 ` Jeff Moyer
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=x497ftxz2m6.fsf@segfault.boston.devel.redhat.com \
--to=jmoyer@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.lei@canonical.com \
--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;
as well as URLs for NNTP newsgroup(s).