From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout12.his.huawei.com (canpmsgout12.his.huawei.com [113.46.200.227]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7202C33769F for ; Fri, 9 Jan 2026 08:40:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.227 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767948047; cv=none; b=jwlk7j53K9PPTGgveMZVnN+oBsF1U6VXdCXApZuiXK8OxcqBrdulox0zA8a6MBAV0YxOdOeOMfx6W6Tn1vHjZSzGte/+O4Dc2DA6BK8zKJ/XqM0PrnljrgYQI5/M3VlelZ2b0z/1+VT9lJH/qJbYT8GACUogbFPhZEVfssCxeGc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767948047; c=relaxed/simple; bh=xMmFvNFnbEaSFRwCscvODtj5a90vuCK8lSUr/D0ipLw=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=pWWVpge3id4otfxGlDtGA7ZN6Vccr0EDSaan4ryHGu8GjoUEpc1rJ9wWaxwXAwQi4Hvi4ZHVe3bPs1A2mhp8pwBZI8xEj4PuE7GIsDYT+eO0rzrIobR9kA538KlKZ/FQeSv8r0C9Y8fxQtWYAUrAmgx4RPOyG6W/S/vsbPaFRks= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=Ozn/2F8F; arc=none smtp.client-ip=113.46.200.227 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="Ozn/2F8F" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=VhTSgtVt6ZTJXViv4EjP/is2HxtQEPrYSFSwCr/oLJI=; b=Ozn/2F8FmQenaJ+SvTXClgH9lXc1rQgMQ4rgS3bIoJXwdY9ZrK7P8LrxDcfCONeBkDDI9qb0U y3RLe8zpf7ih6F9ZU3oSu67X3efpW90VzH+eBul3e159mj8oEllLTw7HFlw7txrha5Q4d9JSLip 0aL+JFrHGgjnrWgmKcJ15Qs= Received: from mail.maildlp.com (unknown [172.19.163.15]) by canpmsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dnZsG5JjFznTW1; Fri, 9 Jan 2026 16:37:38 +0800 (CST) Received: from dggemv706-chm.china.huawei.com (unknown [10.3.19.33]) by mail.maildlp.com (Postfix) with ESMTPS id D958140539; Fri, 9 Jan 2026 16:40:41 +0800 (CST) Received: from kwepemq100012.china.huawei.com (7.202.195.195) by dggemv706-chm.china.huawei.com (10.3.19.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 9 Jan 2026 16:40:41 +0800 Received: from [10.67.111.196] (10.67.111.196) by kwepemq100012.china.huawei.com (7.202.195.195) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 9 Jan 2026 16:40:41 +0800 Message-ID: <23574b3c-e990-45bc-b3f5-8664781adddf@huawei.com> Date: Fri, 9 Jan 2026 16:40:40 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] sched/fair: Fix vruntime drift by preventing double lag scaling during reweight To: K Prateek Nayak , , , , , , , , , , CC: , References: <20251226001731.3730586-1-quzicheng@huawei.com> <0615d2c6-c963-46ff-9088-d85e3821eec8@amd.com> From: Zicheng Qu In-Reply-To: <0615d2c6-c963-46ff-9088-d85e3821eec8@amd.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemq100012.china.huawei.com (7.202.195.195) Hi Prateek, On 1/9/2026 12:50 PM, K Prateek Nayak wrote: > If I'm not mistaken, the problem is that we'll see "curr->on_rq" and > then do: > > if (curr && curr->on_rq) > load += scale_load_down(curr->load.weight); > > lag *= load + scale_load_down(se->load.weight); > > > which shouldn't be the case since we are accounting "se" twice when > it is also the "curr" and avg_vruntime() would have also accounted it > already since "curr->on_rq" and then we do everything twice for "se". Thanks for the analysis — I agree your concern is reasonable, but I think the issue here is slightly different from "accounting se twice", but a semantic mismatch in how place_entity() is used. place_entity() is meant to compensate lag for entities being inserted into the runqueue, accounting for the effect of a new entity on the weighted average vruntime. That assumption holds when an se is joining the rq. However, when se == cfs_rq->curr, the entity never left the runqueue and avg_vruntime() has not changed, so applying enqueue-style lag scaling is not appropriate. > I'm wondering if instead of adding a flag, we can do: Yes, I totally agree that adding a new flag is unnecessary. We can handle this directly in place_entity() by skipping lag scaling in case of `se == cfs_rq->curr`, for example: diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index da46c3164537..1b279bf43f38 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5123,6 +5123,15 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)                 lag = se->vlag; +              /* +               * place_entity() compensates lag for entities being inserted into the +               * runqueue. When se == cfs_rq->curr, the entity never left the rq and +               * avg_vruntime() did not change, so enqueue-style lag scaling does not +               * apply. +               */ +              if (se == cfs_rq->curr) +                      goto skip_lag_scale; +                 /*                  * If we want to place a task and preserve lag, we have to                  * consider the effect of the new entity on the weighted @@ -5185,6 +5194,7 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)                 lag = div_s64(lag, load);         } +skip_lag_scale:         se->vruntime = vruntime - lag;         if (se->rel_deadline) { Best regards, Zicheng