From patchwork Tue Nov 19 00:28:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13879271 Received: from 009.lax.mailroute.net (009.lax.mailroute.net [199.89.1.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 147AC1CA81; Tue, 19 Nov 2024 00:28:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731976137; cv=none; b=n9gRfcoa/kf+zXo83tQ5P1exnIHniC+5co7K/gXhWRfvIKUSmevKvnEW/uorq20UxSZ1dbDnzZc3wO3EE19biEZgvJ8j88cUHDcDVcDc7XZuHWzFB4JP2lyePC9FRmauq1v9umtHZzXuyLL+B817oCgi0FSAT56GMyCLOItZxD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731976137; c=relaxed/simple; bh=rKdB9eAJuqecXPJ1Ip+TFvZjsbRzDHsvQKGOfrBPXSA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rAL+WzIoq3arpWvsVUoX7BLEgGqtVeZGWBxUu7HZqqI9DASP3WudUjuaGD714u8yfySe0WPbJEw9cb6n6G6m9zmR7LquxYneAVQdkHNGSmj2J8R/i0hZQGXYxtP8fJieyMny64vL1UqbifZw62sje36OAFAtMpI1NlZH7IhNUCI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=nVWwhhCA; arc=none smtp.client-ip=199.89.1.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="nVWwhhCA" Received: from localhost (localhost [127.0.0.1]) by 009.lax.mailroute.net (Postfix) with ESMTP id 4XsljM5slyzlgMVX; Tue, 19 Nov 2024 00:28:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1731976131; x=1734568132; bh=mRFhE hPfN0g3PDtdjUeIsCcBOXYtmEpeE7xYsQ1hmxs=; b=nVWwhhCAwcKDxDG+iQNRU zgerqZrXl5obg1jAvS5PXpKE37mGFGYuM9xrauFZtSHSq8kAm4mouqUnkTu/lslh HPtWjjKQq6qBr6C/Hg/FOqm4jB+wri1xn7hASjj8YZIkT3uee/glrGpYenf1DXLe 4H2asKTfoa/YlfSXcIk8ZfUVtk3c5+VhHngDUQl63zTDwPvMAzO89bIyIPRiB4k+ uthqW93F0atMQsXI09Gdj+i6AJ4K1pq+iW2SFVpdHC7tfrMe9eFgyTihqHL60kr2 jSO1vor6Hl6wNMYM5R+n33vKmhylQYwgFrCLp1oINiVaSW5Vd9EF2gOaRgy8UElR A== X-Virus-Scanned: by MailRoute Received: from 009.lax.mailroute.net ([127.0.0.1]) by localhost (009.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id 8O4LOpz5ytuX; Tue, 19 Nov 2024 00:28:51 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 009.lax.mailroute.net (Postfix) with ESMTPSA id 4XsljF68b2zlgT1M; Tue, 19 Nov 2024 00:28:49 +0000 (UTC) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, Christoph Hellwig , Damien Le Moal , Jaegeuk Kim , Bart Van Assche Subject: [PATCH v16 13/26] block: Support allocating from a specific software queue Date: Mon, 18 Nov 2024 16:28:02 -0800 Message-ID: <20241119002815.600608-14-bvanassche@acm.org> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog In-Reply-To: <20241119002815.600608-1-bvanassche@acm.org> References: <20241119002815.600608-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A later patch will preserve the order of pipelined zoned writes by submitting all zoned writes per zone to the same queue as previously submitted zoned writes. Hence support allocating a request from a specific queue. Signed-off-by: Bart Van Assche --- block/blk-mq.c | 18 ++++++++++++++---- block/blk-mq.h | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 5ff124fbc17c..f134d5e1c4a1 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -493,6 +493,7 @@ __blk_mq_alloc_requests_batch(struct blk_mq_alloc_data *data) static struct request *__blk_mq_alloc_requests(struct blk_mq_alloc_data *data) { struct request_queue *q = data->q; + int swq_cpu = data->swq_cpu; u64 alloc_time_ns = 0; struct request *rq; unsigned int tag; @@ -505,7 +506,8 @@ static struct request *__blk_mq_alloc_requests(struct blk_mq_alloc_data *data) data->flags |= BLK_MQ_REQ_NOWAIT; retry: - data->ctx = blk_mq_get_ctx(q); + data->swq_cpu = swq_cpu >= 0 ? swq_cpu : raw_smp_processor_id(); + data->ctx = __blk_mq_get_ctx(q, data->swq_cpu); data->hctx = blk_mq_map_queue(q, data->cmd_flags, data->ctx); if (q->elevator) { @@ -585,6 +587,7 @@ static struct request *blk_mq_rq_cache_fill(struct request_queue *q, .cmd_flags = opf, .nr_tags = plug->nr_ios, .cached_rqs = &plug->cached_rqs, + .swq_cpu = -1, }; struct request *rq; @@ -646,6 +649,7 @@ struct request *blk_mq_alloc_request(struct request_queue *q, blk_opf_t opf, .flags = flags, .cmd_flags = opf, .nr_tags = 1, + .swq_cpu = -1, }; int ret; @@ -2969,12 +2973,14 @@ static bool blk_mq_attempt_bio_merge(struct request_queue *q, } static struct request *blk_mq_get_new_requests(struct request_queue *q, + int swq_cpu, struct blk_plug *plug, struct bio *bio, unsigned int nsegs) { struct blk_mq_alloc_data data = { .q = q, + .swq_cpu = swq_cpu, .nr_tags = 1, .cmd_flags = bio->bi_opf, }; @@ -3001,7 +3007,8 @@ static struct request *blk_mq_get_new_requests(struct request_queue *q, * Check if there is a suitable cached request and return it. */ static struct request *blk_mq_peek_cached_request(struct blk_plug *plug, - struct request_queue *q, blk_opf_t opf) + struct request_queue *q, + int swq_cpu, blk_opf_t opf) { enum hctx_type type = blk_mq_get_hctx_type(opf); struct request *rq; @@ -3011,6 +3018,8 @@ static struct request *blk_mq_peek_cached_request(struct blk_plug *plug, rq = rq_list_peek(&plug->cached_rqs); if (!rq || rq->q != q) return NULL; + if (swq_cpu >= 0 && rq->mq_ctx->cpu != swq_cpu) + return NULL; if (type != rq->mq_hctx->type && (type != HCTX_TYPE_READ || rq->mq_hctx->type != HCTX_TYPE_DEFAULT)) return NULL; @@ -3069,6 +3078,7 @@ void blk_mq_submit_bio(struct bio *bio) struct blk_mq_hw_ctx *hctx; unsigned int nr_segs; struct request *rq; + int swq_cpu = -1; blk_status_t ret; /* @@ -3111,7 +3121,7 @@ void blk_mq_submit_bio(struct bio *bio) goto queue_exit; new_request: - rq = blk_mq_peek_cached_request(plug, q, bio->bi_opf); + rq = blk_mq_peek_cached_request(plug, q, swq_cpu, bio->bi_opf); if (rq) { blk_mq_use_cached_rq(rq, plug, bio); /* @@ -3121,7 +3131,7 @@ void blk_mq_submit_bio(struct bio *bio) */ blk_queue_exit(q); } else { - rq = blk_mq_get_new_requests(q, plug, bio, nr_segs); + rq = blk_mq_get_new_requests(q, swq_cpu, plug, bio, nr_segs); if (unlikely(!rq)) goto queue_exit; } diff --git a/block/blk-mq.h b/block/blk-mq.h index 89a20fffa4b1..309db553aba6 100644 --- a/block/blk-mq.h +++ b/block/blk-mq.h @@ -158,6 +158,7 @@ struct blk_mq_alloc_data { struct rq_list *cached_rqs; /* input & output parameter */ + int swq_cpu; struct blk_mq_ctx *ctx; struct blk_mq_hw_ctx *hctx; };