Re: [PATCH v4] do_wait: make PIDTYPE_PID case O(1) instead of O(n)

From: Jim Newsome
Date: Fri Mar 12 2021 - 11:52:32 EST



On 3/12/21 10:41, Oleg Nesterov wrote:
> On 03/11, Jim Newsome wrote:
>> +
>> + if (target && is_effectively_child(wo, ptrace, target)) {
>> + retval = wait_consider_task(wo, ptrace, target);
> No, this is not right... You need to check target->ptrace != 0.

Shoot; got lost in the shuffle. Sorry about that and thanks for catching!

> I know that Eric suggests to not use thread_group_leader() and I won't argue
> even if I don't really agree.
>
> Up to you, but to me something like
>
> do_wait_pid()
> {
> target = pid_task(wo->wo_pid, PIDTYPE_PID);
>
> if (!target)
> return 0;
>
> if (thread_group_leader(target) &&
> is_effectively_child(wo, 0, target) {
> ...
> }
>
> if (target->ptrace &&
> is_effectively_child(wo, 1, target) {
> ...
> }
>
> return 0;
>
> }
>
> looks more simple/clean.

I like that a little better too. I'll go this way since Eric seemed Ok
with either way.

If we do that then it might make sense to move the `thread_group_leader`
filter into `is_effectively_child`, but maybe that obscures what the
latter is doing too much. It'd at least have to be renamed, and I'm not
sure of a clear name that'd capture exactly what it's doing. Maybe
`is_valid_waitee`?

If I don't hear anything I'll just go with how you've already proposed.

v5 coming in a bit. I'll drop your (Oleg's) reviewed-by since it's
changed substantially since then.