From nobody Mon Sep 07 08:42:41 2026 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hdgYs6j03z6rhpx for ; Mon, 07 Sep 2026 08:42:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hdgYs5Rszz44Zy for ; Mon, 07 Sep 2026 08:42:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1788770561; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hSFUeRN5a69mMMLlX27+xg4KY0heBE4dVLmXeP0trzQ=; b=adwM0M+mFcAx+pQEl9IYDVL5SmxARa3vHrI6OsKUjQe6k1uyCiYB3X3tkXF04XUeVckUya S9ILxEvajGQ+d1EfybUdXgrPQHCmNZqHpLijk5EW+UwDUUhoOfU4NcX3q72WfFrWkPnWdU erRKm5OYtxMMVpZzn8IQXBge26GsaDLI5Ch+XT/ujfLXxEAwttIJ0ZJFQE6yG7JWKApaEi TZOT0aLq/9cB0h0ayZeZuyNijLBVyhlNoPwbCuNN5AeXTu0HyFW2jzyVDYz7zHfgGSKyRU cym69AB8VhKLqRePgMgsyxFy+6+KHUUhWnVSZGb7z1iUruTVtEWZbrj5h5ZZ0w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1788770561; a=rsa-sha256; cv=none; b=iqUqKglHEZDyVY7a/korjfJG5b5w0EodSUvovgMXwgdrR+K2YDTjBD6oh+jyWbOH7af3Jm Odc56gcJy5RFc/djFD5HbxrpDKPrRf/BrrWKxpyMorlZUfcZ7onLn8rPzQ4aoy1m72Sk/y Pr09QY7KywO3EnZapQpMTXKBk6hLmVfd3wwBT6JP0+J4mNELwvY+ZqsGpXlASFKKhTQmiP lmvf1sGzTnYfvYwr0q0Q5e5DGJ9eaLQtTZamH0V/LDzKFAf/eSjGee+kIAt5QGhp1e6oqF z3UIqx/X0FtRhQeTdZclSs3T/JYbCsknyICNK2vBacbURCbT7Smd4euqwtUlGQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1788770561; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hSFUeRN5a69mMMLlX27+xg4KY0heBE4dVLmXeP0trzQ=; b=KjlD3vYHsuigshMlPlVCPuBIETCfMBCuB5AI985BWOUSJBaLe2Xq7bVUyncyv7e4YLXuGc h3aBWanhCk2iJnV08aVK6jyeizLZhTh1o9ROkyJUywaqhvFmL259KnneJ3PUqMjJRLgC7u Y2dc5P/chFnP2XY8RXzXVWFuLAsIppOYUkXtx8aThwsxmg+2donwq/idQrIvNBNtxJ38VH 12u5980de4feKwYtUDGNfK2VV+Z2nkjoFwlaxqDA/SD50FBzChg4noh0lNE/ltoFcQSLh7 beSXUycFuoRlyfU41966Ne01C1ZZtiHkmp9V9mFOAtEfpPbNn1oRPZUa94w9Tg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hdgYs3JGwz18sB for ; Mon, 07 Sep 2026 08:42:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3ed4f by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 07 Sep 2026 08:42:41 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: 5db755a864d9 - stable/15 - sched_4bsd: Fix conflating priority of differently-niced CPU-bound threads List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 5db755a864d9fd7ba9d7ad0753072a900dd8ffa5 Auto-Submitted: auto-generated Date: Mon, 07 Sep 2026 08:42:41 +0000 Message-Id: <6a9e7901.3ed4f.696d54aa@gitrepo.freebsd.org> The branch stable/15 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=5db755a864d9fd7ba9d7ad0753072a900dd8ffa5 commit 5db755a864d9fd7ba9d7ad0753072a900dd8ffa5 Author: Olivier Certner AuthorDate: 2026-06-13 13:09:42 +0000 Commit: Olivier Certner CommitDate: 2026-09-07 08:41:09 +0000 sched_4bsd: Fix conflating priority of differently-niced CPU-bound threads We introduced (PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE) as part of ESTCPULIM() in commit eebc148f25c3 ("sched_4bsd: ESTCPULIM(): Allow any value in the timeshare range") in order to use more than a fixed number (40) of all the available priority levels in the timeshare range (136 before the 256-queue runqueue work, 224 now) to take into account the number of ticks a thread has run ('ts_estcpu'). In the computation of a new thread's priority (resetpriority()), in addition to the "ticks running" contribution, the final priority also includes a "nice" value contribution. The final value is clamped into the [PRI_MIN_TIMESHARE; PRI_MAX_TRIMESHARE] range. Problem is that the new "ticks running" contribution now can lead to a computed priority value that exceeds PRI_MAX_TRIMESHARE, and is thus finally clamped to PRI_MAX_TIMESHARE, which becomes an alias for all out-of-bound values. In particular, this can conflate CPU-hungry threads. With at least two of them competing on the same CPU, with an increase of 'ts_estcpu' of ~64 per second (stathz being 127) and the minimal decay of 4/5 (load average 2 or more), both threads will easily reach the current clamping of 224 (+ PRI_MIN_TIMESHARE), and be considered indifferently by the scheduler. Fix this problem by ensuring that the maximum contribution of 'ts_estcpu' (via ESTCPULIM()) cannot exceed the timeshare range of priorities when the nice contribution is added to it, so the nice contribution continues to have an effect on CPU-bound threads. Introduction of the nice term in ESTCPULIM() (then NICE_WEIGHT * PRIO_MAX) has been done in commit bdf423572ee3 ("Scheduler fixes equivalent to the ones logged in the following NetBSD commit...") and does not appear to have made any real sense even then. Fixes: bdf423572ee3 ("Scheduler fixes equivalent to the ones logged in the following NetBSD commit...") Fixes: eebc148f25c3 ("sched_4bsd: ESTCPULIM(): Allow any value in the timeshare range") MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D57826 (cherry picked from commit e8dec0038bd95f6d940afa19b4d101f466280fd6) --- sys/kern/sched_4bsd.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sys/kern/sched_4bsd.c b/sys/kern/sched_4bsd.c index 53e32026029d..f86dcda218a4 100644 --- a/sys/kern/sched_4bsd.c +++ b/sys/kern/sched_4bsd.c @@ -78,8 +78,8 @@ #define NICE_WEIGHT 1 /* Priorities per nice level. */ #define ESTCPULIM(e) \ min((e), INVERSE_ESTCPU_WEIGHT * \ - (NICE_WEIGHT * (PRIO_MAX - PRIO_MIN) + \ - PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE) \ + (PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE - \ + (PRIO_MAX - PRIO_MIN) * NICE_WEIGHT) \ + INVERSE_ESTCPU_WEIGHT - 1) #define TS_NAME_LEN (MAXCOMLEN + sizeof(" td ") + sizeof(__XSTRING(UINT_MAX))) @@ -596,11 +596,13 @@ resetpriority(struct thread *td) if (td->td_pri_class != PRI_TIMESHARE) return; - newpriority = PUSER + + newpriority = PRI_MIN_TIMESHARE + td_get_sched(td)->ts_estcpu / INVERSE_ESTCPU_WEIGHT + NICE_WEIGHT * (td->td_proc->p_nice - PRIO_MIN); - newpriority = min(max(newpriority, PRI_MIN_TIMESHARE), - PRI_MAX_TIMESHARE); + KASSERT(PRI_MIN_TIMESHARE <= newpriority && + newpriority <= PRI_MAX_TIMESHARE, + ("Out-of-bounds priority, probably 'ts_estcpu' not clamped " + "correctly, see ESTCPULIM()")); sched_user_prio(td, newpriority); }