Skip to content

Commit a20d6f6

Browse files
Sebastian Andrzej SiewiorKAGA-KOKO
Sebastian Andrzej Siewior
authored andcommitted
signal: Add a proper comment about preempt_disable() in ptrace_stop()
Commit 53da1d9 ("fix ptrace slowness") added a preempt-disable section between read_unlock() and the following schedule() invocation without explaining why it is needed. Replace the existing contentless comment with a proper explanation to clarify that it is not needed for correctness but for performance reasons. Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: Oleg Nesterov <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 0bb80ec commit a20d6f6

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

kernel/signal.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,10 +2329,22 @@ static int ptrace_stop(int exit_code, int why, unsigned long message,
23292329
do_notify_parent_cldstop(current, false, why);
23302330

23312331
/*
2332-
* Don't want to allow preemption here, because
2333-
* sys_ptrace() needs this task to be inactive.
2332+
* The previous do_notify_parent_cldstop() invocation woke ptracer.
2333+
* One a PREEMPTION kernel this can result in preemption requirement
2334+
* which will be fulfilled after read_unlock() and the ptracer will be
2335+
* put on the CPU.
2336+
* The ptracer is in wait_task_inactive(, __TASK_TRACED) waiting for
2337+
* this task wait in schedule(). If this task gets preempted then it
2338+
* remains enqueued on the runqueue. The ptracer will observe this and
2339+
* then sleep for a delay of one HZ tick. In the meantime this task
2340+
* gets scheduled, enters schedule() and will wait for the ptracer.
23342341
*
2335-
* XXX: implement read_unlock_no_resched().
2342+
* This preemption point is not bad from a correctness point of
2343+
* view but extends the runtime by one HZ tick time due to the
2344+
* ptracer's sleep. The preempt-disable section ensures that there
2345+
* will be no preemption between unlock and schedule() and so
2346+
* improving the performance since the ptracer will observe that
2347+
* the tracee is scheduled out once it gets on the CPU.
23362348
*/
23372349
preempt_disable();
23382350
read_unlock(&tasklist_lock);

0 commit comments

Comments
 (0)