All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Peng Huang" <penghuang@google.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Ingo Molnar" <mingo@redhat.com>, "Will Deacon" <will@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>,
	"Juri Lelli" <juri.lelli@redhat.com>,
	"Vincent Guittot" <vincent.guittot@linaro.org>
Cc: "Waiman Long" <longman@redhat.com>,
	"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Ben Segall" <bsegall@google.com>, "Mel Gorman" <mgorman@suse.de>,
	"Valentin Schneider" <vschneid@redhat.com>,
	"K Prateek Nayak" <kprateek.nayak@amd.com>,
	"John Stultz" <jstultz@google.com>,
	"Suren Baghdasaryan" <surenb@google.com>,
	linux-mm@kvack.org
Subject: Re: [RFC PATCH v2 4/6] sched: Apply rwsem holder boost to the fair load weight
Date: Wed, 02 Dec 2026 06:28:05 +0000	[thread overview]
Message-ID: <sashiko-outbox-244970@kernel.org> (raw)
In-Reply-To: <20261201062738.1047159-5-penghuang@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] sched/fair: unrescaled PELT load_avg in
  rwsem_boost_clear_fair()
--

commit 76872673ec3d9e5160e5c3b26fe2c8d22b817c8c
Author: Peng Huang <penghuang@google.com>

sched: Apply rwsem holder boost to the fair load weight

This commit adds per-task rwsem boost priority tracking and applies it to
the fair load weight of rwsem holders when higher-priority waiters are
queued.

> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 2d9d3d6862619..f755ee810ce26 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -8199,6 +8199,102 @@ static inline void update_curr_eevdf(struct cfs_rq *cfs_rq)
>  	update_curr(cfs_rq_of(cfs_rq->curr));
>  }
>  
> +#ifdef CONFIG_RWSEM_SCHED_BOOST
[ ... ]
> +/*
> + * Clear @p's rwsem boost when it leaves fair_sched_class, so unlocking
> + * outside CFS never leaves a stale weight behind.  This runs before
> + * detach_task_cfs_rq(), so handle PELT like detach_entity_cfs_rq().
> + */
> +static void rwsem_boost_clear_fair(struct rq *rq, struct task_struct *p)
> +{
> +	struct sched_entity *se = &p->se;
> +
> +	lockdep_assert_rq_held(rq);
> +
> +	if (!rwsem_boost_active(p))
> +		return;
> +
> +	/* Wakeup still pending: no cfs_rq holds this load yet. */
> +	if (!se->avg.last_update_time) {
> +		WRITE_ONCE(p->rwsem_boost.prio, MAX_PRIO);
> +		set_load_weight(p, false);
> +		return;
> +	}

[Severity: Medium]
Does calling set_load_weight(p, false) when !se->avg.last_update_time
leave se->avg.load_avg scaled to the boosted weight while p->se.load is
lowered back to the unboosted weight?

When a boosted sleeping or waking task migrates, migrate_task_rq_fair()
calls remove_entity_load_avg(se) and sets se->avg.last_update_time = 0
while se->avg.load_avg remains scaled to the boosted weight.  If the task
then leaves fair_sched_class (for example via rt_mutex_setprio()),
set_load_weight(p, false) skips reweight_entity() and does not rescale
se->avg.load_avg from se->avg.load_sum.

When the task later returns to fair_sched_class, switched_to_fair() ->
attach_entity_load_avg() adds the stale boosted se->avg.load_avg to
cfs_rq->avg and divides by the now-unboosted se_weight(se), inflating
se->avg.load_sum past LOAD_AVG_MAX:

kernel/sched/fair.c:attach_entity_load_avg() {
	...
	se->avg.load_sum = se->avg.load_avg * divider;
	if (se_weight(se) < se->avg.load_sum)
		se->avg.load_sum = div_u64(se->avg.load_sum, se_weight(se));
	else
		se->avg.load_sum = 1;

	enqueue_load_avg(cfs_rq, se);
	...
}

Rescaling se->avg.load_avg from se_weight(se) * se->avg.load_sum /
get_pelt_divider(&se->avg) in this branch (or letting reweight_entity()
handle the !se->avg.last_update_time case without touching cfs_rq->avg)
would keep se->avg.load_avg consistent with the restored weight.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201062738.1047159-1-penghuang@google.com?part=4


  reply	other threads:[~2026-12-02  6:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  6:27 [RFC PATCH v2 0/6] rwsem: priority boost for holders blocking high-priority waiters Peng Huang
2026-12-01  6:27 ` [RFC PATCH v2 1/6] locking/rwsem: Track held rwsems per task Peng Huang
2026-12-01  6:27 ` [RFC PATCH v2 2/6] btrfs: untrack i_rwsem before io_uring encoded read completion Peng Huang
2026-12-01  8:40   ` Christoph Hellwig
2026-12-01 14:43     ` Steven Rostedt
2026-12-01 17:41     ` Peng Huang
2026-12-02  6:20       ` Christoph Hellwig
2026-12-01  6:27 ` [RFC PATCH v2 3/6] locking/rwsem: Publish the top waiter priority Peng Huang
2026-12-01  6:27 ` [RFC PATCH v2 4/6] sched: Apply rwsem holder boost to the fair load weight Peng Huang
2026-12-02  6:28   ` sashiko-bot [this message]
2026-12-01  6:27 ` [RFC PATCH v2 5/6] sched/fair: Boost rwsem holders with contended high-priority waiters Peng Huang
2026-12-01  6:27 ` [RFC PATCH v2 6/6] locking/rwsem: Add KUnit tests for scheduler priority boost Peng Huang
2026-12-02  6:28   ` sashiko-bot
2026-12-01 20:43 ` [RFC PATCH v2 0/6] rwsem: priority boost for holders blocking high-priority waiters Kayra Cizmeci
2026-12-01 21:10   ` Peng Huang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-244970@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=boqun@kernel.org \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=jstultz@google.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-mm@kvack.org \
    --cc=longman@redhat.com \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=penghuang@google.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=surenb@google.com \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.