Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1320721pxb; Sat, 16 Apr 2022 05:14:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBqmE/WG0/Npr8OD5WHWZLbt/w88XZBQiHbNiX5sR44oiUdlmOVqwAUkK5hnyhZTokMMpX X-Received: by 2002:a17:906:3144:b0:6ce:de5d:5e3b with SMTP id e4-20020a170906314400b006cede5d5e3bmr2558048eje.689.1650111291272; Sat, 16 Apr 2022 05:14:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650111291; cv=none; d=google.com; s=arc-20160816; b=VhsrS5r0AlCN+caO1CMcQUoNjDZOwRADgHjx5v8UYlOAjjjwN2ys1i0pWKvJml67B5 I0doSQ9kB/j57gd8jknqzCaE0HbE8PCkWLLFUdPFr7UpyWTR8qhhm5KiAgSlKkxD/fd+ Q2nqhMnYd7oHLdv12gTwWl9oTNDtQKo4eurdLr0tSDR/P/nSgsCRfl0UC8q/IR9+U2JD 36eteTQL2F77sksKA3F//+I1AAi8EFbcVyWq3c0njVuWxza0wiggukJb8gaqaTa8sBYr NRGrK1WJSeeT5kncCqyXFmtA2ZG40lCmjbGYIbiR0vI+Nl8tA9nOl8V38FP85aVop8bt DFjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=M+gG4LRjOAyywLEKjFRi+c4yLg3U6d9s6O2EmfMapNk=; b=WynrxL9nJbTE76DmJV2MVdd+b7CeVo5qhPe2/agB1nQRJIpLAgFtFJ5wT2yNudwRRK Sng381mX86kCav9umaLnXwLO3lrpwTshUILjdiSYi5BBjpz3T3hHw/sCBhec6BMKaZcs iqHLu1NNqlJbP0txjPktEhdgMdkVmsEG23801qoveAfr8laaO0DHHGTq/g3QZuN89XWo cAwxgx2jg3m3r63WU/IMKWwfe3oHPGX8y10sgAdNR4k3DxHDUvPzm62Bz5jMtIeBsfYE VbW3lBlNSnzeLZUxSoRhWLJrnUXqswpW1zZbagiISob8o9CKPGbLY+5PGow3tY32YvjR Hrgg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qn15-20020a170907210f00b006df76385e39si2664647ejb.729.2022.04.16.05.14.13; Sat, 16 Apr 2022 05:14:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231292AbiDPJ0O (ORCPT + 99 others); Sat, 16 Apr 2022 05:26:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231248AbiDPJ0C (ORCPT ); Sat, 16 Apr 2022 05:26:02 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15C471031; Sat, 16 Apr 2022 02:23:31 -0700 (PDT) Received: from kwepemi100016.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4KgSLg6x3RzCr6N; Sat, 16 Apr 2022 17:19:07 +0800 (CST) Received: from kwepemm600009.china.huawei.com (7.193.23.164) by kwepemi100016.china.huawei.com (7.221.188.123) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 16 Apr 2022 17:23:29 +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; Sat, 16 Apr 2022 17:23:28 +0800 From: Yu Kuai To: , , , CC: , , , , Subject: [PATCH -next v2 4/5] block, bfq: refactor the counting of 'num_groups_with_pending_reqs' Date: Sat, 16 Apr 2022 17:37:52 +0800 Message-ID: <20220416093753.3054696-5-yukuai3@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220416093753.3054696-1-yukuai3@huawei.com> References: <20220416093753.3054696-1-yukuai3@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600009.china.huawei.com (7.193.23.164) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 to '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 pending requests. 3) Don't count if bfqg complete all the requests. With this patch, the occasion that only one group have pending requests can be detected, and next patch will support concurrent sync io in the occasion. Signed-off-by: Yu Kuai --- block/bfq-iosched.c | 52 ++++++--------------------------------------- block/bfq-iosched.h | 18 ++++++++-------- block/bfq-wf2q.c | 13 ------------ 3 files changed, 15 insertions(+), 68 deletions(-) diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index 994c6b36a5d5..39abcd95df8e 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -941,7 +941,8 @@ void bfq_weights_tree_add(struct bfq_data *bfqd, struct bfq_queue *bfqq) #ifdef CONFIG_BFQ_GROUP_IOSCHED if (!entity->in_groups_with_pending_reqs) { entity->in_groups_with_pending_reqs = true; - bfqq_group(bfqq)->num_entities_with_pending_reqs++; + if (!(bfqq_group(bfqq)->num_entities_with_pending_reqs++)) + bfqd->num_groups_with_pending_reqs++; } #endif } @@ -974,7 +975,8 @@ void __bfq_weights_tree_remove(struct bfq_data *bfqd, struct bfq_queue *bfqq) #ifdef CONFIG_BFQ_GROUP_IOSCHED if (bfqq->entity.in_groups_with_pending_reqs) { bfqq->entity.in_groups_with_pending_reqs = false; - bfqq_group(bfqq)->num_entities_with_pending_reqs--; + if (!(--bfqq_group(bfqq)->num_entities_with_pending_reqs)) + bfqd->num_groups_with_pending_reqs--; } #endif @@ -989,48 +991,6 @@ void __bfq_weights_tree_remove(struct bfq_data *bfqd, struct bfq_queue *bfqq) void bfq_weights_tree_remove(struct bfq_data *bfqd, struct bfq_queue *bfqq) { - struct bfq_entity *entity = bfqq->entity.parent; - - for_each_entity(entity) { - struct bfq_sched_data *sd = 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 = 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); } @@ -3710,7 +3670,7 @@ static void bfq_dispatch_remove(struct request_queue *q, struct request *rq) * group. More precisely, for conditions (i-a) or (i-b) to become * false because of such a group, it is not even necessary that the * group is (still) active: it is sufficient that, even if the group - * has become inactive, some of its descendant processes still have + * has become inactive, some of its processes still have * some request already dispatched but still waiting for * completion. In fact, requests have still to be guaranteed their * share of the throughput even after being dispatched. In this @@ -3719,7 +3679,7 @@ static void bfq_dispatch_remove(struct request_queue *q, struct request *rq) * happens, the group is not considered in the calculation of whether * the scenario is asymmetric, then the group may fail to be * guaranteed its fair share of the throughput (basically because - * idling may not be performed for the descendant processes of the + * idling may not be performed for the processes of the * group, but it had to be). We address this issue with the following * bi-modal behavior, implemented in the function * bfq_asymmetric_scenario(). diff --git a/block/bfq-iosched.h b/block/bfq-iosched.h index 5e1a0ead2b6a..0850ca03e1d5 100644 --- a/block/bfq-iosched.h +++ b/block/bfq-iosched.h @@ -495,27 +495,27 @@ struct bfq_data { struct rb_root_cached queue_weights_tree; /* - * Number of groups with at least one descendant process that + * Number of groups with at least one 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 + * 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 + * groups with multiple processes. Consider a group + * that is inactive, i.e., that has no 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 + * group, because the group has 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 + * last 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 @@ -524,7 +524,7 @@ struct bfq_data { * 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 + * num_groups_with_pending_reqs when the first * process of the group remains with no request waiting for * completion. * @@ -532,12 +532,12 @@ struct bfq_data { * 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 + * inactive. Then, when the first 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 + * longer in case a new queue of the entity remains * with no request waiting for completion. */ unsigned int num_groups_with_pending_reqs; diff --git a/block/bfq-wf2q.c b/block/bfq-wf2q.c index ae12c6b2c525..e848d5d2bcdc 100644 --- a/block/bfq-wf2q.c +++ b/block/bfq-wf2q.c @@ -979,19 +979,6 @@ static void __bfq_activate_entity(struct bfq_entity *entity, entity->on_st_or_in_serv = true; } -#ifdef CONFIG_BFQ_GROUP_IOSCHED - if (!bfq_entity_to_bfqq(entity)) { /* bfq_group */ - struct bfq_group *bfqg = - container_of(entity, struct bfq_group, entity); - struct bfq_data *bfqd = bfqg->bfqd; - - if (!entity->in_groups_with_pending_reqs) { - entity->in_groups_with_pending_reqs = true; - bfqd->num_groups_with_pending_reqs++; - } - } -#endif - bfq_update_fin_time_enqueue(entity, st, backshifted); } -- 2.31.1