Skip to content

Commit

Permalink
proc: Use task_is_running() for wchan in /proc/$pid/stat
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kees authored and Peter Zijlstra committed Oct 15, 2021
1 parent cf2a85e commit 4e04615
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions fs/proc/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
}

if (permitted && (!whole || num_threads < 2))
wchan = get_wchan(task);
wchan = !task_is_running(task);
if (!whole) {
min_flt = task->min_flt;
maj_flt = task->maj_flt;
Expand Down Expand Up @@ -606,10 +606,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
*
* This works with older implementations of procps as well.
*/
if (wchan)
seq_puts(m, " 1");
else
seq_puts(m, " 0");
seq_put_decimal_ull(m, " ", wchan);

seq_put_decimal_ull(m, " ", 0);
seq_put_decimal_ull(m, " ", 0);
Expand Down

0 comments on commit 4e04615

Please sign in to comment.