From owner-freebsd-smp Wed Aug 28 12:37: 4 2002 Delivered-To: freebsd-smp@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5AAA437B400 for ; Wed, 28 Aug 2002 12:37:01 -0700 (PDT) Received: from mail.speakeasy.net (mail12.speakeasy.net [216.254.0.212]) by mx1.FreeBSD.org (Postfix) with ESMTP id E6C5243E6E for ; Wed, 28 Aug 2002 12:37:00 -0700 (PDT) (envelope-from jhb@FreeBSD.org) Received: (qmail 20511 invoked from network); 28 Aug 2002 19:36:59 -0000 Received: from unknown (HELO server.baldwin.cx) ([216.27.160.63]) (envelope-sender ) by mail12.speakeasy.net (qmail-ldap-1.03) with DES-CBC3-SHA encrypted SMTP for ; 28 Aug 2002 19:36:59 -0000 Received: from laptop.baldwin.cx (gw1.twc.weather.com [216.133.140.1]) by server.baldwin.cx (8.12.5/8.12.5) with ESMTP id g7SJawBQ042969; Wed, 28 Aug 2002 15:36:58 -0400 (EDT) (envelope-from jhb@FreeBSD.org) Message-ID: X-Mailer: XFMail 1.5.2 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: <20020828123148.7717f871.makonnen@pacbell.net> Date: Wed, 28 Aug 2002 15:37:01 -0400 (EDT) From: John Baldwin To: Mike Makonnen Subject: RE: Locking questions Cc: smp@FreeBSD.ORG Sender: owner-freebsd-smp@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org On 28-Aug-2002 Mike Makonnen wrote: > Hi folks, > > I resumed working on my resource limit lock patch, and I have a couple of > questions. > > 1. I get "duplicate lock of same type" witness warnings because of this: > > limhold(plimit) { lock(plimit), bump refcount, unlock(plimit) } > > newlim = limget(); > PROC_LOCK(p2); > PROC_LOCK(p1); > LIM_LOCK(p1->p_limit); > if (p1->p_limit->p_lflags & PL_SHAREMOD) { > limcopy(newlim, p1->p_limit); > p2->p_limit = limhold(newlim); > } else { > p2->p_limit = limhold(p1->p_limit); > } > LIM_UNLOCK(p1->p_limit); > PROC_UNLOCK(p1); > PROC_UNLOCK(p2); > limfree(newlim); > newlim = NULL; > > I get this message in limhold() because of: > p2->p_limit = limhold(p1->p_limit); > > Why is this bad? You could deadlock since you don't have a well-defined order of how multiple limit locks are acquired. > Is it safe to drop the p1->p_plimit lock > right before I do the hold? It should be because you need Yes, once you have done the limcopy, you can drop the limit lock for p1->p_limit. The proc lock should probably only protect the p_limit pointer, not the actual contents of the limits though. > 2. Should I add the plimit lock to > static struct witness_order_list_entry order_lists[] ? > What is the rationale behind the ordering of the list? The ordering in the list defines the order in which it is allowed to grab locks. Witness also figures this out on its own so it is not necessary to add the lock to the list unless you just really want to. -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-smp" in the body of the message