Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 13 Jan 2008 17:01:27 +0100
From:      Ed Schouten <ed@fxq.nl>
To:        FreeBSD Hackers <freebsd-hackers@freebsd.org>
Subject:   Three questions about FreeBSD kernel internals
Message-ID:  <20080113160127.GF80300@hoeg.nl>

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

--McOwgVabxjWRBDh+
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hello everyone,

I've got three small questions about some of the source code in the
FreeBSD kernel, based on some of the source code and the manpages. I
didn't send it to questions@, because of their technical nature.

>>> Question 1:

Sleepqueues and turnstiles are allocated on thread creation. Why can't
they be allocated when needed?

I think the following answer should be quite okay:

I suspect because we can't always run sleepq_alloc(). That way we're
use we always have a sleepqueue for the process when we need it. We
always need these, because otherwise the process is doomed when it can't
allocate one.

It's also faster I guess, because we don't have to allocate a brand new
sleepqueue whenever we walk into a condition on which we have to wait
(which happens a real lot, because a real lot of processes sleep).

The reason why we don't keep them on the freelist as much as possible,
is because we don't have to lock the hash table that much. We've always
got one at hand.

>>> Question 2:

The kernel has three mechanisms to wait for an asynchronous event,
namely sema(9), condvar(9) and sleep(9). Strictly, there are only two
interfaces, because sema(9) is implemented using mutex(9) and
condvar(9). My question is: which interface is the preferred one when
writing new code?

>>> Question 3:

In the file tty_subr.c there is the following comment:

| /*
|  * Allocate an initial base set of cblocks as a 'slush'.
|  * We allocate non-slush cblocks with each initial tty_open() and
|  * deallocate them with each tty_close().
|  * We should adjust the slush allocation.  This can't be done in
|  * the i/o routines because they are sometimes called from
|  * interrupt handlers when it may be unsafe to call malloc().
|  */

My question is whether the bottom three lines of the comment are still
accurate. If I believe the manpage, it's safe to call malloc() in
interrupt handlers, if you use M_NOWAIT. I'm not really familiar with
older xBSD implementations, but is it true that the kernel couldn't
allocate memory in interrupt handlers back then?

Yours,
--=20
 Ed Schouten <ed@fxq.nl>
 WWW: http://g-rave.nl/

--McOwgVabxjWRBDh+
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (FreeBSD)

iEYEARECAAYFAkeKNdcACgkQ52SDGA2eCwU34ACeOLhY5OIQFJy5q1JoxkAbEHu7
f2IAnimXZ8FFk8pRKDfdTHxwd9PAMDBE
=ob6e
-----END PGP SIGNATURE-----

--McOwgVabxjWRBDh+--



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