From nobody Sun Feb 8 05:42:07 2026 Received: from mail-il1-f228.google.com (mail-il1-f228.google.com [209.85.166.228]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 945D226B96B for ; Wed, 23 Apr 2025 20:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.228 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745441497; cv=none; b=eji6nrJ8PCdvd9xV8q99iBCDVO29B0XO92Sf/35qPyjHgD0v5crvcOM04Hi8cMW4SKMvpdU/mAlVm10G+CM31OPOe1OP22HBEJBHBWtmcjdQvkw4ADl7YoNfs0HAH0oSBIrCoNFj245P6pv1gVRJBCR/FQ5rnN9BhQWFH36DUbQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745441497; c=relaxed/simple; bh=ti5z4JVtSZzRIvZC6dUX4azsCUaOndsOm7qk1lMNfYs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ooXzwapZCQ0j2VIlaSmbWErk4s+4mAeMRd3ByxqzVNMfeCtg5IuGnRRm8srVOoPtdH6rH0KxGS9jfqRX7eq8bg0CjtlI2E15oGbB9hpBC9T7ivsN+LrGN0LaAi1dtSFzqi4f1euJP+T4ikiTSVZFOx4gL19ybO3hE+VUDnWMOA4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=fail smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=MOAAfZN+; arc=none smtp.client-ip=209.85.166.228 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="MOAAfZN+" Received: by mail-il1-f228.google.com with SMTP id e9e14a558f8ab-3d90215ff34so137385ab.0 for ; Wed, 23 Apr 2025 13:51:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1745441493; x=1746046293; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=io7FZ7jM2VblIMiViDDtGdBTQwQ9HPxFb0/zqdALMPI=; b=MOAAfZN+T+TEdN5yhZmCsvpA7+DybaWK/V/IZHRG6ImaubJSB9SAPrjkna60/+uHvG nsGdFQz24ARaYmKIYHAge0+BryN64kQ8ik3ODv3cpS/pNI/n35mZuyeJldfww3I3NR+V ruVoHTf5jp1pNAwdqR0fX9IBnU0WwqiWzpitEIEPq/2/7YVC9EFV5xw6yG8hCSJ3Xwhl GMxhoGXlQeI8IPeGFNViIZsDV/uI3tL9Lj5kr3PEGA3NKsQeAeHqWZWPoyzviREQ2z8p Yu1eQzJVS0NCWP9BZQT3py93xmllkNS07J3FTt8VVgSg1bIXexsqV3qjc95DET6CgxZu yTXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745441493; x=1746046293; 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=io7FZ7jM2VblIMiViDDtGdBTQwQ9HPxFb0/zqdALMPI=; b=K1uRwA9L9wb3jsolpIEV6sg8lKVz0aijJpToAgK+XLwakNUZ3r6fhO3U0QjsG3Rhz3 lIWlyO1zPWbJjL8VwxDLQYrFvSQJeDnmTiGdGTTLylDPRFPGGXxPm/X+LnlD+g3DcYDb qGHzQbFmF+1J0YLLb4jFwky4KtwRJvL8vfeH1Rx3wHZbN5nUi2MbqBxnKcZFnc2fCmif QZPm7X7pUmCwj6tQHG0X71Mq80xpqr1U0RcH4KXlEbXddWgLa750FgMTCkkwDoODi+uu 1h58wUy3jegvU8ECRnLh03pk/5rCndqplSij0c9tzwFqiIBK8sz08WU1iLSwjY5vfQXl lrtw== X-Forwarded-Encrypted: i=1; AJvYcCUO/hT6W+jnXO7ltEc5304nGZrWhRM1mnTLU/S487UHPdOCtR+3ekQORBrEGtKWL08YMa4gpAxtTe0B+Iw=@vger.kernel.org X-Gm-Message-State: AOJu0YxGa56Wq+knt/wtFlmaPp7zA8F6n/+2nNr1qxtum6QU+8/mXebV HCecFViTtprGiqpKLZfoTyZtEy4LuwUNCWwV5el8SD8B7AXsYj6iL8O3Jr7MO/BAC95OY4YM8E0 lJioAf7v8Bol7i5mPvmztVmy1l5cDx+r+aZxrPzqj9VKfn87O X-Gm-Gg: ASbGncvWEhVg1M6lqiKXkyYuO50f6SWM/1OLe90n2bWbwX93qxI6UDlecxagjN/ccb2 tprKhURW5O7Z/NAv2+ywafwl7KeQwrseCI3d2WqkQrVd3sMK4X34ij/hNLHw0Ki15U6WNro2bbi u3K69WkZY1/HcvhZTZtpVkdVmJ//bR5F1JWiAIKRbM8/x+6hVjpKJXrWPIx7zOIe7Pcu3qn/o18 2Ua8cbdyPq7K/mCoQDZPfbGat7RQcgUZDmPjEsNM6NQxDJCGDgkAfWGaKR9BVePrJzmAs7AJun6 /KSmtvXuhNOwez5TZWvOnAkv20WJeQ== X-Google-Smtp-Source: AGHT+IH2QoG9AKfqv9dap7Sq/fd6X84H+flJOYdI2qKcxs5wCyuBiQ9DiPZiZOePpQ0Cj6W+5e0sHjw2hq4k X-Received: by 2002:a05:6e02:17cd:b0:3d9:2d10:9dd2 with SMTP id e9e14a558f8ab-3d930481fefmr272895ab.7.1745441493683; Wed, 23 Apr 2025 13:51:33 -0700 (PDT) Received: from c7-smtp-2023.dev.purestorage.com ([2620:125:9017:12:36:3:5:0]) by smtp-relay.gmail.com with ESMTPS id 8926c6da1cb9f-4f6a39602d6sm496856173.65.2025.04.23.13.51.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Apr 2025 13:51:33 -0700 (PDT) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (unknown [IPv6:2620:125:9007:640:ffff::418a]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id 55BDA34058D; Wed, 23 Apr 2025 14:51:33 -0600 (MDT) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 50B25E42828; Wed, 23 Apr 2025 14:51:33 -0600 (MDT) From: Caleb Sander Mateos To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Caleb Sander Mateos Subject: [PATCH 1/3] block: take rq_list instead of plug in dispatch functions Date: Wed, 23 Apr 2025 14:51:25 -0600 Message-ID: <20250423205127.2976981-2-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250423205127.2976981-1-csander@purestorage.com> References: <20250423205127.2976981-1-csander@purestorage.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" blk_mq_plug_issue_direct(), __blk_mq_flush_plug_list(), and blk_mq_dispatch_plug_list() take a struct blk_plug * but only use its mq_list. Pass the struct rq_list * instead in preparation for calling them with other lists of requests. Drop "plug" from the function names as they are no longer plug-specific. Signed-off-by: Caleb Sander Mateos Reviewed-by: Christoph Hellwig --- block/blk-mq.c | 26 ++++++++++++-------------- block/mq-deadline.c | 2 +- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 554380bfd002..fb514fd41d76 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2788,19 +2788,19 @@ static blk_status_t blk_mq_request_issue_directly(s= truct request *rq, bool last) if (!blk_mq_get_budget_and_tag(rq)) return BLK_STS_RESOURCE; return __blk_mq_issue_directly(hctx, rq, last); } =20 -static void blk_mq_plug_issue_direct(struct blk_plug *plug) +static void blk_mq_issue_direct(struct rq_list *rqs) { struct blk_mq_hw_ctx *hctx =3D NULL; struct request *rq; int queued =3D 0; blk_status_t ret =3D BLK_STS_OK; =20 - while ((rq =3D rq_list_pop(&plug->mq_list))) { - bool last =3D rq_list_empty(&plug->mq_list); + while ((rq =3D rq_list_pop(rqs))) { + bool last =3D rq_list_empty(rqs); =20 if (hctx !=3D rq->mq_hctx) { if (hctx) { blk_mq_commit_rqs(hctx, queued, false); queued =3D 0; @@ -2827,29 +2827,28 @@ static void blk_mq_plug_issue_direct(struct blk_plu= g *plug) out: if (ret !=3D BLK_STS_OK) blk_mq_commit_rqs(hctx, queued, false); } =20 -static void __blk_mq_flush_plug_list(struct request_queue *q, - struct blk_plug *plug) +static void __blk_mq_flush_list(struct request_queue *q, struct rq_list *r= qs) { if (blk_queue_quiesced(q)) return; - q->mq_ops->queue_rqs(&plug->mq_list); + q->mq_ops->queue_rqs(rqs); } =20 -static void blk_mq_dispatch_plug_list(struct blk_plug *plug, bool from_sch= ed) +static void blk_mq_dispatch_list(struct rq_list *rqs, bool from_sched) { struct blk_mq_hw_ctx *this_hctx =3D NULL; struct blk_mq_ctx *this_ctx =3D NULL; struct rq_list requeue_list =3D {}; unsigned int depth =3D 0; bool is_passthrough =3D false; LIST_HEAD(list); =20 do { - struct request *rq =3D rq_list_pop(&plug->mq_list); + struct request *rq =3D rq_list_pop(rqs); =20 if (!this_hctx) { this_hctx =3D rq->mq_hctx; this_ctx =3D rq->mq_ctx; is_passthrough =3D blk_rq_is_passthrough(rq); @@ -2858,13 +2857,13 @@ static void blk_mq_dispatch_plug_list(struct blk_pl= ug *plug, bool from_sched) rq_list_add_tail(&requeue_list, rq); continue; } list_add_tail(&rq->queuelist, &list); depth++; - } while (!rq_list_empty(&plug->mq_list)); + } while (!rq_list_empty(rqs)); =20 - plug->mq_list =3D requeue_list; + *rqs =3D requeue_list; trace_block_unplug(this_hctx->queue, depth, !from_sched); =20 percpu_ref_get(&this_hctx->queue->q_usage_counter); /* passthrough requests should never be issued to the I/O scheduler */ if (is_passthrough) { @@ -2912,23 +2911,22 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, = bool from_schedule) * already know at this point that all requests belong to the * same queue, caller must ensure that's the case. */ if (q->mq_ops->queue_rqs) { blk_mq_run_dispatch_ops(q, - __blk_mq_flush_plug_list(q, plug)); + __blk_mq_flush_list(q, &plug->mq_list)); if (rq_list_empty(&plug->mq_list)) return; } =20 - blk_mq_run_dispatch_ops(q, - blk_mq_plug_issue_direct(plug)); + blk_mq_run_dispatch_ops(q, blk_mq_issue_direct(&plug->mq_list)); if (rq_list_empty(&plug->mq_list)) return; } =20 do { - blk_mq_dispatch_plug_list(plug, from_schedule); + blk_mq_dispatch_list(&plug->mq_list, from_schedule); } while (!rq_list_empty(&plug->mq_list)); } =20 static void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx, struct list_head *list) diff --git a/block/mq-deadline.c b/block/mq-deadline.c index 754f6b7415cd..2edf1cac06d5 100644 --- a/block/mq-deadline.c +++ b/block/mq-deadline.c @@ -713,11 +713,11 @@ static void dd_insert_request(struct blk_mq_hw_ctx *h= ctx, struct request *rq, list_add_tail(&rq->queuelist, &per_prio->fifo_list[data_dir]); } } =20 /* - * Called from blk_mq_insert_request() or blk_mq_dispatch_plug_list(). + * Called from blk_mq_insert_request() or blk_mq_dispatch_list(). */ static void dd_insert_requests(struct blk_mq_hw_ctx *hctx, struct list_head *list, blk_insert_t flags) { --=20 2.45.2 From nobody Sun Feb 8 05:42:07 2026 Received: from mail-io1-f100.google.com (mail-io1-f100.google.com [209.85.166.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28EC626B953 for ; Wed, 23 Apr 2025 20:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745441497; cv=none; b=sHJOSWy1JQyK7gGV3cABPolheA12IO+fp4xOaegDuU9HHDwyaPs2hZMmUsH03aST3eddbIXRTOsM5POw0hPbDq1k98gUgLsUlvz0zCI0i1KkPcps7K4v6PBfiXION9I02vEreBAcV+N5vCfb8k7LercHbhTfUgBdkEErMvQ2JKE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745441497; c=relaxed/simple; bh=lNtRTij/kdPLKZxepwEn5KKyU0DtZ6R8eX1YGzaUvfc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W5Mlai2crsafqNhVlrG7NweH9SvBGBScBPXkbSYiTyW0NK/oCCdS1A4ebkH7P0dCT0OiKXEjFa/QpOjss+xx2VPLlc0OoDCwiv0Qze/Foj02tMuv+0e4zQl+XTSEAvRh066GNnyNXw8FA9uJdBNl2Slnpd/H72bKv5GaPvhp2qo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=fail smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=StX+oTby; arc=none smtp.client-ip=209.85.166.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="StX+oTby" Received: by mail-io1-f100.google.com with SMTP id ca18e2360f4ac-8640c6163f2so1394139f.3 for ; Wed, 23 Apr 2025 13:51:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1745441494; x=1746046294; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lWHmi7U03uv5Tv+dtowxYZMDQUd28bYLC+apU9ROBaA=; b=StX+oTby8KA4Jk8Ni1M9sEF2VCEyG2iQSo8j8N3iHlWRGWzbJ4vr2Oz36sKsI3rWbc UyOUeyjwVJRV+4RZ/r6X4Q6yiyI8IQN5JHYgUCVfFsD5O7qBJEg+1Y/FXamnJCYXcyl8 zWyyt5IOZ82UaoWVKxLWMNp/ENZ8vzxQ+UwrgnQrLUxiJ/GJ0gDqzuxfiG3jfhF7SPl+ 3Dot9Kxjq5RuiqpIS7UivETxTHVL35u+qcmegA7ZZgKnTu1inrDMEQaW4F2kR+bTPazy Fxa7rNNQC0I6a3vfJ0+YKCErKXNde1xUggIUBUjBlaIENK55GogciW2lrrxjvAEYNwti hDTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745441494; x=1746046294; 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=lWHmi7U03uv5Tv+dtowxYZMDQUd28bYLC+apU9ROBaA=; b=WTOu3NHbUEqmmuPkM6kWb6vAaETXc1p04qqMIrQb/55diGbKyKWE66gSevant3fP1w 4qXnR1Ov4h8WcgE3UnqSQ2Jx8XDcf3Ycep1b5mvqkuV5inzmnTfSZ1/C3ZMxufvP0Dqs 6RzsBMLoAqrtjeKmfLepsvFPePuoPA63P/cv3+QqRjgTdhNZ3gDYg0u09YZdkHhrQz+N pkeV2joQ4euxqMxLSluZQBKCLxFJyX/2Bb7Vfj+OzsCiP9UgUNuPadjUc2MzV4F0365+ VRXgrw+aeBfzRNULtqnNUGygVSzs4050mDQPIuku0Pq+uHB6fPsWijsTWsA73HhUfJpR XbEw== X-Forwarded-Encrypted: i=1; AJvYcCWyI9aKCKLRJD1iyLxEz0nznlZshOiJ+Vknvr7Larp1veSCcl9nLYfd0O5CIDE6oiOOP21RH0QMrBO0wuE=@vger.kernel.org X-Gm-Message-State: AOJu0Yw7/YqlYJb15iIOvu90iqDSBUP2T3CCy70+5Am3QGvsh+5/oBbe xZyTR/83vXjauRWnckyy8k8kV/6HXQ6jKXBf/M4XqUtUGi9qjNOXx4/+xNTTUYQcjqNilNDl8ez 4KDizXsYOPQvFGGNOwR11bNp9uJOc69r4WlvRmGoP/smx4vJ0 X-Gm-Gg: ASbGncshmPHP9/29AM7Xv3v+57huGSSPX22/exy5RVZvTQaj06sPRnd6ypmqH5gIZQJ tNYarAIwau6DgHSNaDnwkl0uED2Nibiv3mCroOMRX3eaWmCxFc0jqcJ/sKDwRxH2J1yzE69LPNZ YBMvaX5X8eP3W018Dq0ylps+gIpehVislWK98hTR8hcWqox0q7bI/BwrlljAhdr7aESK4+dMPQz EoLoONJfp+tgK7xzK4EvdfQOIGiXN2NgQeXd0qyJBY1Lt/AWvXT0zayPt/A0py2S5YZNacl96xr 7Bo5DCPzB5NI44NK90GtUBph+8ZGpw== X-Google-Smtp-Source: AGHT+IHqT55VMq3aAVcdjK3iZb2NqKPkeixuITq/SEY9d+tOugQ7pOMBgq9vEEkQYGym57eRPF+Lu7Z0EKnq X-Received: by 2002:a05:6602:1694:b0:85e:12c1:fe90 with SMTP id ca18e2360f4ac-8644fabb3b2mr13521539f.5.1745441494124; Wed, 23 Apr 2025 13:51:34 -0700 (PDT) Received: from c7-smtp-2023.dev.purestorage.com ([2620:125:9017:12:36:3:5:0]) by smtp-relay.gmail.com with ESMTPS id 8926c6da1cb9f-4f6a393ab9esm483652173.58.2025.04.23.13.51.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Apr 2025 13:51:34 -0700 (PDT) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (dev-csander.dev.purestorage.com [10.7.70.37]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id CA2CA34058D; Wed, 23 Apr 2025 14:51:33 -0600 (MDT) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id C660EE42AD1; Wed, 23 Apr 2025 14:51:33 -0600 (MDT) From: Caleb Sander Mateos To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Caleb Sander Mateos Subject: [PATCH 2/3] block: factor out blk_mq_dispatch_queue_requests() helper Date: Wed, 23 Apr 2025 14:51:26 -0600 Message-ID: <20250423205127.2976981-3-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250423205127.2976981-1-csander@purestorage.com> References: <20250423205127.2976981-1-csander@purestorage.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Factor out the logic from blk_mq_flush_plug_list() that calls ->queue_rqs() with a fallback to ->queue_rq() into a helper function blk_mq_dispatch_queue_requests(). This is in preparation for using this code with other lists of requests. Signed-off-by: Caleb Sander Mateos Reviewed-by: Christoph Hellwig --- block/blk-mq.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index fb514fd41d76..a777cb361ee3 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2834,10 +2834,31 @@ static void __blk_mq_flush_list(struct request_queu= e *q, struct rq_list *rqs) if (blk_queue_quiesced(q)) return; q->mq_ops->queue_rqs(rqs); } =20 +static void blk_mq_dispatch_queue_requests(struct rq_list *rqs, unsigned d= epth) +{ + struct request_queue *q =3D rq_list_peek(rqs)->q; + + trace_block_unplug(q, depth, true); + + /* + * Peek first request and see if we have a ->queue_rqs() hook. + * If we do, we can dispatch the whole list in one go. + * We already know at this point that all requests belong to the + * same queue, caller must ensure that's the case. + */ + if (q->mq_ops->queue_rqs) { + blk_mq_run_dispatch_ops(q, __blk_mq_flush_list(q, rqs)); + if (rq_list_empty(rqs)) + return; + } + + blk_mq_run_dispatch_ops(q, blk_mq_issue_direct(rqs)); +} + static void blk_mq_dispatch_list(struct rq_list *rqs, bool from_sched) { struct blk_mq_hw_ctx *this_hctx =3D NULL; struct blk_mq_ctx *this_ctx =3D NULL; struct rq_list requeue_list =3D {}; @@ -2881,11 +2902,10 @@ static void blk_mq_dispatch_list(struct rq_list *rq= s, bool from_sched) percpu_ref_put(&this_hctx->queue->q_usage_counter); } =20 void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule) { - struct request *rq; unsigned int depth; =20 /* * We may have been called recursively midway through handling * plug->mq_list via a schedule() in the driver's queue_rq() callback. @@ -2897,30 +2917,11 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, = bool from_schedule) return; depth =3D plug->rq_count; plug->rq_count =3D 0; =20 if (!plug->multiple_queues && !plug->has_elevator && !from_schedule) { - struct request_queue *q; - - rq =3D rq_list_peek(&plug->mq_list); - q =3D rq->q; - trace_block_unplug(q, depth, true); - - /* - * Peek first request and see if we have a ->queue_rqs() hook. - * If we do, we can dispatch the whole plug list in one go. We - * already know at this point that all requests belong to the - * same queue, caller must ensure that's the case. - */ - if (q->mq_ops->queue_rqs) { - blk_mq_run_dispatch_ops(q, - __blk_mq_flush_list(q, &plug->mq_list)); - if (rq_list_empty(&plug->mq_list)) - return; - } - - blk_mq_run_dispatch_ops(q, blk_mq_issue_direct(&plug->mq_list)); + blk_mq_dispatch_queue_requests(&plug->mq_list, depth); if (rq_list_empty(&plug->mq_list)) return; } =20 do { --=20 2.45.2 From nobody Sun Feb 8 05:42:07 2026 Received: from mail-io1-f97.google.com (mail-io1-f97.google.com [209.85.166.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B4E726FD83 for ; Wed, 23 Apr 2025 20:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.97 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745441497; cv=none; b=u8CZlI7zi5E77u/HbP9rWsWLCixxNrkhF7PRsLZMLll/H3yc3CG/lykYXr37JwXL8BM3OQsNrTlZaV6qEg9DgVCx1KKLP2SDVKQB6BLu3xMwmzc2CQeSsCF8D8LlbSfIFPLd8QbTVVRibi66jLU7mcLUgdUgQv4hDnfBCszWAqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745441497; c=relaxed/simple; bh=4Q2iPo/tnEZ49XySLTXbJNcXJ7aWlvW/11m4VHSBuh4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nji2OrrxippoBQ5ATGOP4EnGfHBltIqhZC2pvOvz/wgTUJLHnceoabN380dU4JHRa47fk7qKUdASKCywJ4QBrTXIOnKuwzOp2HRcsGWmFcbTE1SaXpSQO5/DR0ipxaPWUpUK80DiFNJcDyjcumNn+1UAe3ENojQETBUlI6s59PQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=fail smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=ZUmoys1F; arc=none smtp.client-ip=209.85.166.97 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="ZUmoys1F" Received: by mail-io1-f97.google.com with SMTP id ca18e2360f4ac-85e14fc7483so1354339f.1 for ; Wed, 23 Apr 2025 13:51:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1745441494; x=1746046294; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SoK4bN+8xfY+ulGAa3XB64iIL6M5dgQU+nAPX6fChJA=; b=ZUmoys1Fg2KUfoxVmJVYB0AD5cWKaYsCl+17yVqSq6OP/Bg8jzITD3ba61bp2di60v IWzGTRrHNxr9DtgoygMj46X/qdrE/wfjfrwNN6ZjADwZIJFQVN/9PjAb8L7h1+l2kvUc 8K0jZqyG5Q2PBzms6030RVfIWi0nEAGEUO664LoZGOrs82XN6DRcEl5lkJNjf3mZmCLB 4Wj3aFAOb62UvDl/Sp11ZrxUG3O65lq5wGBfRPmAhhfliGMOYne3diMPdakxXDKJw6NW 2W5jpxoIQJoeH6gSyScpCDhTLlbWasQzFy5VQYFYLfU1GYn2CvNWmETDLcpVMjbzHV8e y/hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745441494; x=1746046294; 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=SoK4bN+8xfY+ulGAa3XB64iIL6M5dgQU+nAPX6fChJA=; b=U6wwcOq8AT9xzguzaE5PYIkPC/SuhQobhgdGJxdPEH+wNFf4k1HCWvGXXG2Sta1w9i li8vHvYPS0LVztpcQZxBZXtIjBBY+F+PO/tu/C74TKWLppWNGUNPVm0CYmQC4N7ZQyZl 1KXnVZ83OCpkCT0n1TcmQ6m31lSxBwqz9+KLCsy0a4K4RG1x7mGWpgnKUg/GPXolwaUE IAXuYNwT4p11pFhrpubwDAeckYrvJ9icJYpOERuBUk7nPfpjikhAuziUqt4vR+whO8wy /TTt76XvpcszybWnLUyqTRO8MoKZQyyfasiaswMxaf2Z1tQkO7oTb6dWGGN08vyMJgMc zJyA== X-Forwarded-Encrypted: i=1; AJvYcCUimuveLj+vTWo9nw5mEODhyvnsxXhMvww+wWTbxwMBZFSm8PrxdN2wy7T1Ec/vFbSAl8dQ19zZGeVgOZc=@vger.kernel.org X-Gm-Message-State: AOJu0YzpZCtqHZqgMirIKSBlz4XXkjMH5Xi+DDTsWPTwgabiIbVqA705 NuJVu9K/BjJ4HPgDJBnC9ncGyfrseO6htu8h1a5ni2OpvO5ZkaJS3ZJy2uUKtZyCBAu7D+6V5bs OpOmx3mdhtQCyrQgixHNzbwvQtcgf1D7fWwn66E2+yUqc4x2x X-Gm-Gg: ASbGnctPt24zCek55aAvCOHIvbgocfS8fQUj56/nAGTGfzr0Lq/v5bqV8+12Elzxlaa yfKVPSpLlakYbW5CGn/V+4T5Kv4The9DqTEzj7ScQPPOYa5gYMBUmT3gcAkh4/vR2dnXMDnuIhr hj/fk/d9zWj73Ukwuu9bvYpn6uiwA37HZ0DT8tMWRWcU6OYgpsupT41ECTzOUzqkLs2QI3bWfWU xsjavMrl4s2RSFxu5NdJYQJNB4AhcDYAeLhLVe+zyuzaIvqAcCB9+6/MZgCWxTvEnP060mxT/Cy uDa/7J4H1o8+rUVpI/3gv6+tmuSAUg== X-Google-Smtp-Source: AGHT+IFJ1Z7TIe/cw66oWuzP5zk7tdlA5RhAtITdf0i5ke7NN9haVVrLyhsgZl5LKFwJ/C6phPrEpMG+gEZ2 X-Received: by 2002:a05:6602:3f92:b0:85e:5cbc:115 with SMTP id ca18e2360f4ac-8644f97cf29mr13547139f.1.1745441494510; Wed, 23 Apr 2025 13:51:34 -0700 (PDT) Received: from c7-smtp-2023.dev.purestorage.com ([2620:125:9017:12:36:3:5:0]) by smtp-relay.gmail.com with ESMTPS id 8926c6da1cb9f-4f6a37d38e2sm517458173.2.2025.04.23.13.51.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Apr 2025 13:51:34 -0700 (PDT) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (unknown [IPv6:2620:125:9007:640:ffff::418a]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id 30907340159; Wed, 23 Apr 2025 14:51:34 -0600 (MDT) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 2B6FEE428D4; Wed, 23 Apr 2025 14:51:34 -0600 (MDT) From: Caleb Sander Mateos To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Caleb Sander Mateos Subject: [PATCH 3/3] block: avoid hctx spinlock for plug with multiple queues Date: Wed, 23 Apr 2025 14:51:27 -0600 Message-ID: <20250423205127.2976981-4-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250423205127.2976981-1-csander@purestorage.com> References: <20250423205127.2976981-1-csander@purestorage.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" blk_mq_flush_plug_list() has a fast path if all requests in the plug are destined for the same request_queue. It calls ->queue_rqs() with the whole batch of requests, falling back on ->queue_rq() for any requests not handled by ->queue_rqs(). However, if the requests are destined for multiple queues, blk_mq_flush_plug_list() has a slow path that calls blk_mq_dispatch_list() repeatedly to filter the requests by ctx/hctx. Each queue's requests are inserted into the hctx's dispatch list under a spinlock, then __blk_mq_sched_dispatch_requests() takes them out of the dispatch list (taking the spinlock again), and finally blk_mq_dispatch_rq_list() calls ->queue_rq() on each request. Acquiring the hctx spinlock twice and calling ->queue_rq() instead of ->queue_rqs() makes the slow path significantly more expensive. Thus, batching more requests into a single plug (e.g. io_uring_enter syscall) can counterintuitively hurt performance by causing the plug to span multiple queues. We have observed 2-3% of CPU time spent acquiring the hctx spinlock alone on workloads issuing requests to multiple NVMe devices in the same io_uring SQE batches. Add a medium path in blk_mq_flush_plug_list() for plugs that don't have elevators or come from a schedule, but do span multiple queues. Filter the requests by queue and call ->queue_rqs()/->queue_rq() on the list of requests destined to each request_queue. With this change, we no longer see any CPU time spent in _raw_spin_lock from blk_mq_flush_plug_list and throughput increases accordingly. Signed-off-by: Caleb Sander Mateos --- block/blk-mq.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index a777cb361ee3..f820c6c0cb1a 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2834,10 +2834,34 @@ static void __blk_mq_flush_list(struct request_queu= e *q, struct rq_list *rqs) if (blk_queue_quiesced(q)) return; q->mq_ops->queue_rqs(rqs); } =20 +static void blk_mq_extract_queue_requests(struct rq_list *rqs, + struct rq_list *queue_rqs, + unsigned *queue_depth) +{ + struct rq_list matched_rqs =3D {}, unmatched_rqs =3D {}; + struct request *rq =3D rq_list_pop(rqs); + struct request_queue *this_q =3D rq->q; + unsigned depth =3D 1; + + rq_list_add_tail(&matched_rqs, rq); + while ((rq =3D rq_list_pop(rqs))) { + if (rq->q =3D=3D this_q) { + rq_list_add_tail(&matched_rqs, rq); + depth++; + } else { + rq_list_add_tail(&unmatched_rqs, rq); + } + } + + *queue_rqs =3D matched_rqs; + *rqs =3D unmatched_rqs; + *queue_depth =3D depth; +} + static void blk_mq_dispatch_queue_requests(struct rq_list *rqs, unsigned d= epth) { struct request_queue *q =3D rq_list_peek(rqs)->q; =20 trace_block_unplug(q, depth, true); @@ -2900,10 +2924,24 @@ static void blk_mq_dispatch_list(struct rq_list *rq= s, bool from_sched) blk_mq_insert_requests(this_hctx, this_ctx, &list, from_sched); } percpu_ref_put(&this_hctx->queue->q_usage_counter); } =20 +static void blk_mq_dispatch_multiple_queue_requests(struct rq_list *rqs) +{ + do { + struct rq_list queue_rqs; + unsigned depth; + + blk_mq_extract_queue_requests(rqs, &queue_rqs, &depth); + blk_mq_dispatch_queue_requests(&queue_rqs, depth); + while (!rq_list_empty(&queue_rqs)) { + blk_mq_dispatch_list(&queue_rqs, false); + } + } while (!rq_list_empty(rqs)); +} + void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule) { unsigned int depth; =20 /* @@ -2916,11 +2954,16 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, = bool from_schedule) if (plug->rq_count =3D=3D 0) return; depth =3D plug->rq_count; plug->rq_count =3D 0; =20 - if (!plug->multiple_queues && !plug->has_elevator && !from_schedule) { + if (!plug->has_elevator && !from_schedule) { + if (plug->multiple_queues) { + blk_mq_dispatch_multiple_queue_requests(&plug->mq_list); + return; + } + blk_mq_dispatch_queue_requests(&plug->mq_list, depth); if (rq_list_empty(&plug->mq_list)) return; } =20 --=20 2.45.2