From owner-freebsd-hackers@FreeBSD.ORG Sun Jan 13 16:01:30 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0F77216A41B for ; Sun, 13 Jan 2008 16:01:30 +0000 (UTC) (envelope-from ed@hoeg.nl) Received: from palm.hoeg.nl (mx0.hoeg.nl [IPv6:2001:610:652::211]) by mx1.freebsd.org (Postfix) with ESMTP id D1CB613C455 for ; Sun, 13 Jan 2008 16:01:29 +0000 (UTC) (envelope-from ed@hoeg.nl) Received: by palm.hoeg.nl (Postfix, from userid 1000) id 8847C1CD4C; Sun, 13 Jan 2008 17:01:27 +0100 (CET) Date: Sun, 13 Jan 2008 17:01:27 +0100 From: Ed Schouten To: FreeBSD Hackers Message-ID: <20080113160127.GF80300@hoeg.nl> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="McOwgVabxjWRBDh+" Content-Disposition: inline User-Agent: Mutt/1.5.17 (2007-11-01) Subject: Three questions about FreeBSD kernel internals X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Jan 2008 16:01:30 -0000 --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 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+--