Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 03 Apr 2008 03:38:42 +0300
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        "Rao\, Nikhil" <nikhil.rao@intel.com>
Cc:        freebsd-hackers@freebsd.org, Roman Divacky <rdivacky@freebsd.org>
Subject:   Re: pfind() and the proc structure
Message-ID:  <87tzijojql.fsf@kobe.laptop>
In-Reply-To: <12A5C15467D5B94F8E0FF265D9498ADD02CC01D8@orsmsx419.amr.corp.intel.com> (Nikhil Rao's message of "Wed, 2 Apr 2008 10:59:26 -0700")
References:  <20080329120018.0A8F5106567F@hub.freebsd.org> <12A5C15467D5B94F8E0FF265D9498ADD02CBF8FF@orsmsx419.amr.corp.intel.com> <20080401075623.GA19770@freebsd.org> <12A5C15467D5B94F8E0FF265D9498ADD02CBF949@orsmsx419.amr.corp.intel.com> <878wzxa250.fsf@kobe.laptop> <12A5C15467D5B94F8E0FF265D9498ADD02CC01D8@orsmsx419.amr.corp.intel.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 2 Apr 2008 10:59:26 -0700, "Rao, Nikhil" <nikhil.rao@intel.com> wrote:
> Thanks for all your replies,
>
> the all_proc lock is held in pfind(..) at the point PROC_LOCK(p) is
> obtained. In the kern_wait(..) code below, the allproc_lock is acquired
> before removing the proc from the list of all procs. The PROC_LOCK is
> then acquired before continuing. Since the thread that called pfind(..)
> has the PROC_LOCK, kern_wait(..) would need to wait for it to release
> the PROC_LOCK before continuing. I hope this understanding is correct.
>
> In http://fxr.watson.org/fxr/source/kern/kern_exit.c?v=RELENG62#L579
>
> 				   sx_xlock(&allproc_lock);
> 675                         LIST_REMOVE(p, p_list); /* off zombproc */
> 676                         sx_xunlock(&allproc_lock);
> 677                         LIST_REMOVE(p, p_sibling);
> 678                         leavepgrp(p);
> 679                         sx_xunlock(&proctree_lock);
> 680
> 681                         /*
> 682                          * As a side effect of this lock, we know
> that
> 683                          * all other writes to this proc are visible
> now, so
> 684                          * no more locking is needed for p.
> 685                          */
> 686                         PROC_LOCK(p);

Yes, line 686 above will have to wait for any holders of the proc lock
on the specific proc entry.  The allproc_lock is not needed anymore,
because these last lines are inside:

                if (p->p_state == PRS_ZOMBIE) {
                        ...

After the zombie process has been removed from the zombie list, we will
have to wait until the proc entry is unlocked.  At that point, the proc
entry is no longer on the zombie list, so it won't be locked by anyone
else.  We grab the lock, clean it up and it's gone for good.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?87tzijojql.fsf>