From patchwork Mon May 21 23:11:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 10417035 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A25CB60545 for ; Mon, 21 May 2018 23:09:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9259628ACE for ; Mon, 21 May 2018 23:09:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8705328AD3; Mon, 21 May 2018 23:09:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D58D28AD2 for ; Mon, 21 May 2018 23:09:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751138AbeEUXJW (ORCPT ); Mon, 21 May 2018 19:09:22 -0400 Received: from mga03.intel.com ([134.134.136.65]:25869 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751112AbeEUXJW (ORCPT ); Mon, 21 May 2018 19:09:22 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 May 2018 16:09:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,428,1520924400"; d="scan'208";a="56343796" Received: from unknown (HELO localhost.lm.intel.com) ([10.232.112.44]) by fmsmga004.fm.intel.com with ESMTP; 21 May 2018 16:09:21 -0700 From: Keith Busch To: Jens Axboe , linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, Ming Lei , Christoph Hellwig , Bart Van Assche Cc: Keith Busch Subject: [RFC PATCH 1/3] blk-mq: Reference count request usage Date: Mon, 21 May 2018 17:11:29 -0600 Message-Id: <20180521231131.6685-2-keith.busch@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180521231131.6685-1-keith.busch@intel.com> References: <20180521231131.6685-1-keith.busch@intel.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds a struct kref to struct request so that request users can be sure they're operating on the same request without it changing while they're processing it. The request's tag won't be released for reuse until the last user is done with it. Signed-off-by: Keith Busch --- block/blk-mq.c | 30 +++++++++++++++++++++++------- include/linux/blkdev.h | 2 ++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 4cbfd784e837..8b370ed75605 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -332,6 +332,7 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, #endif data->ctx->rq_dispatched[op_is_sync(op)]++; + kref_init(&rq->ref); return rq; } @@ -465,13 +466,33 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q, } EXPORT_SYMBOL_GPL(blk_mq_alloc_request_hctx); +static void blk_mq_exit_request(struct kref *ref) +{ + struct request *rq = container_of(ref, struct request, ref); + struct request_queue *q = rq->q; + struct blk_mq_ctx *ctx = rq->mq_ctx; + struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, ctx->cpu); + const int sched_tag = rq->internal_tag; + + if (rq->tag != -1) + blk_mq_put_tag(hctx, hctx->tags, ctx, rq->tag); + if (sched_tag != -1) + blk_mq_put_tag(hctx, hctx->sched_tags, ctx, sched_tag); + blk_mq_sched_restart(hctx); + blk_queue_exit(q); +} + +static void blk_mq_put_request(struct request *rq) +{ + kref_put(&rq->ref, blk_mq_exit_request); +} + void blk_mq_free_request(struct request *rq) { struct request_queue *q = rq->q; struct elevator_queue *e = q->elevator; struct blk_mq_ctx *ctx = rq->mq_ctx; struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, ctx->cpu); - const int sched_tag = rq->internal_tag; if (rq->rq_flags & RQF_ELVPRIV) { if (e && e->type->ops.mq.finish_request) @@ -495,12 +516,7 @@ void blk_mq_free_request(struct request *rq) blk_put_rl(blk_rq_rl(rq)); blk_mq_rq_update_state(rq, MQ_RQ_IDLE); - if (rq->tag != -1) - blk_mq_put_tag(hctx, hctx->tags, ctx, rq->tag); - if (sched_tag != -1) - blk_mq_put_tag(hctx, hctx->sched_tags, ctx, sched_tag); - blk_mq_sched_restart(hctx); - blk_queue_exit(q); + blk_mq_put_request(rq); } EXPORT_SYMBOL_GPL(blk_mq_free_request); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index f3999719f828..26bf2c1e3502 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -257,6 +257,8 @@ struct request { struct u64_stats_sync aborted_gstate_sync; u64 aborted_gstate; + struct kref ref; + /* access through blk_rq_set_deadline, blk_rq_deadline */ unsigned long __deadline;