Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp815850rdg; Wed, 11 Oct 2023 06:26:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHclsKBz0FwWcNppyZr/1Sex63skETxP1kI4QlxODkKZMaTaZxkb0kdlColKS01OMRnK/Yk X-Received: by 2002:a17:90b:30cb:b0:279:cea:cfa9 with SMTP id hi11-20020a17090b30cb00b002790ceacfa9mr17911290pjb.21.1697030788469; Wed, 11 Oct 2023 06:26:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697030788; cv=none; d=google.com; s=arc-20160816; b=yr9ggOrgm7XTqmkIJLEFcVusMkSjMKGCCq6LS4gvlDBplzaZgCUIjK13LXeruyVi0O 3QveHI+Ocmsdg5HoijJDm0zES6EQs65ti1LO51b2JaXJGKwlSLsShRT+k8v7eaSp4HhT /FeYA32HrO8cwFG/rlwvDk4TFqDira60gWiMS+TRhKwLssnWHHMfUwC+q+fXqavlrqMc wnGjf6zEwYnmQGOEF4z50wyxRQlOQaJSUIbbGljJLYG2SoETlvbw0NXTDeK8kOuOVA8C hNBNxyKjhLhVB3da9Vat/UwS7eDXL+FJ/mRqt3qoVFnn4Gt/HHxVR7Qdn6OEyJhWmWGn 0lLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=fjWlCAr02qhHiPzFN+j8xSGNeytzdn+jfQfHwKa+nhM=; fh=XpiPn/MVFfhC5CRzn5cT5q5iGdWPmFDEHOvC4FluDcY=; b=J6ke7Wq1oCsIIFcIwCw2wgsAyNsMBANrQU3rmsNVrxfQEyb+AMnAq2GqPbWoaqeGcB mEofltLezKVWSavLFFlQUKxrvxzVWIl/FnilBhsz7by1nqda47vURETo9hyBJ9PCFCkZ jeA9OoXxIU7tZCzA9oLGNmi+5KuhnSnrutyFyQgpjdXTitLB2bcrj+/g2F0oVMD8GVdh IUHqy5iD/yH/KZBEiZzfe3p/bnPM9K/k9ckKKrDtvxf3PICNn2dAbohQMpPyPnxXkQHA pfnd19pM9wBhy1Q820vNzh5c1JBJdmyG6BKhITvohxFZYaZurkGf7mblNh3C7DZuAGCf IXOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=PNQrCO1q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id y22-20020a17090ad71600b0027d0c3507eesi855040pju.32.2023.10.11.06.26.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 06:26:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=PNQrCO1q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D4A5E806AFC0; Wed, 11 Oct 2023 06:25:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232297AbjJKNZl (ORCPT + 99 others); Wed, 11 Oct 2023 09:25:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232085AbjJKNZk (ORCPT ); Wed, 11 Oct 2023 09:25:40 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B51A92 for ; Wed, 11 Oct 2023 06:25:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=fjWlCAr02qhHiPzFN+j8xSGNeytzdn+jfQfHwKa+nhM=; b=PNQrCO1qldo1XHBEfFbOw2F3K+ pJ2Mn3AGYevAa6PJALfrvv2J4i2qL6wV7mRRLq7pjNH4+BrPl18Kkj7t6EV4NFn0Wnngs3fBFqCHf y6BiozmkpXAp6qwd68NwBHV4cUm0ScJQV499k0wjyrF8dqLyCb2/Uaq9vIoEb5YzkBi7l05s8Plpo 1dqCrXhklg4Me5o9neFzilft17ezyJrd52P0BTUf9usM8Ybm4Rdm0Z1Etla5j9dYfOjvZTnyRJkEh sSMKe5Wts7fnBb3Sw+nt5G/vtY9sJJd1JCQDpNo+Rqg6hajXAl8VZUvej8UgGrQ/X8ineVODPvML8 U5oJ5Kcw==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qqZCq-00AzE3-GF; Wed, 11 Oct 2023 13:24:56 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 2C6FA30036C; Wed, 11 Oct 2023 15:24:56 +0200 (CEST) Date: Wed, 11 Oct 2023 15:24:56 +0200 From: Peter Zijlstra To: Abel Wu Cc: mingo@kernel.org, vincent.guittot@linaro.org, linux-kernel@vger.kernel.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, corbet@lwn.net, qyousef@layalina.io, chris.hyser@oracle.com, patrick.bellasi@matbug.net, pjt@google.com, pavel@ucw.cz, qperret@google.com, tim.c.chen@linux.intel.com, joshdon@google.com, timj@gnu.org, kprateek.nayak@amd.com, yu.c.chen@intel.com, youssefesmat@chromium.org, joel@joelfernandes.org, efault@gmx.de, tglx@linutronix.de Subject: Re: [PATCH 03/15] sched/fair: Add lag based placement Message-ID: <20231011132456.GO14330@noisy.programming.kicks-ass.net> References: <20230531115839.089944915@infradead.org> <20230531124603.794929315@infradead.org> <87f1feec-1be5-4d24-a206-e30238072ae1@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87f1feec-1be5-4d24-a206-e30238072ae1@bytedance.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 11 Oct 2023 06:25:49 -0700 (PDT) On Wed, Oct 11, 2023 at 08:00:22PM +0800, Abel Wu wrote: > On 5/31/23 7:58 PM, Peter Zijlstra Wrote: > > /* > > + * If we want to place a task and preserve lag, we have to > > + * consider the effect of the new entity on the weighted > > + * average and compensate for this, otherwise lag can quickly > > + * evaporate. > > + * > > + * Lag is defined as: > > + * > > + * lag_i = S - s_i = w_i * (V - v_i) > > + * > > + * To avoid the 'w_i' term all over the place, we only track > > + * the virtual lag: > > + * > > + * vl_i = V - v_i <=> v_i = V - vl_i > > + * > > + * And we take V to be the weighted average of all v: > > + * > > + * V = (\Sum w_j*v_j) / W > > + * > > + * Where W is: \Sum w_j > > + * > > + * Then, the weighted average after adding an entity with lag > > + * vl_i is given by: > > + * > > + * V' = (\Sum w_j*v_j + w_i*v_i) / (W + w_i) > > + * = (W*V + w_i*(V - vl_i)) / (W + w_i) > > + * = (W*V + w_i*V - w_i*vl_i) / (W + w_i) > > + * = (V*(W + w_i) - w_i*l) / (W + w_i) > > + * = V - w_i*vl_i / (W + w_i) > > + * > > + * And the actual lag after adding an entity with vl_i is: > > + * > > + * vl'_i = V' - v_i > > + * = V - w_i*vl_i / (W + w_i) - (V - vl_i) > > + * = vl_i - w_i*vl_i / (W + w_i) > > + * > > + * Which is strictly less than vl_i. So in order to preserve lag > > Maybe a stupid question, but why vl'_i < vl_i? Since vl_i can be negative. So the below doesn't care about the sign, it simply inverts this relation to express vl_i in vl'_i: > > + * we should inflate the lag before placement such that the > > + * effective lag after placement comes out right. > > + * > > + * As such, invert the above relation for vl'_i to get the vl_i > > + * we need to use such that the lag after placement is the lag > > + * we computed before dequeue. > > + * > > + * vl'_i = vl_i - w_i*vl_i / (W + w_i) > > + * = ((W + w_i)*vl_i - w_i*vl_i) / (W + w_i) > > + * > > + * (W + w_i)*vl'_i = (W + w_i)*vl_i - w_i*vl_i > > + * = W*vl_i > > + * > > + * vl_i = (W + w_i)*vl'_i / W And then we obtain the scale factor: (W + w_i)/W, which is >1, right? As such, that means that vl'_i must be smaller than vl_i in the absolute sense, irrespective of sign.