Re: more on exit performance

Jaromir Dolecek <[email protected]>
Newsgroups gmane.os.netbsd.devel.performance
Message-ID <[email protected]>
David Laight wrote:
> >  (2) for (pid == -1), we can keep the stopped and dead children on
> >      separate lists, and only look at the list(s) that we care about.
> 
> Why not just requeue a stopped child at the top of the sibling list?
> It will save all the extra pointers (and data structures to get wrong!).
> I don't know how how many children the benchmark process has, but I
> suspet it is a lot!  Even then this gains <10%, for a normal process
> (and system workload) it must be noise.

It would be very easy to optimize the WAIT_ANY zombie lookup by looking
at zombproc - that list should be mostly empty and the lookup
should be faster than loop over children.

> >  (3) for (pid < -1), we can similarly look up the pgrp in pid_table
> >      and keep the stopped and dead children on separate lists in the pgrp.
> 
> Can't possibly happen often enough to worry about.

Yeah, I don't think wait on pgrp is used very often.
 
> 	David
> 
> Index: kern_exit.c
> ===================================================================
> RCS file: /cvsroot/src/sys/kern/kern_exit.c,v
> retrieving revision 1.124
> diff -u -p -r1.124 kern_exit.c
> --- kern_exit.c	2003/09/16 13:46:24	1.124
> +++ kern_exit.c	2003/11/02 10:39:49
> @@ -718,10 +727,16 @@ find_stopped_child(struct proc *parent, 
>  	for (;;) {
>  		c_found = 0;
>  		LIST_FOREACH(child, &parent->p_children, p_sibling) {
> -			if (pid != WAIT_ANY &&
> -			    child->p_pid != pid &&
> -			    child->p_pgid != -pid)
> -				continue;
> +			if (pid >= 0) {
> +				if (child->p_pid != pid) {
> +					child = pfind(pid);
> +					if (child == NULL
> +					    || child->p_parent != parent)
> +						break;

This should be outside the LIST_FOREACH() loop. Also, this only
optimizes asleep child lookup, not zombie lookup. Given that
more frequent operation is wait for deceased child, we should
optimize that operation too.
 
> +				}
> +			} else
> +				if (pid != WAIT_ANY && child->p_pgid != -pid)
> +					continue;
>  			/*
>  			 * Wait for processes with p_exitsig != SIGCHLD
>  			 * processes only if WALTSIG is set; wait for
> @@ -730,8 +745,11 @@ find_stopped_child(struct proc *parent, 
>  			 */
>  			if (((options & WALLSIG) == 0) &&
>  			    (options & WALTSIG ? child->p_exitsig == SIGCHLD
> -						: P_EXITSIG(child) != SIGCHLD))
> +						: P_EXITSIG(child) != SIGCHLD)){
> +				if (child->p_pid == pid)
> +					break;
>  				continue;
> +			}
>  
>  			c_found = 1;
>  			if (child->p_stat == SZOMB &&
> @@ -748,6 +766,8 @@ find_stopped_child(struct proc *parent, 
>  				*child_p = child;
>  				return 0;
>  			}
> +			if (child->p_pid == pid)
> +				break;
>  		}
>  		if (c_found == 0)
>  			return ECHILD;
> -- 
> David Laight: [email protected]
> 

-- 
Jaromir Dolecek <[email protected]>            http://www.NetBSD.cz/
-=- We should be mindful of the potential goal, but as the tantric    -=-
-=- Buddhist masters say, ``You may notice during meditation that you -=-
-=- sometimes levitate or glow.   Do not let this distract you.''     -=-
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.