BGL

Erik Trulsson ertr1013 at student.uu.se
Sat Oct 1 01:02:05 PDT 2005


On Fri, Sep 30, 2005 at 11:58:14PM -0400, Ansar Mohammed wrote:
> I love FreeBSD. I have been using it since 2.x. I have never had any
> problems with it. Rock Solid. Never a single kernel panic.
> 
> Then I come across this article in a comparison between Linux and FreeBSD
> saying that FreeBSD has kernel locking issues. Specifically, a problem
> nicknamed BGL or Big Giant Lock. It seems that it affects SMP systems under
> high load.

That is not really a "problem", but just a design decision that can lead to 
bad efficiency in a few situations.

In FreeBSD 4.x (and earlier) the kernel is protected by a "Big Giant Lock"
that means that at most one process can be inside the kernel at any given
time.   The reason for having such a lock is that otherwise much confusion
could result when two processes try modify the same data structures at once.

On a uni-processor system such a lock is not problem, since you only have a
single process running at any given time anyway.
On multi-cpu system where processes spend most of their time doing
computations this is not a problem either, since the processes will spend
very little time inside the kernel.

On a multi-cpu system it can mean a loss of efficiency, if you have several
processes all wanting to execute inside the kernel, but in unrelated ares of
the kernel.  In that situation the BGL will make sure that only one process
is in the kernel at one time, and the other processes will have to wait for
it, even if they theoretically could have run in parallell without any
problems.

In FreeBSD 5.x (and even more so in the upcoming 6.x) the BGL has mostly
been split up into several locks which protect smaller parts of the kernel,
meaning that two processes that want to run in unrelated parts of the kernel
can run in parallell.  This can lead to improved efficiency on multi-cpu
systems, since processes won't have to wait for each other as often, but
also leads to a slight slow-down on single-cpu systems, since processes
entering the kernel now usually have to obtain (and release) several locks
rather than a single lock.


In short the BGL is not a problem that can lead to crashes or instability,
but just can lead to inefficent use of the hardware on multi-cpu systems.


> 
> How much do other OSes suffer from this?

Depends.  The BGL design is by far the easiest way to provide support for
running on SMP hardware, and has therefore been used by many OSes at first.
Several of them have since moved on to a more fine-grained locking design
similar to what FreeBSD uses, in order to get the system to scale well
to large machines.

> 
> 
> > -----Original Message-----
> > From: Kris Kennaway [mailto:kris at obsecurity.org]
> > Sent: September 30, 2005 4:46 PM
> > To: Ansar Mohammed
> > Cc: freebsd-questions at freebsd.org
> > Subject: Re: BGL
> > 
> > On Thu, Sep 29, 2005 at 10:09:17PM -0400, Ansar Mohammed wrote:
> > > Is the kernel locking issue with FreeBSD 4.x sorted out in 5.x? I can't
> > seem
> > > to get a proper answer.
> > 
> > Perhaps because the above isn't a proper question?  Yes, the BGL was
> > pushed down a lot in FreeBSD 5.  It still covers some parts of the
> > kernel (less in 6), so if can be more precise about a specific
> > "locking issue" then perhaps we can give a more precise answer.
> > 
> > Kris
> 
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"

-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013 at student.uu.se


More information about the freebsd-questions mailing list