From nobody Sun May 5 14:10:31 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD876C433FE for ; Mon, 23 May 2022 13:04:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235857AbiEWNEr (ORCPT ); Mon, 23 May 2022 09:04:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235729AbiEWNEq (ORCPT ); Mon, 23 May 2022 09:04:46 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 204F92DF; Mon, 23 May 2022 06:04:45 -0700 (PDT) Received: from kwepemi500006.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4L6Hbs0zfJzDqMC; Mon, 23 May 2022 21:04:41 +0800 (CST) Received: from kwepemm600009.china.huawei.com (7.193.23.164) by kwepemi500006.china.huawei.com (7.221.188.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 23 May 2022 21:04:42 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 23 May 2022 21:04:42 +0800 From: Yu Kuai To: , , , CC: , , , , Subject: [PATCH -next v6 1/3] block, bfq: record how many queues are busy in bfq_group Date: Mon, 23 May 2022 21:18:16 +0800 Message-ID: <20220523131818.2798712-2-yukuai3@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220523131818.2798712-1-yukuai3@huawei.com> References: <20220523131818.2798712-1-yukuai3@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600009.china.huawei.com (7.193.23.164) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Prepare to refactor the counting of 'num_groups_with_pending_reqs'. Add a counter 'busy_queues' in bfq_group, and update it in bfq_add/del_bfqq_busy(). Signed-off-by: Yu Kuai Reviewed-by: Jan Kara --- block/bfq-cgroup.c | 1 + block/bfq-iosched.h | 2 ++ block/bfq-wf2q.c | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c index 09574af83566..4d516879d9fa 100644 --- a/block/bfq-cgroup.c +++ b/block/bfq-cgroup.c @@ -557,6 +557,7 @@ static void bfq_pd_init(struct blkg_policy_data *pd) */ bfqg->bfqd =3D bfqd; bfqg->active_entities =3D 0; + bfqg->busy_queues =3D 0; bfqg->online =3D true; bfqg->rq_pos_tree =3D RB_ROOT; } diff --git a/block/bfq-iosched.h b/block/bfq-iosched.h index 978ef5d6fe6a..3847f4ab77ac 100644 --- a/block/bfq-iosched.h +++ b/block/bfq-iosched.h @@ -906,6 +906,7 @@ struct bfq_group_data { * are groups with more than one active @bfq_entity * (see the comments to the function * bfq_bfqq_may_idle()). + * @busy_queues: number of busy bfqqs. * @rq_pos_tree: rbtree sorted by next_request position, used when * determining if two or more queues have interleaving * requests (see bfq_find_close_cooperator()). @@ -942,6 +943,7 @@ struct bfq_group { struct bfq_entity *my_entity; =20 int active_entities; + int busy_queues; =20 struct rb_root rq_pos_tree; =20 diff --git a/block/bfq-wf2q.c b/block/bfq-wf2q.c index f8eb340381cf..d9ff33e0be38 100644 --- a/block/bfq-wf2q.c +++ b/block/bfq-wf2q.c @@ -218,6 +218,16 @@ static bool bfq_no_longer_next_in_service(struct bfq_e= ntity *entity) return false; } =20 +static void bfq_inc_busy_queues(struct bfq_queue *bfqq) +{ + bfqq_group(bfqq)->busy_queues++; +} + +static void bfq_dec_busy_queues(struct bfq_queue *bfqq) +{ + bfqq_group(bfqq)->busy_queues--; +} + #else /* CONFIG_BFQ_GROUP_IOSCHED */ =20 static bool bfq_update_parent_budget(struct bfq_entity *next_in_service) @@ -230,6 +240,14 @@ static bool bfq_no_longer_next_in_service(struct bfq_e= ntity *entity) return true; } =20 +static void bfq_inc_busy_queues(struct bfq_queue *bfqq) +{ +} + +static void bfq_dec_busy_queues(struct bfq_queue *bfqq) +{ +} + #endif /* CONFIG_BFQ_GROUP_IOSCHED */ =20 /* @@ -1660,6 +1678,7 @@ void bfq_del_bfqq_busy(struct bfq_data *bfqd, struct = bfq_queue *bfqq, bfq_clear_bfqq_busy(bfqq); =20 bfqd->busy_queues[bfqq->ioprio_class - 1]--; + bfq_inc_busy_queues(bfqq); =20 if (bfqq->wr_coeff > 1) bfqd->wr_busy_queues--; @@ -1683,6 +1702,7 @@ void bfq_add_bfqq_busy(struct bfq_data *bfqd, struct = bfq_queue *bfqq) =20 bfq_mark_bfqq_busy(bfqq); bfqd->busy_queues[bfqq->ioprio_class - 1]++; + bfq_dec_busy_queues(bfqq); =20 if (!bfqq->dispatched) if (bfqq->wr_coeff =3D=3D 1) --=20 2.31.1 From nobody Sun May 5 14:10:31 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12CE0C433EF for ; Mon, 23 May 2022 13:04:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235869AbiEWNEw (ORCPT ); Mon, 23 May 2022 09:04:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235856AbiEWNEr (ORCPT ); Mon, 23 May 2022 09:04:47 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C732D62C5; Mon, 23 May 2022 06:04:45 -0700 (PDT) Received: from kwepemi500003.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4L6HZp67yrzjWwy; Mon, 23 May 2022 21:03:46 +0800 (CST) Received: from kwepemm600009.china.huawei.com (7.193.23.164) by kwepemi500003.china.huawei.com (7.221.188.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 23 May 2022 21:04:43 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 23 May 2022 21:04:42 +0800 From: Yu Kuai To: , , , CC: , , , , Subject: [PATCH -next v6 2/3] block, bfq: refactor the counting of 'num_groups_with_pending_reqs' Date: Mon, 23 May 2022 21:18:17 +0800 Message-ID: <20220523131818.2798712-3-yukuai3@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220523131818.2798712-1-yukuai3@huawei.com> References: <20220523131818.2798712-1-yukuai3@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600009.china.huawei.com (7.193.23.164) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently, bfq can't handle sync io concurrently as long as they are not issued from root group. This is because 'bfqd->num_groups_with_pending_reqs > 0' is always true in bfq_asymmetric_scenario(). The way that bfqg is counted into 'num_groups_with_pending_reqs': Before this patch: 1) root group will never be counted. 2) Count if bfqg or it's child bfqgs have pending requests. 3) Don't count if bfqg and it's child bfqgs complete all the requests. After this patch: 1) root group is counted. 2) Count if bfqg have at least one bfqq that is marked busy. 3) Don't count if bfqg doesn't have any busy bfqqs. The main reason to use busy state of bfqq instead of 'pending requests' is that bfqq can stay busy after dispatching the last request if idling is needed for service guarantees. With this change, the occasion that only one group is activated can be detected, and next patch will support concurrent sync io in the occasion. This patch also rename 'num_groups_with_pending_reqs' to 'num_groups_with_busy_queues'. Signed-off-by: Yu Kuai Reviewed-by: Jan Kara --- block/bfq-iosched.c | 46 ++----------------------------------- block/bfq-iosched.h | 55 ++++++--------------------------------------- block/bfq-wf2q.c | 19 ++++------------ 3 files changed, 13 insertions(+), 107 deletions(-) diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index e47c75f1fa0f..609b4e894684 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -844,7 +844,7 @@ static bool bfq_asymmetric_scenario(struct bfq_data *bf= qd, =20 return varied_queue_weights || multiple_classes_busy #ifdef CONFIG_BFQ_GROUP_IOSCHED - || bfqd->num_groups_with_pending_reqs > 0 + || bfqd->num_groups_with_busy_queues > 0 #endif ; } @@ -962,48 +962,6 @@ void __bfq_weights_tree_remove(struct bfq_data *bfqd, void bfq_weights_tree_remove(struct bfq_data *bfqd, struct bfq_queue *bfqq) { - struct bfq_entity *entity =3D bfqq->entity.parent; - - for_each_entity(entity) { - struct bfq_sched_data *sd =3D entity->my_sched_data; - - if (sd->next_in_service || sd->in_service_entity) { - /* - * entity is still active, because either - * next_in_service or in_service_entity is not - * NULL (see the comments on the definition of - * next_in_service for details on why - * in_service_entity must be checked too). - * - * As a consequence, its parent entities are - * active as well, and thus this loop must - * stop here. - */ - break; - } - - /* - * The decrement of num_groups_with_pending_reqs is - * not performed immediately upon the deactivation of - * entity, but it is delayed to when it also happens - * that the first leaf descendant bfqq of entity gets - * all its pending requests completed. The following - * instructions perform this delayed decrement, if - * needed. See the comments on - * num_groups_with_pending_reqs for details. - */ - if (entity->in_groups_with_pending_reqs) { - entity->in_groups_with_pending_reqs =3D false; - bfqd->num_groups_with_pending_reqs--; - } - } - - /* - * Next function is invoked last, because it causes bfqq to be - * freed if the following holds: bfqq is not in service and - * has no dispatched request. DO NOT use bfqq after the next - * function invocation. - */ __bfq_weights_tree_remove(bfqd, bfqq, &bfqd->queue_weights_tree); } @@ -7107,7 +7065,7 @@ static int bfq_init_queue(struct request_queue *q, st= ruct elevator_type *e) bfqd->idle_slice_timer.function =3D bfq_idle_slice_timer; =20 bfqd->queue_weights_tree =3D RB_ROOT_CACHED; - bfqd->num_groups_with_pending_reqs =3D 0; + bfqd->num_groups_with_busy_queues =3D 0; =20 INIT_LIST_HEAD(&bfqd->active_list); INIT_LIST_HEAD(&bfqd->idle_list); diff --git a/block/bfq-iosched.h b/block/bfq-iosched.h index 3847f4ab77ac..b71a088a7f1d 100644 --- a/block/bfq-iosched.h +++ b/block/bfq-iosched.h @@ -197,9 +197,6 @@ struct bfq_entity { /* flag, set to request a weight, ioprio or ioprio_class change */ int prio_changed; =20 - /* flag, set if the entity is counted in groups_with_pending_reqs */ - bool in_groups_with_pending_reqs; - /* last child queue of entity created (for non-leaf entities) */ struct bfq_queue *last_bfqq_created; }; @@ -495,52 +492,14 @@ struct bfq_data { struct rb_root_cached queue_weights_tree; =20 /* - * Number of groups with at least one descendant process that - * has at least one request waiting for completion. Note that - * this accounts for also requests already dispatched, but not - * yet completed. Therefore this number of groups may differ - * (be larger) than the number of active groups, as a group is - * considered active only if its corresponding entity has - * descendant queues with at least one request queued. This - * number is used to decide whether a scenario is symmetric. - * For a detailed explanation see comments on the computation - * of the variable asymmetric_scenario in the function - * bfq_better_to_idle(). - * - * However, it is hard to compute this number exactly, for - * groups with multiple descendant processes. Consider a group - * that is inactive, i.e., that has no descendant process with - * pending I/O inside BFQ queues. Then suppose that - * num_groups_with_pending_reqs is still accounting for this - * group, because the group has descendant processes with some - * I/O request still in flight. num_groups_with_pending_reqs - * should be decremented when the in-flight request of the - * last descendant process is finally completed (assuming that - * nothing else has changed for the group in the meantime, in - * terms of composition of the group and active/inactive state of child - * groups and processes). To accomplish this, an additional - * pending-request counter must be added to entities, and must - * be updated correctly. To avoid this additional field and operations, - * we resort to the following tradeoff between simplicity and - * accuracy: for an inactive group that is still counted in - * num_groups_with_pending_reqs, we decrement - * num_groups_with_pending_reqs when the first descendant - * process of the group remains with no request waiting for - * completion. - * - * Even this simpler decrement strategy requires a little - * carefulness: to avoid multiple decrements, we flag a group, - * more precisely an entity representing a group, as still - * counted in num_groups_with_pending_reqs when it becomes - * inactive. Then, when the first descendant queue of the - * entity remains with no request waiting for completion, - * num_groups_with_pending_reqs is decremented, and this flag - * is reset. After this flag is reset for the entity, - * num_groups_with_pending_reqs won't be decremented any - * longer in case a new descendant queue of the entity remains - * with no request waiting for completion. + * Number of groups with at least one bfqq that is marked busy, + * and this number is used to decide whether a scenario is symmetric. + * Note that bfqq is busy doesn't mean that the bfqq contains requests. + * If idling is needed for service guarantees, bfqq will stay busy + * after dispatching the last request, see details in + * __bfq_bfqq_expire(). */ - unsigned int num_groups_with_pending_reqs; + unsigned int num_groups_with_busy_queues; =20 /* * Per-class (RT, BE, IDLE) number of bfq_queues containing diff --git a/block/bfq-wf2q.c b/block/bfq-wf2q.c index d9ff33e0be38..42464e6ff40c 100644 --- a/block/bfq-wf2q.c +++ b/block/bfq-wf2q.c @@ -220,12 +220,14 @@ static bool bfq_no_longer_next_in_service(struct bfq_= entity *entity) =20 static void bfq_inc_busy_queues(struct bfq_queue *bfqq) { - bfqq_group(bfqq)->busy_queues++; + if (!(bfqq_group(bfqq)->busy_queues++)) + bfqq->bfqd->num_groups_with_busy_queues++; } =20 static void bfq_dec_busy_queues(struct bfq_queue *bfqq) { - bfqq_group(bfqq)->busy_queues--; + if (!(--bfqq_group(bfqq)->busy_queues)) + bfqq->bfqd->num_groups_with_busy_queues--; } =20 #else /* CONFIG_BFQ_GROUP_IOSCHED */ @@ -1002,19 +1004,6 @@ static void __bfq_activate_entity(struct bfq_entity = *entity, entity->on_st_or_in_serv =3D true; } =20 -#ifdef CONFIG_BFQ_GROUP_IOSCHED - if (!bfq_entity_to_bfqq(entity)) { /* bfq_group */ - struct bfq_group *bfqg =3D - container_of(entity, struct bfq_group, entity); - struct bfq_data *bfqd =3D bfqg->bfqd; - - if (!entity->in_groups_with_pending_reqs) { - entity->in_groups_with_pending_reqs =3D true; - bfqd->num_groups_with_pending_reqs++; - } - } -#endif - bfq_update_fin_time_enqueue(entity, st, backshifted); } =20 --=20 2.31.1 From nobody Sun May 5 14:10:31 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A07EFC433F5 for ; Mon, 23 May 2022 13:05:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235885AbiEWNFF (ORCPT ); Mon, 23 May 2022 09:05:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235871AbiEWNFA (ORCPT ); Mon, 23 May 2022 09:05:00 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22E5E4992F; Mon, 23 May 2022 06:04:59 -0700 (PDT) Received: from kwepemi500002.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4L6HZD3pm1z1JCFC; Mon, 23 May 2022 21:03:16 +0800 (CST) Received: from kwepemm600009.china.huawei.com (7.193.23.164) by kwepemi500002.china.huawei.com (7.221.188.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 23 May 2022 21:04:44 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 23 May 2022 21:04:43 +0800 From: Yu Kuai To: , , , CC: , , , , Subject: [PATCH -next v6 3/3] block, bfq: do not idle if only one group is activated Date: Mon, 23 May 2022 21:18:18 +0800 Message-ID: <20220523131818.2798712-4-yukuai3@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220523131818.2798712-1-yukuai3@huawei.com> References: <20220523131818.2798712-1-yukuai3@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600009.china.huawei.com (7.193.23.164) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Now that root group is counted into 'num_groups_with_busy_queues', 'num_groups_with_busy_queues > 0' is always true in bfq_asymmetric_scenario(). Thus change the condition to '> 1'. On the other hand, this change can enable concurrent sync io if only one group is activated. Signed-off-by: Yu Kuai Reviewed-by: Jan Kara --- block/bfq-iosched.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index 609b4e894684..142e1ca4600f 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -812,7 +812,7 @@ bfq_pos_tree_add_move(struct bfq_data *bfqd, struct bfq= _queue *bfqq) * much easier to maintain the needed state: * 1) all active queues have the same weight, * 2) all active queues belong to the same I/O-priority class, - * 3) there are no active groups. + * 3) there are one active group at most. * In particular, the last condition is always true if hierarchical * support or the cgroups interface are not enabled, thus no state * needs to be maintained in this case. @@ -844,7 +844,7 @@ static bool bfq_asymmetric_scenario(struct bfq_data *bf= qd, =20 return varied_queue_weights || multiple_classes_busy #ifdef CONFIG_BFQ_GROUP_IOSCHED - || bfqd->num_groups_with_busy_queues > 0 + || bfqd->num_groups_with_busy_queues > 1 #endif ; } --=20 2.31.1