Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp565932pxj; Tue, 18 May 2021 09:22:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9ED1CL6G/8XO5LdLsPZ8sxuClixu1iOBQOogT20d1pITi5iVVsW1NYaM47GGh9+ZabNs7 X-Received: by 2002:a02:ab87:: with SMTP id t7mr6337560jan.57.1621354920232; Tue, 18 May 2021 09:22:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621354920; cv=none; d=google.com; s=arc-20160816; b=eZ5G1cAoM965NR2Ou3E3vDj1UJX6Zqz4AsH1mI3OnekmuptuLXIVFCUikA4QxSOahs pGf3znNlN1wZ5Q7JGAAuhJFLsncLIBGTy2xafKGvt/3sGpfo3eANST87fsPJinzwmSKI 9Yusn0IZyTNCrrVTsMg0S4u2+yT1Pl+qdyEcVX7GEazxyYL1LMrUUe3c87CaBOo0Ch2a sdUeFO8pcE2mlPTI31uSa4Eq4EFptat5wQETraStI/NcxFwpQby1jYlZnqigWegl3DY6 7/yZLe2dL0CKGXi00oVMlumTvgL4RSsTL0nnz7rtbAaFoCLrAFdDBZ49nSRo5354HNm0 slAA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=S1CSoEDdhKS51DS/98ZXmM+LjwRRKDVvU+lRWlSC67g=; b=BIldLJH/H/w42Czeb18dOZjGwor7pMIR/ymjNdkQNebqyoxRU91f409zrQr82Bt9Bf L4o5NOIslZr7X3DdcNavvxb5rHLkf5cgLVA0xfT2OzUCwzwQu2MbdBUClhcEf9UC9H+6 1c1vYTZ4cSvQ+lCVb2lPDdp644wh4/ni7+V3iA1pW63cK7TMGQnQGJ1VpjAzGLntFW/M h3JeipV/DW7qEr/wHTHi93UEwduyodbV9bddv2U1WTkA6LIXuyOrBcDgfE4qsbXF9RNr 7P6qqOPxNpKcII0B4TkghZtABoHuKkdG3kcQugJ0dMgETeC69zJady8eqxP6BpeEkOsc ZYxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=i9dgcqYF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x4si11941338ilm.150.2021.05.18.09.21.30; Tue, 18 May 2021 09:22:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=i9dgcqYF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345921AbhEQQA1 (ORCPT + 99 others); Mon, 17 May 2021 12:00:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:50168 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344051AbhEQPkN (ORCPT ); Mon, 17 May 2021 11:40:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8CE4C6194B; Mon, 17 May 2021 14:41:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262512; bh=gOuhFINJlzt8XFWTVxxmGAwRNy6+ka+gZ1gF4QnJRm8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i9dgcqYFKwEItJoyiInUYAtF26Ym+v2fqUk9A9U1MR4ASKHdSWsp2PDSX+hItwORh 6SzRXJ6M7lD6XEn2I/igXNYqoic8jlTQ5nYVfjIgc2C6mifPlUzIvhj4+1SukaE/U2 EYI/9ixfSlBl44mnCy+xgvftsgV28WgkvTrKVdBM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tejun Heo , Dan Schatzberg , Jens Axboe Subject: [PATCH 5.10 204/289] blk-iocost: fix weight updates of inner active iocgs Date: Mon, 17 May 2021 16:02:09 +0200 Message-Id: <20210517140311.978383361@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tejun Heo commit e9f4eee9a0023ba22db9560d4cc6ee63f933dae8 upstream. When the weight of an active iocg is updated, weight_updated() is called which in turn calls __propagate_weights() to update the active and inuse weights so that the effective hierarchical weights are update accordingly. The current implementation is incorrect for inner active nodes. For an active leaf iocg, inuse can be any value between 1 and active and the difference represents how much the iocg is donating. When weight is updated, as long as inuse is clamped between 1 and the new weight, we're alright and this is what __propagate_weights() currently implements. However, that's not how an active inner node's inuse is set. An inner node's inuse is solely determined by the ratio between the sums of inuse's and active's of its children - ie. they're results of propagating the leaves' active and inuse weights upwards. __propagate_weights() incorrectly applies the same clamping as for a leaf when an active inner node's weight is updated. Consider a hierarchy which looks like the following with saturating workloads in AA and BB. R / \ A B | | AA BB 1. For both A and B, active=100, inuse=100, hwa=0.5, hwi=0.5. 2. echo 200 > A/io.weight 3. __propagate_weights() update A's active to 200 and leave inuse at 100 as it's already between 1 and the new active, making A:active=200, A:inuse=100. As R's active_sum is updated along with A's active, A:hwa=2/3, B:hwa=1/3. However, because the inuses didn't change, the hwi's remain unchanged at 0.5. 4. The weight of A is now twice that of B but AA and BB still have the same hwi of 0.5 and thus are doing the same amount of IOs. Fix it by making __propgate_weights() always calculate the inuse of an active inner iocg based on the ratio of child_inuse_sum to child_active_sum. Signed-off-by: Tejun Heo Reported-by: Dan Schatzberg Fixes: 7caa47151ab2 ("blkcg: implement blk-iocost") Cc: stable@vger.kernel.org # v5.4+ Link: https://lore.kernel.org/r/YJsxnLZV1MnBcqjj@slm.duckdns.org Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/blk-iocost.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -1023,7 +1023,17 @@ static void __propagate_weights(struct i lockdep_assert_held(&ioc->lock); - inuse = clamp_t(u32, inuse, 1, active); + /* + * For an active leaf node, its inuse shouldn't be zero or exceed + * @active. An active internal node's inuse is solely determined by the + * inuse to active ratio of its children regardless of @inuse. + */ + if (list_empty(&iocg->active_list) && iocg->child_active_sum) { + inuse = DIV64_U64_ROUND_UP(active * iocg->child_inuse_sum, + iocg->child_active_sum); + } else { + inuse = clamp_t(u32, inuse, 1, active); + } iocg->last_inuse = iocg->inuse; if (save) @@ -1040,7 +1050,7 @@ static void __propagate_weights(struct i /* update the level sums */ parent->child_active_sum += (s32)(active - child->active); parent->child_inuse_sum += (s32)(inuse - child->inuse); - /* apply the udpates */ + /* apply the updates */ child->active = active; child->inuse = inuse;