From owner-freebsd-hackers@FreeBSD.ORG Thu Apr 3 00:39:31 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AB662106566B; Thu, 3 Apr 2008 00:39:31 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id 1D0ED8FC25; Thu, 3 Apr 2008 00:39:30 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (adsl90-21.kln.forthnet.gr [77.49.57.21]) (authenticated bits=128) by igloo.linux.gr (8.14.2/8.14.2/Debian-3) with ESMTP id m330cxM2015621 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 3 Apr 2008 03:39:05 +0300 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.2/8.14.2) with ESMTP id m330cv0G003743; Thu, 3 Apr 2008 03:38:57 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.2/8.14.2/Submit) id m330cgfc003742; Thu, 3 Apr 2008 03:38:42 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) From: Giorgos Keramidas To: "Rao\, Nikhil" 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> Date: Thu, 03 Apr 2008 03:38:42 +0300 In-Reply-To: <12A5C15467D5B94F8E0FF265D9498ADD02CC01D8@orsmsx419.amr.corp.intel.com> (Nikhil Rao's message of "Wed, 2 Apr 2008 10:59:26 -0700") Message-ID: <87tzijojql.fsf@kobe.laptop> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-MailScanner-ID: m330cxM2015621 X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-3.945, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.45, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: freebsd-hackers@freebsd.org, Roman Divacky Subject: Re: pfind() and the proc structure X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Apr 2008 00:39:31 -0000 On Wed, 2 Apr 2008 10:59:26 -0700, "Rao, Nikhil" 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.