From patchwork Mon Jul 17 20:52:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13316582 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FD67C001DF for ; Mon, 17 Jul 2023 20:53:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229886AbjGQUxR (ORCPT ); Mon, 17 Jul 2023 16:53:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229658AbjGQUxP (ORCPT ); Mon, 17 Jul 2023 16:53:15 -0400 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4BF21725 for ; Mon, 17 Jul 2023 13:52:31 -0700 (PDT) Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-5577900c06bso3772733a12.2 for ; Mon, 17 Jul 2023 13:52:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689627151; x=1692219151; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nVSZbVbHnYr4oPJtre+peVtx9ULfxBAErKcKzg0bkGo=; b=bwmgYrGxumBZZqaT2xGEE6poTEv8MbZTvdwqAMz6o241uftyy+VL+8KjtOM5rMD8hf UwA/+bfq1WDaLcRFnoi0xJ6nZaSG/siZXfVe7xNOk9OcGn8kKmhiBxNKughgJOFUevQi sYlrD6R87qQMMMTHdwmapZy17JK/mFJidAH+YexdcTnoxlqIHxwt7FCrAw8TD7JG9Upz Aze58rWkQoAHHph45wmPgdWXjrl6CR/ANTe8TPEtq725916MSbYwM47zySEA0FzvF2Xp MAErYTZcPwfpJjyqiYMBLS4xSkjVQiD+poKrCdZVFcAsoHXApkXPAGdzCYM+NJlt3iEx 0I0g== X-Gm-Message-State: ABy/qLbgKwLiMvBdcgm23LJZdDEGdEoHEbHYcRteX/M8h2+nkV1p0SQy ztenSng/R7VIxIRcGM56tlg= X-Google-Smtp-Source: APBJJlHhebQiAEEp/s+2qZtNhZeSgejD+aqeb4F5EKr0V25ZS3YmkT1iD08aHoFUtJR0cpcDBKNDKQ== X-Received: by 2002:a17:90a:b00d:b0:259:b065:da4f with SMTP id x13-20020a17090ab00d00b00259b065da4fmr12266934pjq.36.1689627150877; Mon, 17 Jul 2023 13:52:30 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ac3:b183:3725:4b8f]) by smtp.gmail.com with ESMTPSA id v17-20020a17090abb9100b0025645ce761dsm5222403pjr.35.2023.07.17.13.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jul 2023 13:52:30 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , "Martin K . Petersen" , Bart Van Assche , "James E.J. Bottomley" Subject: [PATCH 1/3] scsi: Inline scsi_kick_queue() Date: Mon, 17 Jul 2023 13:52:13 -0700 Message-ID: <20230717205216.2024545-2-bvanassche@acm.org> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog In-Reply-To: <20230717205216.2024545-1-bvanassche@acm.org> References: <20230717205216.2024545-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org scsi_kick_queue() is too short to keep it as a separate function. Hence inline it. Cc: Martin K. Petersen Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_lib.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index ad9afae49544..414d29eef968 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -300,11 +300,6 @@ void scsi_device_unbusy(struct scsi_device *sdev, struct scsi_cmnd *cmd) cmd->budget_token = -1; } -static void scsi_kick_queue(struct request_queue *q) -{ - blk_mq_run_hw_queues(q, false); -} - /* * Kick the queue of SCSI device @sdev if @sdev != current_sdev. Called with * interrupts disabled. @@ -340,7 +335,7 @@ static void scsi_single_lun_run(struct scsi_device *current_sdev) * but in most cases, we will be first. Ideally, each LU on the * target would get some limited time or requests on the target. */ - scsi_kick_queue(current_sdev->request_queue); + blk_mq_run_hw_queues(current_sdev->request_queue, false); spin_lock_irqsave(shost->host_lock, flags); if (!starget->starget_sdev_user) @@ -427,7 +422,7 @@ static void scsi_starved_list_run(struct Scsi_Host *shost) continue; spin_unlock_irqrestore(shost->host_lock, flags); - scsi_kick_queue(slq); + blk_mq_run_hw_queues(slq, false); blk_put_queue(slq); spin_lock_irqsave(shost->host_lock, flags); From patchwork Mon Jul 17 20:52:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13316581 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2066C001DC for ; Mon, 17 Jul 2023 20:53:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229525AbjGQUxQ (ORCPT ); Mon, 17 Jul 2023 16:53:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229690AbjGQUxP (ORCPT ); Mon, 17 Jul 2023 16:53:15 -0400 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBE6810FE for ; Mon, 17 Jul 2023 13:52:32 -0700 (PDT) Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2674d0e10c4so2617101a91.3 for ; Mon, 17 Jul 2023 13:52:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689627152; x=1692219152; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DH+74KMTL+L9e/FPJJhBQz9M6cjA6jC0gGOvpB2jAmc=; b=CuslUpiddDiFhafVdkKe9Dy9tPlaefwNgDAfrjQeWdRqYkrYgD/rK1jj9TkFWdf3nS V0DmWawtcpFWfsuBDtlw7fUX2sPSP2ws0wwCnoyY8O9rC3ztczWZ1e9BXiD6LZvDyrsI sz92h7PNBrC4bJXk+qJuCf/EDkfObK7IgrGpczpzgP+KSU/bS0h/PwzpYDIXWNnk/Vzm Wwe1MDKBaPRCV2S1S4qtE+fbfJ5A/UAjqN7mIZMNfcvry5It+C9OxbuQAGVzfVvcC0hD LxdGOAuMoQbup/tqD5BiWo5lk21qOEYD8MTmpY7iQnYNintdgE/j5ar48CA6Q1UZHgdx 8XDQ== X-Gm-Message-State: ABy/qLZlcKA4bDO3abWK6OkntPKVzinAQvnSkJAP2mhpP6+ceM+PYrzB si/nf/T3QU4XsWhmYxHeJWX4hptvMx0= X-Google-Smtp-Source: APBJJlE0MrMC2wiJqc4A2PixPJLclEPbgbnkga1Ii5YHp/GF6UUsQaWiLzDMiU6TTyMF7FDWPPYecA== X-Received: by 2002:a17:90a:9307:b0:262:df58:2411 with SMTP id p7-20020a17090a930700b00262df582411mr9460711pjo.18.1689627152155; Mon, 17 Jul 2023 13:52:32 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ac3:b183:3725:4b8f]) by smtp.gmail.com with ESMTPSA id v17-20020a17090abb9100b0025645ce761dsm5222403pjr.35.2023.07.17.13.52.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jul 2023 13:52:31 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , "Martin K . Petersen" , Bart Van Assche , "James E.J. Bottomley" Subject: [PATCH 2/3] scsi: Remove a blk_mq_run_hw_queues() call Date: Mon, 17 Jul 2023 13:52:14 -0700 Message-ID: <20230717205216.2024545-3-bvanassche@acm.org> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog In-Reply-To: <20230717205216.2024545-1-bvanassche@acm.org> References: <20230717205216.2024545-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org blk_mq_kick_requeue_list() calls blk_mq_run_hw_queues() asynchronously. Leave out the direct blk_mq_run_hw_queues() call since it is superfluous. Note: scsi_run_queue() is not called from the hot I/O submission path so there is no performance concern. Cc: Martin K. Petersen Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_lib.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 414d29eef968..7043ca0f4da9 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -448,7 +448,6 @@ static void scsi_run_queue(struct request_queue *q) scsi_starved_list_run(sdev->host); blk_mq_kick_requeue_list(q); - blk_mq_run_hw_queues(q, false); } void scsi_requeue_run_queue(struct work_struct *work) From patchwork Mon Jul 17 20:52:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13316583 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97351EB64DC for ; Mon, 17 Jul 2023 20:53:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231292AbjGQUxS (ORCPT ); Mon, 17 Jul 2023 16:53:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230376AbjGQUxP (ORCPT ); Mon, 17 Jul 2023 16:53:15 -0400 Received: from mail-io1-f41.google.com (mail-io1-f41.google.com [209.85.166.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7925F1703 for ; Mon, 17 Jul 2023 13:52:34 -0700 (PDT) Received: by mail-io1-f41.google.com with SMTP id ca18e2360f4ac-78666f06691so208853539f.0 for ; Mon, 17 Jul 2023 13:52:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689627153; x=1692219153; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oKt7u9+EufxKoWSvSSwWfFwZSG4OcmiYT019qH8A3aE=; b=MrrcOkKa3AVM/uaApXpZgcxfUhxy+02Kr64nL5K3A6DfbYZXw0IBPnEky7slqPtDhA Gum+LaGXZ//31dxrD6HRF7Wy4XcGGhKAJWKJRSq9AEC8UgXkD63ZAhJQmAqhpCyeAtDU 6ydIyQv9Ovd6dzRDWcaY+ypwbhCbBshtW0jbL6Cta5SnxcLx28pW/SBI73l29gBYWhNS t2M/t/QFfSPdOs4kihmLfSP5R5YMnGk8JOhhEiZDX6b7iBcpXtbO1jFjQAVRKu9J0Pnk WjqIA/UZZa68HFGXb9Wnf6fcd/mUNP/pIuUke8xp6EprOiuIL8MKQ4S2kSdczSvOK87R XHNg== X-Gm-Message-State: ABy/qLZSO7Zfo88g0HKuzS/vgRoLxHH9bBWfhkbs7qPtTlY3aLR9SEmX 089RNj+OmNXGAgzjPKX5opE= X-Google-Smtp-Source: APBJJlFxUGJZcq3xL1IGEUtqf/igiOMLmdPxmULzYW92d67CYEezI/P9MB0isVyVAj9xtAwMexPFiw== X-Received: by 2002:a92:ca0c:0:b0:347:7603:6865 with SMTP id j12-20020a92ca0c000000b0034776036865mr870869ils.11.1689627153482; Mon, 17 Jul 2023 13:52:33 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ac3:b183:3725:4b8f]) by smtp.gmail.com with ESMTPSA id v17-20020a17090abb9100b0025645ce761dsm5222403pjr.35.2023.07.17.13.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jul 2023 13:52:33 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , "Martin K . Petersen" , Bart Van Assche , Ming Lei , "James E.J. Bottomley" Subject: [PATCH 3/3] block: Improve performance for BLK_MQ_F_BLOCKING drivers Date: Mon, 17 Jul 2023 13:52:15 -0700 Message-ID: <20230717205216.2024545-4-bvanassche@acm.org> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog In-Reply-To: <20230717205216.2024545-1-bvanassche@acm.org> References: <20230717205216.2024545-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org blk_mq_run_queue() runs the queue asynchronously if BLK_MQ_F_BLOCKING has been set. This is suboptimal since running the queue asynchronously is slower than running the queue synchronously. This patch modifies blk_mq_run_queue() as follows if BLK_MQ_F_BLOCKING has been set: - Run the queue synchronously if it is allowed to sleep. - Run the queue asynchronously if it is not allowed to sleep. Additionally, blk_mq_run_hw_queue(hctx, false) calls are modified into blk_mq_run_hw_queue(hctx, hctx->flags & BLK_MQ_F_BLOCKING) if the caller may be invoked from atomic context. The following caller chains have been reviewed: blk_mq_run_hw_queue(hctx, false) blk_mq_get_tag() /* may sleep, hence the functions it calls may also sleep */ blk_execute_rq_nowait() nvme_*() /* the NVMe driver does not set BLK_MQ_F_BLOCKING */ scsi_eh_lock_door() /* may sleep */ sg_common_write() /* implements an ioctl and hence may sleep */ st_scsi_execute() /* may sleep */ pscsi_execute_cmd() /* may sleep */ ufshpb_execute_umap_req() /* A request to remove HPB has been submitted. */ ufshbp_execute_map_req() /* A request to remove HPB has been submitted. */ blk_execute_rq() /* may sleep */ blk_mq_run_hw_queues(q, async=false) blk_freeze_queue_start() /* may sleep */ blk_mq_requeue_work() /* may sleep */ scsi_kick_queue() scsi_requeue_run_queue() /* may sleep */ scsi_run_host_queues() scsi_ioctl_reset() /* may sleep */ blk_mq_insert_requests(hctx, ctx, list, run_queue_async=false) blk_mq_dispatch_plug_list(plug, from_sched=false) blk_mq_flush_plug_list(plug, from_schedule=false) __blk_flush_plug(plug, from_schedule=false) blk_add_rq_to_plug() blk_execute_rq_nowait() /* see above */ blk_mq_submit_bio() /* may sleep if REQ_NOWAIT has not been set */ blk_mq_plug_issue_direct() blk_mq_flush_plug_list() /* see above */ blk_mq_dispatch_plug_list(plug, from_sched=false) blk_mq_flush_plug_list() /* see above */ blk_mq_try_issue_directly() blk_mq_submit_bio() /* may sleep if REQ_NOWAIT has not been set */ blk_mq_try_issue_list_directly(hctx, list) blk_mq_insert_requests() /* see above */ Cc: Christoph Hellwig Cc: Ming Lei Cc: Martin K. Petersen Signed-off-by: Bart Van Assche --- block/blk-mq.c | 17 +++++++++++------ drivers/scsi/scsi_lib.c | 3 +++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 5504719b970d..d5ab0bd8b472 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -1289,7 +1289,8 @@ static void blk_add_rq_to_plug(struct blk_plug *plug, struct request *rq) * * Description: * Insert a fully prepared request at the back of the I/O scheduler queue - * for execution. Don't wait for completion. + * for execution. Don't wait for completion. May sleep if BLK_MQ_F_BLOCKING + * has been set. * * Note: * This function will invoke @done directly if the queue is dead. @@ -2213,6 +2214,8 @@ void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async) */ WARN_ON_ONCE(!async && in_interrupt()); + might_sleep_if(!async && hctx->flags & BLK_MQ_F_BLOCKING); + /* * When queue is quiesced, we may be switching io scheduler, or * updating nr_hw_queues, or other things, and we can't run queue @@ -2228,8 +2231,7 @@ void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async) if (!need_run) return; - if (async || (hctx->flags & BLK_MQ_F_BLOCKING) || - !cpumask_test_cpu(raw_smp_processor_id(), hctx->cpumask)) { + if (async || !cpumask_test_cpu(raw_smp_processor_id(), hctx->cpumask)) { blk_mq_delay_run_hw_queue(hctx, 0); return; } @@ -2364,7 +2366,7 @@ void blk_mq_start_hw_queue(struct blk_mq_hw_ctx *hctx) { clear_bit(BLK_MQ_S_STOPPED, &hctx->state); - blk_mq_run_hw_queue(hctx, false); + blk_mq_run_hw_queue(hctx, hctx->flags & BLK_MQ_F_BLOCKING); } EXPORT_SYMBOL(blk_mq_start_hw_queue); @@ -2394,7 +2396,8 @@ void blk_mq_start_stopped_hw_queues(struct request_queue *q, bool async) unsigned long i; queue_for_each_hw_ctx(q, hctx, i) - blk_mq_start_stopped_hw_queue(hctx, async); + blk_mq_start_stopped_hw_queue(hctx, async || + (hctx->flags & BLK_MQ_F_BLOCKING)); } EXPORT_SYMBOL(blk_mq_start_stopped_hw_queues); @@ -2452,6 +2455,8 @@ static void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx, list_for_each_entry(rq, list, queuelist) { BUG_ON(rq->mq_ctx != ctx); trace_block_rq_insert(rq); + if (rq->cmd_flags & REQ_NOWAIT) + run_queue_async = true; } spin_lock(&ctx->lock); @@ -2612,7 +2617,7 @@ static void blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx, if ((rq->rq_flags & RQF_USE_SCHED) || !blk_mq_get_budget_and_tag(rq)) { blk_mq_insert_request(rq, 0); - blk_mq_run_hw_queue(hctx, false); + blk_mq_run_hw_queue(hctx, rq->cmd_flags & REQ_NOWAIT); return; } diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 7043ca0f4da9..197942db8016 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -329,6 +329,9 @@ static void scsi_single_lun_run(struct scsi_device *current_sdev) starget->starget_sdev_user = NULL; spin_unlock_irqrestore(shost->host_lock, flags); + /* Combining BLIST_SINGLELUN with BLK_MQ_F_BLOCKING is not supported. */ + WARN_ON_ONCE(shost->tag_set.flags & BLK_MQ_F_BLOCKING); + /* * Call blk_run_queue for all LUNs on the target, starting with * current_sdev. We race with others (to set starget_sdev_user),