Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 02 May 2002 13:34:00 -0400 (EDT)
From:      John Baldwin <jhb@FreeBSD.org>
To:        John Baldwin <jhb@FreeBSD.org>
Cc:        Jeff Roberson <jeff@FreeBSD.org>, cvs-all@FreeBSD.org, cvs-committers@FreeBSD.org, Jeff Roberson <jroberson@chesapeake.net>
Subject:   RE: cvs commit: src/sys/kern kern_malloc.c src/sys/vm uma_core.c
Message-ID:  <XFMail.20020502133400.jhb@FreeBSD.org>
In-Reply-To: <XFMail.20020502131854.jhb@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help

On 02-May-2002 John Baldwin wrote:
> 
> On 02-May-2002 Jeff Roberson wrote:
>> On Thu, 2 May 2002, John Baldwin wrote:
>> 
>>>
>>> On 02-May-2002 Jeff Roberson wrote:
>>> > jeff        2002/05/02 00:22:19 PDT
>>> >
>>> >   Modified files:
>>> >     sys/kern             kern_malloc.c
>>> >     sys/vm               uma_core.c uma_dbg.c
>>> >     sys/sys              malloc.h
>>> >   Log:
>>> >   malloc/free(9) no longer require Giant.  Use the malloc_mtx to protect
>>> >   the
>>> >   mallochash.  Mallochash is going to go away as soon as I introduce the
>>> >   kfree/kmalloc api and partially overhaul the malloc wrapper.  This
>>> >   can't
>>> > happen
>>> >   until all users of the malloc api that expect memory to be aligned on
>>> >   the
>>> > size
>>> >   of the allocation are fixed.
>>>
>>> Can malloc() still block and still possibly obtain Giant internally?  If
>>> so,
>>> malloc() should still not be called with other locks held.
>>>
>> 
>> Yes, it can.  Is this rule due to lock order reversals?  If so there are
>> certain situations where its use could be permitted.  In Geom, for
>> example, giant is always acquired after the geom locks.
> 
> Yes but locks can't be held while blocking.  So since malloc can block malloc
> should still not be called with locks held, even after Giant is dead and
> buried.

So I should amend: it should probably be ok to hold locks if M_NOWAIT is
used.  However, we should avoid holding locks for "long" periods of time.
Esp. around non-relevant stuff like malloc (doing a malloc() usually isn't
very relevant to the consistency of the data structure, you should almost
always be able to make the structure consistent somehow, drop the lock,
malloc, then lock and make the change, or just malloc first before getting
locks and making changes).  So just as M_NOWAIT should be discouraged (and
I've seen it used in places where it wasn't needed) holding locks across
malloc() should be highly discouraged, IMO.

>> Jeff

-- 

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 cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.20020502133400.jhb>