Skip to content

Commit 4e04615

Browse files
keesPeter Zijlstra
authored andcommitted
proc: Use task_is_running() for wchan in /proc/$pid/stat
The implementations of get_wchan() can be expensive. The only information imparted here is whether or not a process is currently blocked in the scheduler (and even this doesn't need to be exact). Avoid doing the heavy lifting of stack walking and just report that information by using task_is_running(). Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/20211008111626.211281780@infradead.org
1 parent cf2a85e commit 4e04615

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

‎fs/proc/array.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
541541
}
542542

543543
if (permitted && (!whole || num_threads < 2))
544-
wchan = get_wchan(task);
544+
wchan = !task_is_running(task);
545545
if (!whole) {
546546
min_flt = task->min_flt;
547547
maj_flt = task->maj_flt;
@@ -606,10 +606,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
606606
*
607607
* This works with older implementations of procps as well.
608608
*/
609-
if (wchan)
610-
seq_puts(m, " 1");
611-
else
612-
seq_puts(m, " 0");
609+
seq_put_decimal_ull(m, " ", wchan);
613610

614611
seq_put_decimal_ull(m, " ", 0);
615612
seq_put_decimal_ull(m, " ", 0);

0 commit comments

Comments
 (0)