From nobody Fri Dec 19 10:39:40 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 71E9422F16E; Fri, 10 Oct 2025 02:28:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760063303; cv=none; b=fY6XFwO2b3ykHdJMoNdy2yzbsKaugKk2gc4SMjyraX1wpHF1weWh+OhKipRoBHUmP6Qp18MD1mny6jFXGI3OQdNoEGN1BgZbepJjJF8iie/xMyff97A3VnvA8fjf9hrSPN2ZNglOVucvw7EkDHaSV1b9tgVoClyQ95Hfzn+mKXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760063303; c=relaxed/simple; bh=LMSQiR7cO+DiIh19yzFcgQbHO5h0AHO8veD+ASqXLoo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GYBy1EujRo0ToREdvAPPvC0ZEF762KkTAOjS2VdecE6k0ZLFnyX13BkEKJVdiyBBVqOBdAr8Qe4VTavL/BJmmJVmbMsObJb0GaDyfA8OZ5GqC1AD2YbGxJodNsACiDFRD1gvUod2TZ8++HwOkCSiB5Ws9HkqMoDnje1ZdM/sdMI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oFIQ6Vp7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oFIQ6Vp7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88E7FC4CEE7; Fri, 10 Oct 2025 02:28:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760063303; bh=LMSQiR7cO+DiIh19yzFcgQbHO5h0AHO8veD+ASqXLoo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oFIQ6Vp7+XFz2ytP5BVrOISQqm/zQl5woURl81iYlt/gNlPMXIwlgLVwWorOqQ6Z5 jiXmESqvSuMZJTYlq0bFsns+qEkUty7PV8CpeZI+h1ZZtIctnTXqnYjuUw/O14lZMv oB2h+9j4IQZ0SDFdPCxkxn9nBDUIVT3jCbra98Vifqgj7Igw4pfO/T+TzGzoTPmjKI hurdQ05sJXcGHgWSx9WkM4p8Jm/IezIE7x4nVPJP8jWURDqOBshay9Petztj50QMoA 4XzQaqgTpdSTX8s2a/vDaxNL/TJKyDQ7prFno8EdSOICL92gqhAaxPfsGNLt2mQWHM keSTuCw5bTxkw== From: Yu Kuai To: axboe@kernel.dk, bvanassche@acm.org, nilay@linux.ibm.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, yangerkun@huawei.com, johnny.chenyi@huawei.com Subject: [PATCH v3 1/7] block: convert nr_requests to unsigned int Date: Fri, 10 Oct 2025 10:28:03 +0800 Message-ID: <20251010022812.2985286-2-yukuai@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251010022812.2985286-1-yukuai@kernel.org> References: <20251010022812.2985286-1-yukuai@kernel.org> 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" From: Yu Kuai This value represents the number of requests for elevator tags, or drivers tags if elevator is none. The max value for elevator tags is 2048, and in drivers at most 16 bits is used for tag. Signed-off-by: Yu Kuai Reviewed-by: Nilay Shroff --- include/linux/blkdev.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 066e5309bd45..02c006fb94c5 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -541,7 +541,7 @@ struct request_queue { /* * queue settings */ - unsigned long nr_requests; /* Max # of requests */ + unsigned int nr_requests; /* Max # of requests */ =20 #ifdef CONFIG_BLK_INLINE_ENCRYPTION struct blk_crypto_profile *crypto_profile; --=20 2.51.0 From nobody Fri Dec 19 10:39:40 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F28FC2441A0; Fri, 10 Oct 2025 02:28:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760063306; cv=none; b=Kxr5DAhC5rrXDBwMFzdH8/iPzsYRdcBw/qClJVq6H0mA2YUBxxVPibK0df/lvcgwrcjir5ihdE4bl2pECDjPETQ5KsaxVZHzXzXsdSx3sKht//cxTNFW/oLriDBd7p4fwAG78teBhkoZJOJQmM5SqpAgUiSv8G68PaPVamvSXvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760063306; c=relaxed/simple; bh=kTfc8t+GGw7EWJ9kYxVrpISeWOIQnou3+v5NU3S3DiE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o+OyCXdTXOkaOTTCypVfm4YOk4j/CSvkW1MpgNQBqfRoyJzPOgycMBso+PeXFKdvaqP4lf7lBdbUVq7Wf5/aErfJ47KEIZ3O+dWc2CH4BjnE0GA1hdSti9WFdKx933vYW2t0ulxsGHE0MZbr+YylWZT8xAGHYdwmnIG8/ENXL2I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=d6HMnPC5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="d6HMnPC5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A89EC4CEF5; Fri, 10 Oct 2025 02:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760063305; bh=kTfc8t+GGw7EWJ9kYxVrpISeWOIQnou3+v5NU3S3DiE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d6HMnPC5p9MLGcpFyovZj8aK0MAYR1MLC0/F3AaQI9kozmz9pJyjWZLB+AmnaFgKU cP8OpFOX3VenuH7OIXaq6D6J++bAtgQchG9ZoZZ8OxqcV1j1hLS/QilMHA3zy2fpQj E0fkIkbnlS4rV1sTvVmTg25Ydazz0ITyQE4tXrKulH8KYhU5y7nE37B21LfGWkMeyO k6o9kFSFzzAwCs4yVD+mlIBBxmKgjEoe0hlqr9iZx7Fx4mTmFm4pX2y1LKDlxtmCI+ gPljh8W/0fyXtPTl6dGDYbk+3nt/zxaFLA0beWvIEJL4+pFQGWM0+gAi6D5uhUDzBg 4Jjs1ezwcT6OQ== From: Yu Kuai To: axboe@kernel.dk, bvanassche@acm.org, nilay@linux.ibm.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, yangerkun@huawei.com, johnny.chenyi@huawei.com Subject: [PATCH v3 2/7] blk-mq-sched: unify elevators checking for async requests Date: Fri, 10 Oct 2025 10:28:04 +0800 Message-ID: <20251010022812.2985286-3-yukuai@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251010022812.2985286-1-yukuai@kernel.org> References: <20251010022812.2985286-1-yukuai@kernel.org> 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" From: Yu Kuai bfq and mq-deadline consider sync writes as async requests and only resver tags for sync reads by async_depth, however, kyber doesn't consider sync writes as async requests for now. Consider the case there are lots of dirty pages, and user use fsync to flush dirty pages. In this case sched_tags can be exhausted by sync writes and sync reads can stuck waiting for tag. Hence let kyber follow what mq-deadline and bfq did, and unify async requests checking for all elevators. Signed-off-by: Yu Kuai Reviewed-by: Nilay Shroff --- block/bfq-iosched.c | 2 +- block/blk-mq-sched.h | 5 +++++ block/kyber-iosched.c | 2 +- block/mq-deadline.c | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index 4a8d3d96bfe4..63452e791f98 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -697,7 +697,7 @@ static void bfq_limit_depth(blk_opf_t opf, struct blk_m= q_alloc_data *data) unsigned int limit, act_idx; =20 /* Sync reads have full depth available */ - if (op_is_sync(opf) && !op_is_write(opf)) + if (blk_mq_sched_sync_request(opf)) limit =3D data->q->nr_requests; else limit =3D bfqd->async_depths[!!bfqd->wr_busy_queues][op_is_sync(opf)]; diff --git a/block/blk-mq-sched.h b/block/blk-mq-sched.h index 8e21a6b1415d..ae747f9053c7 100644 --- a/block/blk-mq-sched.h +++ b/block/blk-mq-sched.h @@ -103,4 +103,9 @@ static inline void blk_mq_set_min_shallow_depth(struct = request_queue *q, depth); } =20 +static inline bool blk_mq_sched_sync_request(blk_opf_t opf) +{ + return op_is_sync(opf) && !op_is_write(opf); +} + #endif diff --git a/block/kyber-iosched.c b/block/kyber-iosched.c index 18efd6ef2a2b..cf243a457175 100644 --- a/block/kyber-iosched.c +++ b/block/kyber-iosched.c @@ -544,7 +544,7 @@ static void kyber_limit_depth(blk_opf_t opf, struct blk= _mq_alloc_data *data) * We use the scheduler tags as per-hardware queue queueing tokens. * Async requests can be limited at this stage. */ - if (!op_is_sync(opf)) { + if (!blk_mq_sched_sync_request(opf)) { struct kyber_queue_data *kqd =3D data->q->elevator->elevator_data; =20 data->shallow_depth =3D kqd->async_depth; diff --git a/block/mq-deadline.c b/block/mq-deadline.c index 3e741d33142d..592dd853f6e5 100644 --- a/block/mq-deadline.c +++ b/block/mq-deadline.c @@ -492,7 +492,7 @@ static void dd_limit_depth(blk_opf_t opf, struct blk_mq= _alloc_data *data) struct deadline_data *dd =3D data->q->elevator->elevator_data; =20 /* Do not throttle synchronous reads. */ - if (op_is_sync(opf) && !op_is_write(opf)) + if (blk_mq_sched_sync_request(opf)) return; =20 /* --=20 2.51.0 From nobody Fri Dec 19 10:39:40 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 06CED239E75; Fri, 10 Oct 2025 02:28:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760063310; cv=none; b=N/8LVQHXqXDGur2FvX+58LZJfGYRWGK49AGSrvznpSgr0mGkmnCkax56MYP3LSk9ez4RMQNL+vsFsM9C8VCxFFP6NhBPPin7nEzSc/IdPui2r1Y0knESimKnAPDIhWQp8wbSqEukXrjZcMfCXtL6C3sKbfAjCLO0MwIBSif9pCE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760063310; c=relaxed/simple; bh=APAI+hF//ptD6OlrXToB8nH7awX2OzL6LZOrayJYBKQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EI2JjHDMA0YlLfiUwnSt2GX/fW+3pJErzbv9T6qIOgPw/uNLaWYMcorJqUHq3xrBh8EcrgUEglWXGNzzolVWqAZNvYSNFHJiQYjDNDLJmVKMtNrLu/Th9U/BRsTDrwddIl5WLWARbYh4Zo9htOr8z77nPMAAlOzkvBoq0zTj8z4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fY8RhBve; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fY8RhBve" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1D8DC4CEF7; Fri, 10 Oct 2025 02:28:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760063309; bh=APAI+hF//ptD6OlrXToB8nH7awX2OzL6LZOrayJYBKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fY8RhBvegqabJJzbUGHp771pHbti7dSl5BcCECxCx6Uf/6tYT607K4M5/bd64C67a bT6EadH+lMibQYyRvkYNoab1cwNZoSDYl0+Tu3J1eT75QLjDD7r08jdG/em/kM0MY+ rndxUaKpiNmUspnE3j6fxSoFuOabCkvDjBWay3ElOSR0eLd1gqBU9nuXUopnNky/s8 m5TMMjxuJDGWyZkLVdcuEyiARCiNCGTiUO29AsbrjnOxh3MRCEJqB2Gm9n79rYGqfD FqybQJYvtZ3Zefvr23HCW7qb2jismNmIZCCPACWFLsTEgMyBm2ap84gAlyuPVszvpA Bnxc5UGN0K2Pg== From: Yu Kuai To: axboe@kernel.dk, bvanassche@acm.org, nilay@linux.ibm.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, yangerkun@huawei.com, johnny.chenyi@huawei.com Subject: [PATCH v3 3/7] blk-mq: add a new queue sysfs attribute async_depth Date: Fri, 10 Oct 2025 10:28:05 +0800 Message-ID: <20251010022812.2985286-4-yukuai@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251010022812.2985286-1-yukuai@kernel.org> References: <20251010022812.2985286-1-yukuai@kernel.org> 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" From: Yu Kuai Add a new field async_depth to request_queue and related APIs, this is currently not used, following patches will convert elevators to use this instead of internal async_depth. Also factor out a helper blk_mq_limit_depth() to make code cleaner. Signed-off-by: Yu Kuai --- block/blk-core.c | 1 + block/blk-mq.c | 64 +++++++++++++++++++++++++----------------- block/blk-sysfs.c | 42 +++++++++++++++++++++++++++ block/elevator.c | 1 + include/linux/blkdev.h | 1 + 5 files changed, 84 insertions(+), 25 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index dd39ff651095..76df70cfc103 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -463,6 +463,7 @@ struct request_queue *blk_alloc_queue(struct queue_limi= ts *lim, int node_id) fs_reclaim_release(GFP_KERNEL); =20 q->nr_requests =3D BLKDEV_DEFAULT_RQ; + q->async_depth =3D BLKDEV_DEFAULT_RQ; =20 return q; =20 diff --git a/block/blk-mq.c b/block/blk-mq.c index 09f579414161..16b335723610 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -491,6 +491,38 @@ __blk_mq_alloc_requests_batch(struct blk_mq_alloc_data= *data) return rq_list_pop(data->cached_rqs); } =20 +static void blk_mq_limit_depth(struct blk_mq_alloc_data *data) +{ + struct elevator_mq_ops *ops; + + /* If elevator is none, don't limit requests */ + if (!data->q->elevator) { + blk_mq_tag_busy(data->hctx); + return; + } + + data->rq_flags |=3D RQF_SCHED_TAGS; + + /* + * Flush/passthrough requests are special and go directly to the + * dispatch list, they don't have limit. + */ + if ((data->cmd_flags & REQ_OP_MASK) =3D=3D REQ_OP_FLUSH || + blk_op_is_passthrough(data->cmd_flags)) + return; + + WARN_ON_ONCE(data->flags & BLK_MQ_REQ_RESERVED); + data->rq_flags |=3D RQF_USE_SCHED; + + /* + * By default, sync requests have no limit, and async requests is + * limited to async_depth. + */ + ops =3D &data->q->elevator->type->ops; + if (ops->limit_depth) + ops->limit_depth(data->cmd_flags, data); +} + static struct request *__blk_mq_alloc_requests(struct blk_mq_alloc_data *d= ata) { struct request_queue *q =3D data->q; @@ -509,31 +541,7 @@ static struct request *__blk_mq_alloc_requests(struct = blk_mq_alloc_data *data) data->ctx =3D blk_mq_get_ctx(q); data->hctx =3D blk_mq_map_queue(data->cmd_flags, data->ctx); =20 - if (q->elevator) { - /* - * All requests use scheduler tags when an I/O scheduler is - * enabled for the queue. - */ - data->rq_flags |=3D RQF_SCHED_TAGS; - - /* - * Flush/passthrough requests are special and go directly to the - * dispatch list. - */ - if ((data->cmd_flags & REQ_OP_MASK) !=3D REQ_OP_FLUSH && - !blk_op_is_passthrough(data->cmd_flags)) { - struct elevator_mq_ops *ops =3D &q->elevator->type->ops; - - WARN_ON_ONCE(data->flags & BLK_MQ_REQ_RESERVED); - - data->rq_flags |=3D RQF_USE_SCHED; - if (ops->limit_depth) - ops->limit_depth(data->cmd_flags, data); - } - } else { - blk_mq_tag_busy(data->hctx); - } - + blk_mq_limit_depth(data); if (data->flags & BLK_MQ_REQ_RESERVED) data->rq_flags |=3D RQF_RESV; =20 @@ -4605,6 +4613,7 @@ int blk_mq_init_allocated_queue(struct blk_mq_tag_set= *set, spin_lock_init(&q->requeue_lock); =20 q->nr_requests =3D set->queue_depth; + q->async_depth =3D set->queue_depth; =20 blk_mq_init_cpu_queues(q, set->nr_hw_queues); blk_mq_map_swqueue(q); @@ -4971,6 +4980,11 @@ struct elevator_tags *blk_mq_update_nr_requests(stru= ct request_queue *q, q->elevator->et =3D et; } =20 + /* + * Preserve relative value, both nr and async_depth are at most 16 bit + * value, no need to worry about overflow. + */ + q->async_depth =3D max(q->async_depth * nr / q->nr_requests, 1); q->nr_requests =3D nr; if (q->elevator && q->elevator->type->ops.depth_updated) q->elevator->type->ops.depth_updated(q); diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 76c47fe9b8d6..18ef3bbb34e3 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -127,6 +127,46 @@ queue_requests_store(struct gendisk *disk, const char = *page, size_t count) return ret; } =20 +static ssize_t queue_async_depth_show(struct gendisk *disk, char *page) +{ + guard(mutex)(&disk->queue->elevator_lock); + + return queue_var_show(disk->queue->async_depth, page); +} + +static ssize_t +queue_async_depth_store(struct gendisk *disk, const char *page, size_t cou= nt) +{ + struct request_queue *q =3D disk->queue; + unsigned int memflags; + unsigned long nr; + int ret; + + if (!queue_is_mq(q)) + return -EINVAL; + + ret =3D queue_var_store(&nr, page, count); + if (ret < 0) + return ret; + + if (nr =3D=3D 0) + return -EINVAL; + + memflags =3D blk_mq_freeze_queue(q); + scoped_guard(mutex, &q->elevator_lock) { + if (q->elevator) { + q->async_depth =3D min(q->nr_requests, nr); + if (q->elevator->type->ops.depth_updated) + q->elevator->type->ops.depth_updated(q); + } else { + ret =3D -EINVAL; + } + } + blk_mq_unfreeze_queue(q, memflags); + + return ret; +} + static ssize_t queue_ra_show(struct gendisk *disk, char *page) { ssize_t ret; @@ -542,6 +582,7 @@ static struct queue_sysfs_entry _prefix##_entry =3D { \ } =20 QUEUE_RW_ENTRY(queue_requests, "nr_requests"); +QUEUE_RW_ENTRY(queue_async_depth, "async_depth"); QUEUE_RW_ENTRY(queue_ra, "read_ahead_kb"); QUEUE_LIM_RW_ENTRY(queue_max_sectors, "max_sectors_kb"); QUEUE_LIM_RO_ENTRY(queue_max_hw_sectors, "max_hw_sectors_kb"); @@ -764,6 +805,7 @@ static struct attribute *blk_mq_queue_attrs[] =3D { */ &elv_iosched_entry.attr, &queue_requests_entry.attr, + &queue_async_depth_entry.attr, #ifdef CONFIG_BLK_WBT &queue_wb_lat_entry.attr, #endif diff --git a/block/elevator.c b/block/elevator.c index e2ebfbf107b3..8f510cb881ba 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -601,6 +601,7 @@ static int elevator_switch(struct request_queue *q, str= uct elv_change_ctx *ctx) blk_queue_flag_clear(QUEUE_FLAG_SQ_SCHED, q); q->elevator =3D NULL; q->nr_requests =3D q->tag_set->queue_depth; + q->async_depth =3D q->tag_set->queue_depth; } blk_add_trace_msg(q, "elv switch: %s", ctx->name); =20 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 02c006fb94c5..1d470ac71c64 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -542,6 +542,7 @@ struct request_queue { * queue settings */ unsigned int nr_requests; /* Max # of requests */ + unsigned int async_depth; /* Max # of async requests */ =20 #ifdef CONFIG_BLK_INLINE_ENCRYPTION struct blk_crypto_profile *crypto_profile; --=20 2.51.0 From nobody Fri Dec 19 10:39:40 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 08B6E2566E2; Fri, 10 Oct 2025 02:28:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760063314; cv=none; b=GGf0l4PcarZVfuYOllXQnrFmryDZVA3PRuiIWKsbLxITbKKwuqtS/LfkevQHz8C8keBMrG2pI/CNthbsPXY1EkMfiIfyaXDfRny2Yo80s0BuhMighk8fVYy0I+t6iOp1YmXI7JH+l+PT+SGj9SpAxHkT698orHxkpJ74m4jf4XA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760063314; c=relaxed/simple; bh=2taC/R/r2EkYl7NPgfLzCfLf3Ik3Fpxzu7ejMKv33e0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mcEvxGPJgv3pqZJL2HxklLHvlDDP7rVXeLOmQFGvz6Eq2sggQ0uqSxyMWnDD9VNSNAst00iBb0quJtlTW/Vjo4E6JqzBg061hw+Jkv2UkfI1YGALHxo4o5Ws0m6dcN9BbyDxd/Dx8hDotqi2L7rKu9v/JHVIGkwaNHWFoiwmUeU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bdtvm8AH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bdtvm8AH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5935BC4CEE7; Fri, 10 Oct 2025 02:28:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760063313; bh=2taC/R/r2EkYl7NPgfLzCfLf3Ik3Fpxzu7ejMKv33e0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bdtvm8AHqQjJt+sxdo3nNkcTJh6ZCExExsyUvD7U0aiQuDhRqu7tAprtm6tWW8Mcz qbs3KuZ2mZPw3ReI5dsrgzof94GbCW4AdXPuskIeuBPAFKMFy4gniOMXWr1My6kfUd 7cyxw0eWi90bMcpRRcQlH5JnlqLwSAF5lN0+/wSdftIA6naNfnkxjkJwsU/D7vbPDw XBqh21tSiewXffsoEcskmEGI2IeaxVJEXPsLH1ZWGVZ2TZikSLqwCjIZ4JtHJeDeHU C9+VBveC84/JRU+326ado1UXr3r5I0yE6APXydjhazVCrEE4J8xS0aG2+1zhp3KYln vY6DnsCwSKh7w== From: Yu Kuai To: axboe@kernel.dk, bvanassche@acm.org, nilay@linux.ibm.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, yangerkun@huawei.com, johnny.chenyi@huawei.com Subject: [PATCH v3 4/7] kyber: covert to use request_queue->async_depth Date: Fri, 10 Oct 2025 10:28:06 +0800 Message-ID: <20251010022812.2985286-5-yukuai@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251010022812.2985286-1-yukuai@kernel.org> References: <20251010022812.2985286-1-yukuai@kernel.org> 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" From: Yu Kuai Instead of the internal async_depth, remove kqd->async_depth and related helpers. Noted elevator attribute async_depth is now removed, queue attribute with the same name is used instead. Signed-off-by: Yu Kuai Reviewed-by: Nilay Shroff --- block/kyber-iosched.c | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/block/kyber-iosched.c b/block/kyber-iosched.c index cf243a457175..469dad8a981c 100644 --- a/block/kyber-iosched.c +++ b/block/kyber-iosched.c @@ -47,9 +47,8 @@ enum { * asynchronous requests, we reserve 25% of requests for synchronous * operations. */ - KYBER_ASYNC_PERCENT =3D 75, + KYBER_DEFAULT_ASYNC_PERCENT =3D 75, }; - /* * Maximum device-wide depth for each scheduling domain. * @@ -157,9 +156,6 @@ struct kyber_queue_data { */ struct sbitmap_queue domain_tokens[KYBER_NUM_DOMAINS]; =20 - /* Number of allowed async requests. */ - unsigned int async_depth; - struct kyber_cpu_latency __percpu *cpu_latency; =20 /* Timer for stats aggregation and adjusting domain tokens. */ @@ -401,10 +397,7 @@ static struct kyber_queue_data *kyber_queue_data_alloc= (struct request_queue *q) =20 static void kyber_depth_updated(struct request_queue *q) { - struct kyber_queue_data *kqd =3D q->elevator->elevator_data; - - kqd->async_depth =3D q->nr_requests * KYBER_ASYNC_PERCENT / 100U; - blk_mq_set_min_shallow_depth(q, kqd->async_depth); + blk_mq_set_min_shallow_depth(q, q->async_depth); } =20 static int kyber_init_sched(struct request_queue *q, struct elevator_queue= *eq) @@ -421,6 +414,7 @@ static int kyber_init_sched(struct request_queue *q, st= ruct elevator_queue *eq) =20 eq->elevator_data =3D kqd; q->elevator =3D eq; + q->async_depth =3D q->nr_requests * KYBER_DEFAULT_ASYNC_PERCENT / 100; kyber_depth_updated(q); =20 return 0; @@ -540,15 +534,8 @@ static void rq_clear_domain_token(struct kyber_queue_d= ata *kqd, =20 static void kyber_limit_depth(blk_opf_t opf, struct blk_mq_alloc_data *dat= a) { - /* - * We use the scheduler tags as per-hardware queue queueing tokens. - * Async requests can be limited at this stage. - */ - if (!blk_mq_sched_sync_request(opf)) { - struct kyber_queue_data *kqd =3D data->q->elevator->elevator_data; - - data->shallow_depth =3D kqd->async_depth; - } + if (!blk_mq_sched_sync_request(opf)) + data->shallow_depth =3D data->q->async_depth; } =20 static bool kyber_bio_merge(struct request_queue *q, struct bio *bio, @@ -944,15 +931,6 @@ KYBER_DEBUGFS_DOMAIN_ATTRS(KYBER_DISCARD, discard) KYBER_DEBUGFS_DOMAIN_ATTRS(KYBER_OTHER, other) #undef KYBER_DEBUGFS_DOMAIN_ATTRS =20 -static int kyber_async_depth_show(void *data, struct seq_file *m) -{ - struct request_queue *q =3D data; - struct kyber_queue_data *kqd =3D q->elevator->elevator_data; - - seq_printf(m, "%u\n", kqd->async_depth); - return 0; -} - static int kyber_cur_domain_show(void *data, struct seq_file *m) { struct blk_mq_hw_ctx *hctx =3D data; @@ -978,7 +956,6 @@ static const struct blk_mq_debugfs_attr kyber_queue_deb= ugfs_attrs[] =3D { KYBER_QUEUE_DOMAIN_ATTRS(write), KYBER_QUEUE_DOMAIN_ATTRS(discard), KYBER_QUEUE_DOMAIN_ATTRS(other), - {"async_depth", 0400, kyber_async_depth_show}, {}, }; #undef KYBER_QUEUE_DOMAIN_ATTRS --=20 2.51.0 From nobody Fri Dec 19 10:39:40 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 14FE7258EE8; Fri, 10 Oct 2025 02:28:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760063317; cv=none; b=dppcpDCIYdcmVDNfa4bm29q1ZusYOAobHKDuu+xt7P6wxqIY1VKQy5pV2H5dRpNlwr5K/Ur0Tn2aVzV1rFE/DUNzuJf2L+lYCJ7YN/BheIphOdaJqLjjmKNI2EdnSF0U/lnZ/BFusH5/ilZLDTMQoP9nKCA2hQh9R7bajGm6BrA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760063317; c=relaxed/simple; bh=/mAxT00KI2ghSwm4SaZ4d2nka0Re3OeQKZg+SA5dhJM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hLfYhASv6PH1/suTYVj1pXGrq/R3aiCnw+CJcNw0sqG+9X+nkUUVAzID0ahANeFh7Lx4yyf1wXLUGLNKCZP7bGEDqCk8/5TRy3xDwoOZtT8Ip4J6CUIiSVEwO3Uy/LlKDISRnzedfcF+/G8rAfC6ZYuIe4J2vQDuB0S6uAOYPCY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p+ffXItH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="p+ffXItH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63B0AC4CEE7; Fri, 10 Oct 2025 02:28:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760063316; bh=/mAxT00KI2ghSwm4SaZ4d2nka0Re3OeQKZg+SA5dhJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p+ffXItHEPmhxVkHDv4E4DyHyvygf7n+60bvAwHJmTU1CKvQRfusVuJu1gRtcgddB VqV9BaVgHa7c6wNd0iR2MxPwYKvVUyc5HIg/SXPmdPsATHRRAwbbRWGgBWnSPm20jZ utFpW4r9Wf6oNQ7mlcC9IgF+OB3p7nUUVIss1Gn62itUmjQybxqJwmQmMDwF7EMgyJ FhoHECZBxgPXRkZr4dZidwQj850LSzbXw5q3r6Pj0RVpapDDlTZjstgKgPiTQojr4G vofuIspYp3b4UkezgsafXpZ7BK+wQkMLXYplmZvzwNjUsvMV2XHUfis5DUWqkj4qur vevNxWmCelNWg== From: Yu Kuai To: axboe@kernel.dk, bvanassche@acm.org, nilay@linux.ibm.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, yangerkun@huawei.com, johnny.chenyi@huawei.com Subject: [PATCH v3 5/7] mq-deadline: covert to use request_queue->async_depth Date: Fri, 10 Oct 2025 10:28:07 +0800 Message-ID: <20251010022812.2985286-6-yukuai@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251010022812.2985286-1-yukuai@kernel.org> References: <20251010022812.2985286-1-yukuai@kernel.org> 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" From: Yu Kuai In downstream kernel, we test with mq-deadline with many fio workloads, and we found a performance regression after commit 39823b47bbd4 ("block/mq-deadline: Fix the tag reservation code") with following test: [global] rw=3Drandread direct=3D1 ramp_time=3D1 ioengine=3Dlibaio iodepth=3D1024 numjobs=3D24 bs=3D1024k group_reporting=3D1 runtime=3D60 [job1] filename=3D/dev/sda Root cause is that mq-deadline now support configuring async_depth, although the default value is nr_request, however the minimal value is 1, hence min_shallow_depth is set to 1, causing wake_batch to be 1. For consequence, sbitmap_queue will be waken up after each IO instead of 8 IO. In this test case, sda is HDD and max_sectors is 128k, hence each submitted 1M io will be splited into 8 sequential 128k requests, however due to there are 24 jobs and total tags are exhausted, the 8 requests are unlikely to be dispatched sequentially, and changing wake_batch to 1 will make this much worse, accounting blktrace D stage, the percentage of sequential io is decreased from 8% to 0.8%. Fix this problem by converting to request_queue->async_depth, where min_shallow_depth is set each time async_depth is updated. Noted elevator attribute async_depth is now removed, queue attribute with the same name is used instead. Fixes: 39823b47bbd4 ("block/mq-deadline: Fix the tag reservation code") Signed-off-by: Yu Kuai Reviewed-by: Nilay Shroff Reviewed-by: Bart Van Assche --- block/mq-deadline.c | 39 +++++---------------------------------- 1 file changed, 5 insertions(+), 34 deletions(-) diff --git a/block/mq-deadline.c b/block/mq-deadline.c index 592dd853f6e5..87c7b7378397 100644 --- a/block/mq-deadline.c +++ b/block/mq-deadline.c @@ -98,7 +98,6 @@ struct deadline_data { int fifo_batch; int writes_starved; int front_merges; - u32 async_depth; int prio_aging_expire; =20 spinlock_t lock; @@ -483,32 +482,16 @@ static struct request *dd_dispatch_request(struct blk= _mq_hw_ctx *hctx) return rq; } =20 -/* - * Called by __blk_mq_alloc_request(). The shallow_depth value set by this - * function is used by __blk_mq_get_tag(). - */ static void dd_limit_depth(blk_opf_t opf, struct blk_mq_alloc_data *data) { - struct deadline_data *dd =3D data->q->elevator->elevator_data; - - /* Do not throttle synchronous reads. */ - if (blk_mq_sched_sync_request(opf)) - return; - - /* - * Throttle asynchronous requests and writes such that these requests - * do not block the allocation of synchronous requests. - */ - data->shallow_depth =3D dd->async_depth; + if (!blk_mq_sched_sync_request(opf)) + data->shallow_depth =3D data->q->async_depth; } =20 -/* Called by blk_mq_update_nr_requests(). */ +/* Called by blk_mq_init_sched() and blk_mq_update_nr_requests(). */ static void dd_depth_updated(struct request_queue *q) { - struct deadline_data *dd =3D q->elevator->elevator_data; - - dd->async_depth =3D q->nr_requests; - blk_mq_set_min_shallow_depth(q, 1); + blk_mq_set_min_shallow_depth(q, q->async_depth); } =20 static void dd_exit_sched(struct elevator_queue *e) @@ -573,6 +556,7 @@ static int dd_init_sched(struct request_queue *q, struc= t elevator_queue *eq) blk_queue_flag_set(QUEUE_FLAG_SQ_SCHED, q); =20 q->elevator =3D eq; + q->async_depth =3D q->nr_requests; dd_depth_updated(q); return 0; } @@ -758,7 +742,6 @@ SHOW_JIFFIES(deadline_write_expire_show, dd->fifo_expir= e[DD_WRITE]); SHOW_JIFFIES(deadline_prio_aging_expire_show, dd->prio_aging_expire); SHOW_INT(deadline_writes_starved_show, dd->writes_starved); SHOW_INT(deadline_front_merges_show, dd->front_merges); -SHOW_INT(deadline_async_depth_show, dd->async_depth); SHOW_INT(deadline_fifo_batch_show, dd->fifo_batch); #undef SHOW_INT #undef SHOW_JIFFIES @@ -788,7 +771,6 @@ STORE_JIFFIES(deadline_write_expire_store, &dd->fifo_ex= pire[DD_WRITE], 0, INT_MA STORE_JIFFIES(deadline_prio_aging_expire_store, &dd->prio_aging_expire, 0,= INT_MAX); STORE_INT(deadline_writes_starved_store, &dd->writes_starved, INT_MIN, INT= _MAX); STORE_INT(deadline_front_merges_store, &dd->front_merges, 0, 1); -STORE_INT(deadline_async_depth_store, &dd->async_depth, 1, INT_MAX); STORE_INT(deadline_fifo_batch_store, &dd->fifo_batch, 0, INT_MAX); #undef STORE_FUNCTION #undef STORE_INT @@ -802,7 +784,6 @@ static const struct elv_fs_entry deadline_attrs[] =3D { DD_ATTR(write_expire), DD_ATTR(writes_starved), DD_ATTR(front_merges), - DD_ATTR(async_depth), DD_ATTR(fifo_batch), DD_ATTR(prio_aging_expire), __ATTR_NULL @@ -889,15 +870,6 @@ static int deadline_starved_show(void *data, struct se= q_file *m) return 0; } =20 -static int dd_async_depth_show(void *data, struct seq_file *m) -{ - struct request_queue *q =3D data; - struct deadline_data *dd =3D q->elevator->elevator_data; - - seq_printf(m, "%u\n", dd->async_depth); - return 0; -} - static int dd_queued_show(void *data, struct seq_file *m) { struct request_queue *q =3D data; @@ -1007,7 +979,6 @@ static const struct blk_mq_debugfs_attr deadline_queue= _debugfs_attrs[] =3D { DEADLINE_NEXT_RQ_ATTR(write2), {"batching", 0400, deadline_batching_show}, {"starved", 0400, deadline_starved_show}, - {"async_depth", 0400, dd_async_depth_show}, {"dispatch0", 0400, .seq_ops =3D &deadline_dispatch0_seq_ops}, {"dispatch1", 0400, .seq_ops =3D &deadline_dispatch1_seq_ops}, {"dispatch2", 0400, .seq_ops =3D &deadline_dispatch2_seq_ops}, --=20 2.51.0 From nobody Fri Dec 19 10:39:40 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F1BA2261573; Fri, 10 Oct 2025 02:28:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760063320; cv=none; b=C0ZY48VT+Xo5HurLracQ4uyb0gd+JGEmoaF/PSMQLR0z6vEzXPWaiAmzQeOHEZEPxWRrRBznAlMkL3r5qnkazKBckMmfAnuJVkZxXVftiy69JMJhs5e6c06NWw1lfF8f+VvknkcODf9sTc1nOcYaErRBN/VNp4mrmDNFIYBLBXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760063320; c=relaxed/simple; bh=o0IxMr8K7Z/aTz7NIdtgsbeN4pEuzaoBeum3uxdXMjA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H73PmbzKA7vmH9TFsTHdp+f90w1aM0RDBfUBqWTkU8/BcaFjaF2xSL8NxoN7w1wDEAYUSfh9zYPAw5WSyoE326P8EJam6Kw0AUSP17lhAUcXI/E/OzfuKE7ssZHJBpWtkLic2Jh8QcDef5J69ZT8dsjrubYjn6rEREuuRGlUgQQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P9zWguNB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="P9zWguNB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77C1FC4CEE7; Fri, 10 Oct 2025 02:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760063319; bh=o0IxMr8K7Z/aTz7NIdtgsbeN4pEuzaoBeum3uxdXMjA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P9zWguNBwB1KHs7SRoJzi0uQ/GcH8J/kfUrauICCDDKKHXzojix+m0OVwsljUdNe3 xdwXbz6+HORzdZe5tIxjeOdRj5NzXKd4U5IdbAvGojGHTmR/8Xu5w5zsGUZBFToYaA YfY4T7XmtXKCLYI8yXI2SYhDWDcdIJcfimSG6CepGNXnPdsSIVDCYSuTYurTOYHwIk //ZsRylSWst0xLU/VKag16vDotCIypjJI1HUuSpuybsgKGt/0/D8Ft/veie6YDsijI Qmi2HkL+GB/qKIY4hc9iFa/77+JJBz3dl3TEr5AklWofCJSmqFlOOz3IPVDJguXGp7 OcoWxsaJGev8w== From: Yu Kuai To: axboe@kernel.dk, bvanassche@acm.org, nilay@linux.ibm.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, yangerkun@huawei.com, johnny.chenyi@huawei.com Subject: [PATCH v3 6/7] block, bfq: convert to use request_queue->async_depth Date: Fri, 10 Oct 2025 10:28:08 +0800 Message-ID: <20251010022812.2985286-7-yukuai@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251010022812.2985286-1-yukuai@kernel.org> References: <20251010022812.2985286-1-yukuai@kernel.org> 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" From: Yu Kuai The default limits is unchanged, and user can configure async_depth now. Signed-off-by: Yu Kuai Reviewed-by: Nilay Shroff --- block/bfq-iosched.c | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index 63452e791f98..9e0eee9aba5c 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -7112,39 +7112,29 @@ void bfq_put_async_queues(struct bfq_data *bfqd, st= ruct bfq_group *bfqg) static void bfq_depth_updated(struct request_queue *q) { struct bfq_data *bfqd =3D q->elevator->elevator_data; - unsigned int nr_requests =3D q->nr_requests; + unsigned int async_depth =3D q->async_depth; =20 /* - * In-word depths if no bfq_queue is being weight-raised: - * leaving 25% of tags only for sync reads. + * By default: + * - sync reads are not limited + * If bfqq is not being weight-raised: + * - sync writes are limited to 75%(async depth default value) + * - async IO are limited to 50% + * If bfqq is being weight-raised: + * - sync writes are limited to ~37% + * - async IO are limited to ~18 * - * In next formulas, right-shift the value - * (1U<sb.shift), instead of computing directly - * (1U<<(bt->sb.shift - something)), to be robust against - * any possible value of bt->sb.shift, without having to - * limit 'something'. + * If request_queue->async_depth is updated by user, all limit are + * updated relatively. */ - /* no more than 50% of tags for async I/O */ - bfqd->async_depths[0][0] =3D max(nr_requests >> 1, 1U); - /* - * no more than 75% of tags for sync writes (25% extra tags - * w.r.t. async I/O, to prevent async I/O from starving sync - * writes) - */ - bfqd->async_depths[0][1] =3D max((nr_requests * 3) >> 2, 1U); + bfqd->async_depths[0][1] =3D async_depth; + bfqd->async_depths[0][0] =3D max(async_depth * 2 / 3, 1U); + bfqd->async_depths[1][1] =3D max(async_depth >> 1, 1U); + bfqd->async_depths[1][0] =3D max(async_depth >> 2, 1U); =20 /* - * In-word depths in case some bfq_queue is being weight- - * raised: leaving ~63% of tags for sync reads. This is the - * highest percentage for which, in our tests, application - * start-up times didn't suffer from any regression due to tag - * shortage. + * Due to cgroup qos, the allowed request for bfqq might be 1 */ - /* no more than ~18% of tags for async I/O */ - bfqd->async_depths[1][0] =3D max((nr_requests * 3) >> 4, 1U); - /* no more than ~37% of tags for sync writes (~20% extra tags) */ - bfqd->async_depths[1][1] =3D max((nr_requests * 6) >> 4, 1U); - blk_mq_set_min_shallow_depth(q, 1); } =20 @@ -7365,6 +7355,7 @@ static int bfq_init_queue(struct request_queue *q, st= ruct elevator_queue *eq) blk_queue_flag_set(QUEUE_FLAG_DISABLE_WBT_DEF, q); wbt_disable_default(q->disk); blk_stat_enable_accounting(q); + q->async_depth =3D (q->nr_requests * 3) >> 2; =20 return 0; =20 --=20 2.51.0 From nobody Fri Dec 19 10:39:40 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2AB8C268C42; Fri, 10 Oct 2025 02:28:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760063322; cv=none; b=K0rvQchN8n9UDpP2da427Gg61aijrhzrQMKKNWO6A/NF0FzBopSjbVAe51z2tcVZ0KxrPFUWTnl2PsQmX+Tp4KJIiy48YjnYyYlGEIPZE1pAAxXbW0kNr1dt1umdQ0OFHGTl7PWBjLWDAhkcj+eAiqrf0bACoIsUgTqTc1JmDLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760063322; c=relaxed/simple; bh=FK9xKviTcI/C/LX0yN/JGLOVejrI+c9f1E6gl9PnytQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gtPum16gswonQPC3YSA3KWLoS4peJmd/EZZEJ5Tk0j64cvn+mQKTC01Sck4D3jLqJDVMEoyOlJzUQGSymYpTmxz32s1eQRYp8SarLpnsILKBUKwEkukiFyApQe4w3bWr0E7BAbUeBiRWBs3E1TJzmaGisLOV3z9BXRDkSWWzP2g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Bndp/sPY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Bndp/sPY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED887C4CEF7; Fri, 10 Oct 2025 02:28:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760063322; bh=FK9xKviTcI/C/LX0yN/JGLOVejrI+c9f1E6gl9PnytQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bndp/sPYydcCNDbqrXtjVXk/W675XXogzGiv+wYQO7RUr4O7Qb323sK7694qpUdEB j5Wmyok32ASruvnzXq2Wju1+WutiK3Ql+cvY9VIgTVJ0fSOggPEiK2pOUL2LnZrGXP 7MV0NvitQ8m8fJYIVrQHQCcSbwmVP5PJqlMGkaWVb0ptGQRoafeCgF7qyLELfyXdD9 mGDKGey91KwMJTKM21onErVPUAVbS/Cke52c6KzTNY0IR6A74dHjFVE2Z6RxKzuR9R 1EmjpsdWk6l62UzbYDrcD7uHVguKiwM9BwNkgf9sSoM3Kxohizt46BF2+kVK5eyAy1 QeYbPuk8Cz35Q== From: Yu Kuai To: axboe@kernel.dk, bvanassche@acm.org, nilay@linux.ibm.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, yangerkun@huawei.com, johnny.chenyi@huawei.com Subject: [PATCH v3 7/7] blk-mq: add documentation for new queue attribute async_dpeth Date: Fri, 10 Oct 2025 10:28:09 +0800 Message-ID: <20251010022812.2985286-8-yukuai@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251010022812.2985286-1-yukuai@kernel.org> References: <20251010022812.2985286-1-yukuai@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Yu Kuai Explain the attribute and the default value in different case. Signed-off-by: Yu Kuai Reviewed-by: Nilay Shroff --- Documentation/ABI/stable/sysfs-block | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Documentation/ABI/stable/sysfs-block b/Documentation/ABI/stabl= e/sysfs-block index 0ed10aeff86b..aa1e94169666 100644 --- a/Documentation/ABI/stable/sysfs-block +++ b/Documentation/ABI/stable/sysfs-block @@ -609,6 +609,40 @@ Description: enabled, and whether tags are shared. =20 =20 +What: /sys/block//queue/async_depth +Date: August 2025 +Contact: linux-block@vger.kernel.org +Description: + [RW] Controls how many asynchronous requests may be allocated in the + block layer. The value is always capped at nr_requests. + + When no elevator is active (none): + - async_depth is always equal to nr_requests. + + For bfq scheduler: + - By default, async_depth is set to 75% of nr_requests. + Internal limits are then derived from this value: + * Sync writes: limited to async_depth (=E2=89=8875% of nr_requests). + * Async I/O: limited to ~2/3 of async_depth (=E2=89=8850% of nr_reques= ts). + + If a bfq_queue is weight-raised: + * Sync writes: limited to ~1/2 of async_depth (=E2=89=8837% of nr_requ= ests). + * Async I/O: limited to ~1/4 of async_depth (=E2=89=8818% of nr_reques= ts). + + - If the user writes a custom value to async_depth, BFQ will recompute + these limits proportionally based on the new value. + + For Kyber: + - By default async_depth is set to 75% of nr_requests. + - If the user writes a custom value to async_depth, then it override the + default and directly control the limit for writes and async I/O. + + For mq-deadline: + - By default async_depth is set to nr_requests. + - If the user writes a custom value to async_depth, then it override the + default and directly control the limit for writes and async I/O. + + What: /sys/block//queue/nr_zones Date: November 2018 Contact: Damien Le Moal --=20 2.51.0