From: Keith Busch <keith.busch@intel.com>
To: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Jens Axboe <axboe@kernel.dk>,
linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
Tejun Heo <tj@kernel.org>,
Jianchao Wang <jianchao.w.wang@oracle.com>,
Ming Lei <ming.lei@redhat.com>,
Sebastian Ott <sebott@linux.ibm.com>,
Sagi Grimberg <sagi@grimberg.me>,
Israel Rukshin <israelr@mellanox.com>,
Max Gurtovoy <maxg@mellanox.com>
Subject: Re: [PATCH v13] blk-mq: Rework blk-mq timeout handling again
Date: Wed, 23 May 2018 08:02:32 -0600 [thread overview]
Message-ID: <20180523140231.GA9028@localhost.localdomain> (raw)
In-Reply-To: <20180522162515.20650-1-bart.vanassche@wdc.com>
On Tue, May 22, 2018 at 09:25:15AM -0700, Bart Van Assche wrote:
> +static bool blk_mq_change_rq_state(struct request *rq,
> + enum mq_rq_state old_state,
> + enum mq_rq_state new_state)
> +{
> + union blk_generation_and_state gstate = READ_ONCE(rq->gstate);
> + union blk_generation_and_state old_val = gstate;
> + union blk_generation_and_state new_val = gstate;
> +
> + old_val.state = old_state;
> + new_val.state = new_state;
> + if (new_state == MQ_RQ_IN_FLIGHT)
> + new_val.generation++;
> + /*
> + * For transitions from state in-flight to another state cmpxchg()
> + * must be used. For other state transitions it is safe to use
> + * WRITE_ONCE().
> + */
> + if (old_state != MQ_RQ_IN_FLIGHT) {
> + WRITE_ONCE(rq->gstate.val, new_val.val);
> + return true;
> + }
> + return blk_mq_set_rq_state(rq, old_val, new_val);
> +}
<snip>
> void blk_mq_complete_request(struct request *rq)
> {
> struct request_queue *q = rq->q;
> - struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, rq->mq_ctx->cpu);
> - int srcu_idx;
>
> if (unlikely(blk_should_fake_timeout(q)))
> return;
>
> - /*
> - * If @rq->aborted_gstate equals the current instance, timeout is
> - * claiming @rq and we lost. This is synchronized through
> - * hctx_lock(). See blk_mq_timeout_work() for details.
> - *
> - * Completion path never blocks and we can directly use RCU here
> - * instead of hctx_lock() which can be either RCU or SRCU.
> - * However, that would complicate paths which want to synchronize
> - * against us. Let stay in sync with the issue path so that
> - * hctx_lock() covers both issue and completion paths.
> - */
> - hctx_lock(hctx, &srcu_idx);
> - if (blk_mq_rq_aborted_gstate(rq) != rq->gstate)
> - __blk_mq_complete_request(rq);
> - hctx_unlock(hctx, srcu_idx);
> + /* The loop is for the unlikely case of a race with the timeout code. */
> + while (true) {
> + if (blk_mq_change_rq_state(rq, MQ_RQ_IN_FLIGHT,
> + MQ_RQ_COMPLETE)) {
> + __blk_mq_complete_request(rq);
> + break;
> + }
> + if (blk_mq_change_rq_state(rq, MQ_RQ_TIMED_OUT, MQ_RQ_COMPLETE))
> + break;
> + }
> }
Looks like the cmpxchg is also needed if old_state is MQ_RQ_TIMED_OUT,
otherwise its guaranteed to return 'true' and there's no point to the
loop and 'if' check.
next prev parent reply other threads:[~2018-05-23 14:02 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-22 16:25 [PATCH v13] blk-mq: Rework blk-mq timeout handling again Bart Van Assche
2018-05-22 16:44 ` Jens Axboe
2018-05-22 17:17 ` Jens Axboe
2018-05-22 18:47 ` Jens Axboe
2018-05-22 19:03 ` Jens Axboe
2018-05-22 19:38 ` Jens Axboe
2018-05-22 20:26 ` Keith Busch
2018-05-22 20:29 ` Jens Axboe
2018-05-22 21:02 ` Christoph Hellwig
2018-05-22 21:02 ` Jens Axboe
2018-05-22 20:33 ` Bart Van Assche
2018-05-22 20:38 ` Jens Axboe
2018-05-22 20:44 ` Bart Van Assche
2018-05-22 21:03 ` Jens Axboe
2018-05-23 2:35 ` Ming Lei
2018-05-22 20:33 ` Keith Busch
2018-05-22 20:36 ` Bart Van Assche
2018-05-22 20:40 ` Keith Busch
2018-05-22 20:44 ` Keith Busch
2018-05-22 20:47 ` Bart Van Assche
2018-05-23 14:02 ` Keith Busch [this message]
2018-05-23 14:08 ` Keith Busch
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=20180523140231.GA9028@localhost.localdomain \
--to=keith.busch@intel.com \
--cc=axboe@kernel.dk \
--cc=bart.vanassche@wdc.com \
--cc=hch@lst.de \
--cc=israelr@mellanox.com \
--cc=jianchao.w.wang@oracle.com \
--cc=linux-block@vger.kernel.org \
--cc=maxg@mellanox.com \
--cc=ming.lei@redhat.com \
--cc=sagi@grimberg.me \
--cc=sebott@linux.ibm.com \
--cc=tj@kernel.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 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).