Date: Wed, 28 Aug 2002 15:37:01 -0400 (EDT) From: John Baldwin <jhb@FreeBSD.org> To: Mike Makonnen <makonnen@pacbell.net> Cc: smp@FreeBSD.ORG Subject: RE: Locking questions Message-ID: <XFMail.20020828153701.jhb@FreeBSD.org> In-Reply-To: <20020828123148.7717f871.makonnen@pacbell.net>
index | next in thread | previous in thread | raw e-mail
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 <jhb@FreeBSD.org> <>< 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
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.20020828153701.jhb>
