Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp5965465iog; Thu, 23 Jun 2022 08:40:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u8txb9Kg1vtaskFiRJmc4ObTZNOu2SYQRbONYKGJHgh/T9G3f7UW7+qutjdhjMkuF2j7Ur X-Received: by 2002:a05:6402:298e:b0:435:61b0:41a with SMTP id eq14-20020a056402298e00b0043561b0041amr11672308edb.278.1655998800924; Thu, 23 Jun 2022 08:40:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655998800; cv=none; d=google.com; s=arc-20160816; b=Mi3qMNpwTTzPVqO2voIh1K6rqyi9O/dL7cja7sqgD3WqjqR0pM4lh+7C1JBfXWHW+e h6SywP94ogjhZ6SivdxsF6ayeYCbi0TNcs70tI7nPQk8Yk4MuXKhQoJyRnDr9wgxjnNe RpG3k7/jFZmebK9ICjzKzbmgnEcX33wU5iBnWZwBNBRqzdBcE8hw5evgUpcvSztrt5C8 AIxJPjiAywAM1YgyziKx0u5ovMYvCbBbLCm7UL5Yht+w6tKt4vSDhoH8efANT/k3MUeD OYm27uEHW/oxYVzUdRqa+EYXs6lPbyNJexCiCGR98hQ6xxBav/Z8PE/MycccxjPwZGOz NL/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=T+jpYYOmmAX0tTKDun9RBpmd7SAR9bivQfLucksvyjg=; b=emK2CEVhAtOJsbYkmnF8UOnYMf9TxV/EsquuaQulNqGqd3d+nEqDhzUW31J+NLL4bw KB37e1ZxqgV+1CS6ZSYwXr4u6ZD7EXF8YFPOn1anQGL6+fTqrIgEDe2X+Qq2k53bQGtV 4fEzmKq4lSpJnG4SFrXbRiEcu8/EM3kBcpUBiuHG9hocBFRBuhttcp4qSNqRPA/oFXAH EP04GLqsmhthGW6JM5uVEIqOA4g+iexRphoiUYQ2DTU4PMaLwVoBDkn/ZfNSZ8O7Mj6v 7eiZTEg+1XhPL3FHxJ/NRMZWuQHP9dlbOWvFCCvU9unCuZLWaJHYbXgu0Dm27l0TyXxy vOfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qpbQec73; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b15-20020a056402278f00b0043602f1f761si89348ede.340.2022.06.23.08.39.31; Thu, 23 Jun 2022 08:40:00 -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; dkim=pass header.i=@linaro.org header.s=google header.b=qpbQec73; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232090AbiFWPdI (ORCPT + 99 others); Thu, 23 Jun 2022 11:33:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232071AbiFWPdG (ORCPT ); Thu, 23 Jun 2022 11:33:06 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E48D35F5D for ; Thu, 23 Jun 2022 08:33:03 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id s1so28480141wra.9 for ; Thu, 23 Jun 2022 08:33:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=T+jpYYOmmAX0tTKDun9RBpmd7SAR9bivQfLucksvyjg=; b=qpbQec73keboHodaP5ziYd1RpAKQqcvoAXsEGV85lzoEhwbJVc+8syz7um4I/eSFwj +NKnV+I/yjQxjihPuFbbBVB6I4VQNahSOkTUqxSzfBCsHDq6LcpWV0AmkMQ39mR2o6G9 6oVsbtMZVy8rzLpPCyRUvYjzZkkjU1dzqyGvnsb+E9q1fBegaF4ii3uJMHQLYPpd+zjc 3EU024R4KYr2VByEKn+oD14NdJYLSHOEwR7/YVwAkLqMyf+sLzKZjanEI2ID2UbMD76T xnI7ygGgW+dZClKFdVBeecCzS/CLoyqGi9XsSsy+CwFTfIRwrCgFVZcJRuWWsO13Xo1W D/Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=T+jpYYOmmAX0tTKDun9RBpmd7SAR9bivQfLucksvyjg=; b=q3+MdduRUHjnOBHTz6lLyNOFotxRRPkJj4xlOmZQsVlIH94SHxpRz60Pp2HWgNrnZa yqmg6yIPrQG6nPapbU93MXNhyr7eKtv+B8KDbucORKjRDA1pIBc2a+dMUCXJmiflw3UG 61jVTNOUlT9xDoRz9aPgqGXSy1R6bE9Le5kkucV7eXJYzHZmlQoUciTFIw9y8UZKd3kY tr3izJ9DnYXgVocH9304MOTh3zNxp7tTy+cydYRgiuYXo3zq2LSCuvZOLqWx0GgsaMgJ OqL9spN4z8q/IXJ8t3krDtVz43pO5QjDUIKX1DvMsZ5llpSK+YtDnB4o/hJjR/6eTOEV Y/fA== X-Gm-Message-State: AJIora9+2EWiD5vGHp+3NjZxdCCyzT683hN74I3JsKCoo2ydldhACWeZ YTxUqiZf1EIVv/wI9dx89MYBvw== X-Received: by 2002:a05:6000:1789:b0:219:2aa8:7159 with SMTP id e9-20020a056000178900b002192aa87159mr8504373wrg.474.1655998382265; Thu, 23 Jun 2022 08:33:02 -0700 (PDT) Received: from oppo-a74.station (net-37-182-48-184.cust.vodafonedsl.it. [37.182.48.184]) by smtp.gmail.com with ESMTPSA id bw8-20020a0560001f8800b0021b9cfca781sm6885583wrb.45.2022.06.23.08.33.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Jun 2022 08:33:01 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: [PATCH -next v10 3/4] block, bfq: refactor the counting of 'num_groups_with_pending_reqs' From: Paolo Valente In-Reply-To: <20220610021701.2347602-4-yukuai3@huawei.com> Date: Thu, 23 Jun 2022 17:32:59 +0200 Cc: Jan Kara , cgroups@vger.kernel.org, linux-block , Tejun Heo , Jens Axboe , linux-kernel@vger.kernel.org, yi.zhang@huawei.com Content-Transfer-Encoding: quoted-printable Message-Id: <27F2DF19-7CC6-42C5-8CEB-43583EB4AE46@linaro.org> References: <20220610021701.2347602-1-yukuai3@huawei.com> <20220610021701.2347602-4-yukuai3@huawei.com> To: Yu Kuai X-Mailer: Apple Mail (2.3445.104.11) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Sorry for the delay. > Il giorno 10 giu 2022, alle ore 04:17, Yu Kuai ha = scritto: >=20 > 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(). >=20 > The way that bfqg is counted into 'num_groups_with_pending_reqs': >=20 > 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. >=20 > 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. >=20 > 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. >=20 > Signed-off-by: Yu Kuai > Reviewed-by: Jan Kara > --- > block/bfq-iosched.c | 42 ------------------------------------------ > block/bfq-iosched.h | 18 +++++++++--------- > block/bfq-wf2q.c | 19 ++++--------------- > 3 files changed, 13 insertions(+), 66 deletions(-) >=20 > diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c > index 0ec21018daba..03b04892440c 100644 > --- a/block/bfq-iosched.c > +++ b/block/bfq-iosched.c > @@ -970,48 +970,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--; > - } > - } With this part removed, I'm missing how you handle the following sequence of events: 1. a queue Q becomes non busy but still has dispatched requests, so it must not be removed from the counter of queues with pending reqs yet 2. the last request of Q is completed with Q being still idle (non busy). At this point Q must be removed from the counter. It seems to me that this case is not handled any longer Additional comment: if your changes do not cpus the problem above, then this function only invokes __bfq_weights_tree_remove. So what's the point in keeping this function) > - > - /* > - * 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. > - */ I would really love it if you leave this comment. I added it after suffering a lot for a nasty UAF. Of course the first sentence may need to be adjusted if the code that precedes it is to be removed. Thanks, Paolo > __bfq_weights_tree_remove(bfqd, bfqq, > &bfqd->queue_weights_tree); > } > diff --git a/block/bfq-iosched.h b/block/bfq-iosched.h > index de2446a9b7ab..f0fce94583e4 100644 > --- a/block/bfq-iosched.h > +++ b/block/bfq-iosched.h > @@ -496,27 +496,27 @@ struct bfq_data { > struct rb_root_cached queue_weights_tree; >=20 > /* > - * 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 > @@ -525,7 +525,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. > * > @@ -533,12 +533,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 6f36f3fe5cc8..9c2842bedf97 100644 > --- a/block/bfq-wf2q.c > +++ b/block/bfq-wf2q.c > @@ -984,19 +984,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 > @@ -1654,7 +1641,8 @@ void = bfq_add_bfqq_in_groups_with_pending_reqs(struct bfq_queue *bfqq) > if (!entity->in_groups_with_pending_reqs) { > entity->in_groups_with_pending_reqs =3D true; > #ifdef CONFIG_BFQ_GROUP_IOSCHED > - bfqq_group(bfqq)->num_queues_with_pending_reqs++; > + if (!(bfqq_group(bfqq)->num_queues_with_pending_reqs++)) > + bfqq->bfqd->num_groups_with_pending_reqs++; > #endif > } > } > @@ -1666,7 +1654,8 @@ void = bfq_del_bfqq_in_groups_with_pending_reqs(struct bfq_queue *bfqq) > if (entity->in_groups_with_pending_reqs) { > entity->in_groups_with_pending_reqs =3D false; > #ifdef CONFIG_BFQ_GROUP_IOSCHED > - bfqq_group(bfqq)->num_queues_with_pending_reqs--; > + if (!(--bfqq_group(bfqq)->num_queues_with_pending_reqs)) > + bfqq->bfqd->num_groups_with_pending_reqs--; > #endif > } > } > --=20 > 2.31.1 >=20