pfind() and the proc structure
Rao, Nikhil
nikhil.rao at intel.com
Wed Apr 2 11:00:37 PDT 2008
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);
-----Original Message-----
From: Giorgos Keramidas [mailto:keramida at ceid.upatras.gr]
Sent: Tuesday, April 01, 2008 10:58 AM
To: Rao, Nikhil
Cc: Roman Divacky; freebsd-hackers at freebsd.org
Subject: Re: pfind() and the proc structure
On Tue, 1 Apr 2008 07:23:58 -0700, "Rao, Nikhil" <nikhil.rao at intel.com>
wrote:
> Ok, I should have caught that :-( Another question - Now that the
> PROC_LOCK on p is obtained the all_proc lock is released and the
> function returns, at this point can't the proc get deallocated ?
>
> Nikhil
>
> 242 struct proc *
> 243 pfind(pid)
> 244 register pid_t pid;
> 245 {
> 246 register struct proc *p;
> 247
> 248 sx_slock(&allproc_lock);
> 249 LIST_FOREACH(p, PIDHASH(pid), p_hash)
> 250 if (p->p_pid == pid) {
> 251 if (p->p_state == PRS_NEW) {
> 252 p = NULL;
> 253 break;
> 254 }
> 255 PROC_LOCK(p);
> 256 break;
> 257 }
> 258 sx_sunlock(&allproc_lock);
> 259 return (p);
> 260 }
Not until you unlock the specific proc entry. You are holding a lock
for the specific proc entry, so anyone trying to `reap' the process
would have to wait until you are done with what you are doing.
More information about the freebsd-hackers
mailing list