From: Luka Bai <lukafocus@icloud.com>
To: linux-mm@kvack.org
Cc: "Johannes Weiner" <hannes@cmpxchg.org>,
"Suren Baghdasaryan" <surenb@google.com>,
"Peter Ziljstra" <peterz@infradead.org>,
"Ingo Molnar" <mingo@redhat.com>,
"Juri Lelli" <juri.lelli@redhat.com>,
"Vincent Guittot" <vincent.guittot@linaro.org>,
"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>,
"Andrew Morton" <akpm@linux-foundation.org>,
"David Hildenbrand" <david@kernel.org>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Mike Rapoport" <rppt@kernel.org>,
"Michal Hocko" <mhocko@suse.com>, "Kees Cook" <kees@kernel.org>,
"Tejun Heo" <tj@kernel.org>, "Michal Koutný" <mkoutny@suse.com>,
linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
"Luka Bai" <lukabai@tencent.com>
Subject: [PATCH 6/6] psi: remove psi_bug and moves checking of NR_RUNNING ahead.
Date: Tue, 12 May 2026 14:20:02 +0800 [thread overview]
Message-ID: <20260512-psi_impr-v1-6-2b7f10fdfad5@tencent.com> (raw)
In-Reply-To: <20260512-psi_impr-v1-0-2b7f10fdfad5@tencent.com>
From: Luka Bai <lukabai@tencent.com>
During the accounting of psi states we'd like to do some bug detection
to make it more maintainable. And we use the variable psi_bug to make
it print once. We would like to use printk_deferred_once to replace the
usage of psi_bug since their effect are similar, and this can also
increase the readability.
Also, use likely and unlikely in these bug detection branches.
Signed-off-by: Luka Bai <lukabai@tencent.com>
---
kernel/sched/psi.c | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index 4c4bd134c785..70dd642af5e0 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -141,8 +141,6 @@
#include <linux/psi.h>
#include "sched.h"
-static int psi_bug __read_mostly;
-
DEFINE_STATIC_KEY_FALSE(psi_disabled);
static DEFINE_STATIC_KEY_TRUE(psi_cgroups_enabled);
@@ -262,7 +260,7 @@ static u32 test_states(unsigned int *tasks, u32 state_mask)
if (tasks[NR_RUNNING] && !oncpu)
state_mask |= BIT(PSI_CPU_FULL);
- if (tasks[NR_IOWAIT] || tasks[NR_MEMSTALL] || tasks[NR_RUNNING])
+ if (tasks[NR_RUNNING] || tasks[NR_MEMSTALL] || tasks[NR_IOWAIT])
state_mask |= BIT(PSI_NONIDLE);
return state_mask;
@@ -836,14 +834,13 @@ static void psi_group_change(struct psi_group *group, int cpu,
for (t = 0, m = clear; m; m &= ~(1 << t), t++) {
if (!(m & (1 << t)))
continue;
- if (groupc->tasks[t]) {
+ if (likely(groupc->tasks[t])) {
groupc->tasks[t]--;
- } else if (!psi_bug) {
- printk_deferred(KERN_ERR "psi: task underflow! cpu=%d t=%d tasks=[%u %u %u %u] clear=%x set=%x\n",
+ } else {
+ printk_deferred_once("psi: task underflow! cpu=%d t=%d tasks=[%u %u %u %u] clear=%x set=%x\n",
cpu, t, groupc->tasks[0],
groupc->tasks[1], groupc->tasks[2],
groupc->tasks[3], clear, set);
- psi_bug = 1;
}
}
@@ -908,13 +905,11 @@ static inline struct psi_group *task_psi_group(struct task_struct *task)
static void psi_flags_change(struct task_struct *task, int clear, int set)
{
- if (((task->psi_flags & set) ||
- (task->psi_flags & clear) != clear) &&
- !psi_bug) {
- printk_deferred(KERN_ERR "psi: inconsistent task state! task=%d:%s cpu=%d psi_flags=%x clear=%x set=%x\n",
+ if (unlikely(((task->psi_flags & set) ||
+ (task->psi_flags & clear) != clear))) {
+ printk_deferred_once("psi: inconsistent task state! task=%d:%s cpu=%d psi_flags=%x clear=%x set=%x\n",
task->pid, task->comm, task_cpu(task),
task->psi_flags, clear, set);
- psi_bug = 1;
}
task->psi_flags &= ~clear;
@@ -927,7 +922,7 @@ void psi_task_change(struct task_struct *task, int clear, int set)
u64 now;
bool curr_in_memstall;
- if (!task->need_psi)
+ if (unlikely(!task->need_psi))
return;
psi_flags_change(task, clear, set);
--
2.52.0
prev parent reply other threads:[~2026-05-12 6:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 6:19 [PATCH 0/6] psi: slightly improve performance of psi Luka Bai
2026-05-12 6:19 ` [PATCH 1/6] psi: move curr_in_memstall out of psi_group_change Luka Bai
2026-05-12 6:19 ` [PATCH 2/6] psi: reorganize the psi members for cacheline benifits Luka Bai
2026-05-12 6:19 ` [PATCH 3/6] psi: use prefetch to preread the parent groupc Luka Bai
2026-05-12 6:20 ` [PATCH 4/6] psi: do not call record_times when the state is not changed Luka Bai
2026-05-12 6:20 ` [PATCH 5/6] psi: add psi group for the root cgroup Luka Bai
2026-05-12 6:20 ` Luka Bai [this message]
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=20260512-psi_impr-v1-6-2b7f10fdfad5@tencent.com \
--to=lukafocus@icloud.com \
--cc=akpm@linux-foundation.org \
--cc=bsegall@google.com \
--cc=cgroups@vger.kernel.org \
--cc=david@kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=hannes@cmpxchg.org \
--cc=juri.lelli@redhat.com \
--cc=kees@kernel.org \
--cc=kprateek.nayak@amd.com \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=lukabai@tencent.com \
--cc=mgorman@suse.de \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=mkoutny@suse.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=tj@kernel.org \
--cc=vbabka@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox