From nobody Sat Feb 7 18:20:39 2026 Received: from mail-pl1-f225.google.com (mail-pl1-f225.google.com [209.85.214.225]) (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 6C63C1531E3 for ; Sat, 26 Apr 2025 01:17:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.225 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745630259; cv=none; b=KE55ooZ2IpRYUHECqiTK7R0SP97nF3k0+ZBhTdQhmbiJhl8LNQXjgyFt+A2Ks2zLsZr02m/hi+jG8CN30Y1T5TUZQKcUCH95Zu8zxpqvpp5MP+Qg0T2pSEWTA/qyXoWrYNgHd5MlmXPUuvVNf1ppJomao4jh04G8ZUWQnpAO9d4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745630259; c=relaxed/simple; bh=vDrHtxaXCASrQzRkEIF0GNIz5C0/SSp+lBfDNtlXLYU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O84YY5q2IlhvQhoaUctutURtmnNc4YUsJf8Dg9egLhzbOqZWR8Hy+vrEt5lJcir/BJur/2TCFd4Ou9XqXP6r7FOgEHo7Fp/WXn6mKHhVbpiQhz2I5AH/s78ouEkDe12EZQ2NZOF8w9xBODK8pZ8BiaGLGryptm8/Kz4juE7wyMk= 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=AAdmAtym; arc=none smtp.client-ip=209.85.214.225 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="AAdmAtym" Received: by mail-pl1-f225.google.com with SMTP id d9443c01a7336-227e29b6c55so4935045ad.1 for ; Fri, 25 Apr 2025 18:17:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1745630257; x=1746235057; 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=kn7WNOBSA3+MlrBrNQ2tCaRe/xJOjXsGpS6QMvkVlSs=; b=AAdmAtymMYT6RkWIspfg4jaU79dleZrlXVaMBJa+7U4dgr5QWxWwYs8aLFjxWzlx2P 7TxumkYglU2s+i5RV519Te73tJ1uMVPgqWLZaZTIs8Gi6x/7ZIqjsdz2Y8rDP2qVu5r0 7y++kPXlXcnxCSrL1h/pxuqVnrcz4epU7NBRAFghUxIeiq5oK1jcFDsc/zVznSDD4pjl jOjnjsiTLkhuoR8RrtvzDwM4lSK8E095EDywwIWOmkGQPXMap3BYbTWdC6Q/GcpgGpqk 5rsjWLfH7bLl5zbpjKB68paz9S07n72ZzU1LGy3Zj6+IRhzRPLC7mIdOEtaZyh6tEgCz Hhkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745630257; x=1746235057; 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=kn7WNOBSA3+MlrBrNQ2tCaRe/xJOjXsGpS6QMvkVlSs=; b=gJIhCI+yUZKOwzA9MDkYkUDJLr67qvat72DhGWvEylwQMjE/XjWyVmbR2ZMZU2xMBd /wipLRjvxP9xdDiDlqhm9fWtEIJpn0UNs7pGnMKEk80pbdCn+kKaIn1S448aSyHeI0E4 /5s1ME4rnlTCdB7l6f/QiKJTpjg6C3lBcOOyAl/++5S3bR/ajQjkQUN5h71de+BgaVGl ndGKWlIrxGBk85IdATH0pnOoQ/5TAzXKTvvwBNMKLqrdeBxHfwKsdqbJmXs5tVcGBEzk I9DyYtUzVKmkyOHMXL5DnKIgw4sA1nDIEZWojxaWMlk3MmSJhYoCPDMHFguAEJW6JHIO 8D5A== X-Forwarded-Encrypted: i=1; AJvYcCX1LuUoBiEoL7yuAtEFT1P1CQmv+ggo/K5gzQwpe2YLpYmtD42VGpqn9pFmgiPWmbC7EepO8Fv0BF5OKxU=@vger.kernel.org X-Gm-Message-State: AOJu0YyXKjHiTEBwoUnNHS/p6hNNArF2vkbX0dGBOyhmBloCw2Tm99Ra eksapHAo9ykPiogQ1S/04dX1wKuTScu4BZlqkYd+7XuiunVUaBvcpkAdFgqdS+qcEM62FdA7Um0 7C0Dskp9iD0vOUCWogI4myIbxAgoaZy0w X-Gm-Gg: ASbGnctkgFmUD7RRcyWmg4Dl3jta+Si0sMd3fhCAMGAfT9g36/34tSq493+hFodIGbx Kw0gr94so/bbGZVe1iULhke4H562RtzM93+Sw6zF9ego1YqYmT5FMUFr2uB+oVfoCFOqT+cCoGA 7NAq7Z8yrsIO2NaEyXa5GfEUg1jWN+CENm0OpDOCYAwzH04odUuQ5VysPO3MUS6DS+SvXmz+tpj b10iJ7ieLkrtgVaXZKGYhla5GDp81Ub847amCI4lyEB/B3JEFs7rEnF/UidGu8UCJlHZnr5GVJs lCcVyFxlbuQZTMkMXTQ4/5sfxun9t9PmVu1uwaj2FGGP X-Google-Smtp-Source: AGHT+IGF8OjXCTgKiDS6URxBaFTTypnMe621FigXusTuihJwufzzZI1acv3nPcxmOKS5nrg/1xh6Agf7y3VF X-Received: by 2002:a17:902:dac2:b0:21f:356:758f with SMTP id d9443c01a7336-22dbf5df830mr24444435ad.3.1745630256635; Fri, 25 Apr 2025 18:17:36 -0700 (PDT) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.129]) by smtp-relay.gmail.com with ESMTPS id d9443c01a7336-22db4df11b8sm2187395ad.49.2025.04.25.18.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Apr 2025 18:17:36 -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 0B056340572; Fri, 25 Apr 2025 19:17:36 -0600 (MDT) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id AA6C4E41BE9; Fri, 25 Apr 2025 19:17:35 -0600 (MDT) From: Caleb Sander Mateos To: Jens Axboe Cc: Christoph Hellwig , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Caleb Sander Mateos , Christoph Hellwig Subject: [PATCH v2 1/3] block: take rq_list instead of plug in dispatch functions Date: Fri, 25 Apr 2025 19:17:26 -0600 Message-ID: <20250426011728.4189119-2-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250426011728.4189119-1-csander@purestorage.com> References: <20250426011728.4189119-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 Sat Feb 7 18:20:39 2026 Received: from mail-ot1-f98.google.com (mail-ot1-f98.google.com [209.85.210.98]) (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 D95EA19AD89 for ; Sat, 26 Apr 2025 01:17:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.98 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745630259; cv=none; b=BJHUHcnUvzlWsvGweOr1Td+EL7SLby0mKVqPCYBFxbTkc0mXzYg7gBcdpx29tL/q/B/oYX4RrEpoaQTN74+uD0FCzPNhbiIuERY/ofxFDu70c5cAlb9uNM9QRW07BHnQ76/YTNLCsUZ6GtLVOcua2+BMYb1yfPLYWZe4t30VGcQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745630259; c=relaxed/simple; bh=7Gq3wwrmMHKBA3zsEW0C8C//gz0mlIzt82TbCLdxWyo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MUeZKX3SYdPjKcwGHkaj538057Io2Ji/dlkhDaMsZsZ+dLhQtwcqqP4Jp5/awrJRT9dscyRfds9CKXaGLOTRDUXYWAeldBn4qtgVxvKk6n7G4vrDzYO4foadPNcUEuoLP0oOCGxpuNLv5GRar1l5Mh+x9iH9RUfpJcfuXsFaQzw= 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=AMFMwdci; arc=none smtp.client-ip=209.85.210.98 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="AMFMwdci" Received: by mail-ot1-f98.google.com with SMTP id 46e09a7af769-72b93770ba0so267770a34.2 for ; Fri, 25 Apr 2025 18:17:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1745630257; x=1746235057; 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=IQQLXKvkPDoUVqHziv2SJ8rfj54eLgcHoYOfmOv7bJ0=; b=AMFMwdci63SZVZ7BjCIRDJNawW9tC+bZNpiaTi175otDWltGVr28/VLC5ejB99d1Hb 0OLTnfJgdn2Zew/MYrswOTLq9JxEnCe3H0wHg2I1Q8JFEjkkqBfTlHmcmFCnXQBN711x WA0iemEddS7GCKeM4bX2Wn3SRaQNW4zTxw9ETfZ6eNqoIfpeLhERxsxk4w1QjXoDQQfr 2yKzl7/Lqx2cOXW98jI4QWJ10ESDoDX3xXuUId/ydMgKK3CF73tVVgis2fw8hZX1X5ua kBHFMkMo2/P7LpacNRn9qKnpu+UYy1HxtiGrClGnSL+0tQ5zKZsDHB3Dgvbos7dveuUx GUvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745630257; x=1746235057; 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=IQQLXKvkPDoUVqHziv2SJ8rfj54eLgcHoYOfmOv7bJ0=; b=CZ60a+5z5rnVcdNZrWjxdOLbtJaEu+71CvfwTLb1fPktKLs+vXQYbUhB/5dnJekHQu PnCl7KU7HviCOMeUfJW46hbP1XtH2Ml+f4Th8od+R6qA5/HCTPUWQ4+Aulm0Z/YDpbaE xI8rRCHOMDYLEFFtD8xoc93wzClGlrDFUCCoDqjjBbsy4/4S3CCk2pYK6u5kC1E6+vzb Rnwru94C0MqaLPerz0osHjBHu7js5ZxazMcRpuG1JcVBGEWPeLAi3TUpOhZgAiqwrHY2 +y6GPzJ3ghg3rLsnEA8/WeFx7M2WIxECcOjBuWB7yKWaamLvzzRdqEBEy/3IhOZTJ6Si 4VlA== X-Forwarded-Encrypted: i=1; AJvYcCUMUd2PYwQe0hXC0kKoAMVKIUCdJUnxxf4oQUh8h3e88QFOOegKBk8mtOCzGF5uzEwKMwSxgbn1845k1Wo=@vger.kernel.org X-Gm-Message-State: AOJu0YxCOPC/q6+jfSllMBwMNPilv0B+pfShLMId9jbpFYFZAq1LL4Fo jnTXPLtw3QMkJNnr3FFL7C2R4szGFfcrjXQeDAicpOgd9mrmy/+kN6m1UkN/Xhckl5QezLxDXpX BJmHFbB8oslOjAtyDZQQA6W9CoqFd1Uex X-Gm-Gg: ASbGncvdJhsyfgEQdwewxjj0umT7h2MH3JyjB6yfMr7wJNvvWatXfCDgTH/Y35cq8xV ypmg7tICBX6dLnMZ0QlBaie/Ioh1lfv6Rfs/gy+10Xm+iaWMKfFHZ9sTd7tYtWOcwCrJvu6gBpp wOLoULv0zBh9mnPZqR+FqeOjym1MPcGDFot9RmV4A8JOhRygSwQdvzckGC63FV3l7EdZhNqcFCR pejq5FYEoE8HRErEf1by7al2K2FWMb9Ua5AQ/7U0wwlMCMr1qjgLwN92v4dD7mY0PbD+SlCFOJK pL50uMXNnfLaZB/3AF3ztvAEosYHme0KXPHspzrr+S/D X-Google-Smtp-Source: AGHT+IHXP7V6kKd4jmPTmsjz5FjMWXaru01e0xXLDD7oOeyxuDoFtEBZnBnDtZ6TKjJSid7gKI4g+NNRbWqg X-Received: by 2002:a05:6871:7420:b0:296:9146:f455 with SMTP id 586e51a60fabf-2d99d8602eamr828101fac.7.1745630256855; Fri, 25 Apr 2025 18:17:36 -0700 (PDT) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.128]) by smtp-relay.gmail.com with ESMTPS id 586e51a60fabf-2d9756b17b9sm174106fac.22.2025.04.25.18.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Apr 2025 18:17:36 -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 25DC2340615; Fri, 25 Apr 2025 19:17:36 -0600 (MDT) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 2398FE41BE9; Fri, 25 Apr 2025 19:17:36 -0600 (MDT) From: Caleb Sander Mateos To: Jens Axboe Cc: Christoph Hellwig , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Caleb Sander Mateos , Christoph Hellwig Subject: [PATCH v2 2/3] block: factor out blk_mq_dispatch_queue_requests() helper Date: Fri, 25 Apr 2025 19:17:27 -0600 Message-ID: <20250426011728.4189119-3-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250426011728.4189119-1-csander@purestorage.com> References: <20250426011728.4189119-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 Sat Feb 7 18:20:39 2026 Received: from mail-pl1-f227.google.com (mail-pl1-f227.google.com [209.85.214.227]) (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 0E1CA19CC0A for ; Sat, 26 Apr 2025 01:17:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.227 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745630259; cv=none; b=hZbLpnyZAXe1Uvm70wxnqEqDbnj42MF94U7a/XpqA0wAFqVZvpjigtdyQAEVHIR/vEYuNHYoVtVI1P+s/Pn72D7f8Y4ryQ3eFgGHNaqyGKAqwjAjoVfd1maWC/TBl+GLeM5s9NI97kKB6tkvP8g0kr4wu8YL72NFolkHReoopKo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745630259; c=relaxed/simple; bh=QQIf5dt5C4yKuca2TMD3A9dUB9RNF6HldH2GRSGErzo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pGH3ZnicZQsOFatYh7I8RHq97lCe/935X+O2W51P/FSEwE8ds5zKMee4iEMdpE0hvE+vRpzewq3U4WORmHvAbVIw2v03VEBNH2I760gW8XefBV55Lp7Gzw3+Myg3V+gVX3kmAzMhhUEQdstAtJwVRhYUTBWwKqJnI0jC7nwR4gE= 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=Tzdokmk2; arc=none smtp.client-ip=209.85.214.227 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="Tzdokmk2" Received: by mail-pl1-f227.google.com with SMTP id d9443c01a7336-225887c7265so4907325ad.0 for ; Fri, 25 Apr 2025 18:17:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1745630257; x=1746235057; 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=DDOGgOaE862gw8IvAer1t8eUgpK99QL0J22I9Usktk8=; b=Tzdokmk2fZmXkfk6/EzQojCGgAOfMg8h3Tm1vt8RF/fM0rByjpYuJUEV3gnvACUUUX coyTZqPQ1tHL+beoTQrpB6hjX+0+fV/koRScAKiXM4d4coR+EdDB+Q2GhzLNY5N3u5Xz w6Ruzx5IHYZykWLZx2IaBi6En3JXjk6svDVsEs45HlFznzDtR7VPg6gex1hU9jghQzFi TF1jy0q6O8A8sr2dEyGfYiEL0SlbB1wPQENMKTsQgdtUMFANPX/93gAUHm0S4QNn3Rjf QD20+atL7380cicBAeK0QbnNnpNReyeH/jntmh7MuWokLXw3MRsI5NCcp94huAHNpog8 8taw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745630257; x=1746235057; 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=DDOGgOaE862gw8IvAer1t8eUgpK99QL0J22I9Usktk8=; b=YUadWE2TkkgrSaMFzibt/Cv11z9Obx8hc/bKGb2QkN/2RSwfriLOjQjccsOEWkjF4a 4RfaEYU9OPkWHYwxUxHS5UnbO3STbbncvDhPSkg5cN1oFn9wOqGA2SwmnQ7yUKSgqpxK CqdqQvHdS8WNCVzSJnkXuY3AISeyUFuY23FHCTsSsZDkRRd5rZA03fIaAwtted4cWJ+v qMOIDPS0H1etER9VWKi0IzejY/z7TgcInr9rQBZif2WaKEYIBl8gXd0HLxghrdM3344M y7CA97GLEld/7TuhiJYl8IXJU3D72tx6eIuo4Oc2h9bsPsCZ7EGMytttzgjsU86XWMN4 iCRQ== X-Forwarded-Encrypted: i=1; AJvYcCWsEKIk/cfCb54rPIXStdmzXzaZRvPEAxh85aClSN6N3P45pWXCBOr7E08bVOAI57pkD8q62wsmqXdkkmc=@vger.kernel.org X-Gm-Message-State: AOJu0Yx14yhWzYBYztnO3+G9SHNKpbJ0THPV6K2kR9Vdb5v/0iJa4uPQ BjH4iLKdqJMLnarr87YM7SQWybPB5onD3kJXAwb9QhsEwI20ZsF2dRUOgECjgXf43XlxMasmoR3 SaTF75lpctjnGgDY/BsOzyurYsYcLkntG X-Gm-Gg: ASbGncuhrxnXuRgA46nRzB8oiSVkXixIYgSM9FT3+B9jl9+TQrQPQBebuZsDSI36wko HKhU5ijPGec8HmWiFLinmflcMezYDpovP3YXP8fDkzxfQAS6C73YJ/Wj8TVlAurUgi0LaPljX7F 4U3E44YSlzfMkiJRg/S1F2hVUQbf4Xf+RQqLQWU2Ibsk/lh3/vCf3tm4kRj+1Ns0R8pmtX2D3UZ ZNWDa3f1y6JZNHozmlWv7rnunguAfsoIdy8xftA1dJzfBqQZ8eEmlVgxTg2jQitHQSEmTemJby6 dgPgCzk8sFO4lPaE7wrYw7UBMZmH7DiK3f1qAo91HBEG X-Google-Smtp-Source: AGHT+IHIcd1tqHI1KIxaEgnbnwUpZRHCpkBOTlnpeQ8YbWZyA6eMovZB4O6abyU4KRtb1kWf6EN+do9p179s X-Received: by 2002:a17:90b:4a4e:b0:301:ba2b:3bc6 with SMTP id 98e67ed59e1d1-309f7ec261bmr2333968a91.7.1745630257186; Fri, 25 Apr 2025 18:17:37 -0700 (PDT) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.129]) by smtp-relay.gmail.com with ESMTPS id 98e67ed59e1d1-309f7820838sm150265a91.12.2025.04.25.18.17.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Apr 2025 18:17:37 -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 96A1F3402A4; Fri, 25 Apr 2025 19:17:36 -0600 (MDT) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 94516E41BE9; Fri, 25 Apr 2025 19:17:36 -0600 (MDT) From: Caleb Sander Mateos To: Jens Axboe Cc: Christoph Hellwig , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Caleb Sander Mateos Subject: [PATCH v2 3/3] block: avoid hctx spinlock for plug with multiple queues Date: Fri, 25 Apr 2025 19:17:28 -0600 Message-ID: <20250426011728.4189119-4-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250426011728.4189119-1-csander@purestorage.com> References: <20250426011728.4189119-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 Reviewed-by: Christoph Hellwig --- block/blk-mq.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index a777cb361ee3..d39e144863da 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2834,10 +2834,39 @@ 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 unsigned blk_mq_extract_queue_requests(struct rq_list *rqs, + struct rq_list *queue_rqs) +{ + struct request *rq =3D rq_list_pop(rqs); + struct request_queue *this_q =3D rq->q; + struct request **prev =3D &rqs->head; + struct rq_list matched_rqs =3D {}; + struct request *last =3D NULL; + unsigned depth =3D 1; + + rq_list_add_tail(&matched_rqs, rq); + while ((rq =3D *prev)) { + if (rq->q =3D=3D this_q) { + /* move rq from rqs to matched_rqs */ + *prev =3D rq->rq_next; + rq_list_add_tail(&matched_rqs, rq); + depth++; + } else { + /* leave rq in rqs */ + prev =3D &rq->rq_next; + last =3D rq; + } + } + + rqs->tail =3D last; + *queue_rqs =3D matched_rqs; + return 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 +2929,23 @@ 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; + =09 + depth =3D blk_mq_extract_queue_requests(rqs, &queue_rqs); + 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 +2958,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