From owner-freebsd-hackers Fri Oct 20 07:29:08 1995 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id HAA05876 for hackers-outgoing; Fri, 20 Oct 1995 07:29:08 -0700 Received: from sass165.sandia.gov (sass165.sandia.gov [132.175.109.1]) by freefall.freebsd.org (8.6.12/8.6.6) with ESMTP id HAA05871 for ; Fri, 20 Oct 1995 07:29:05 -0700 Received: from sargon.mdl.sandia.gov (sargon.mdl.sandia.gov [134.253.20.128]) by sass165.sandia.gov (8.6.11/8.6.12) with ESMTP id IAA01798 for ; Fri, 20 Oct 1995 08:32:28 -0600 Received: (aflundi@localhost) by sargon.mdl.sandia.gov (8.6.10) id IAA12025 for freebsd-hackers@freebsd.org; Fri, 20 Oct 1995 08:29:00 -0600 Message-Id: <199510201429.IAA12025@sargon.mdl.sandia.gov> From: aflundi@sandia.gov (Alan F Lundin) Date: Fri, 20 Oct 1995 08:28:59 -0600 In-Reply-To: "Ron G. Minnich" "Re: NetBSD/FreeBSD (pthreads)" (Oct 20, 9:10am) X-Mailer: Mail User's Shell (7.2.5 10/14/92) To: freebsd-hackers@freebsd.org Subject: Re: NetBSD/FreeBSD (pthreads) Sender: owner-hackers@freebsd.org Precedence: bulk On Oct 20, 9:10am, "Ron G. Minnich" wrote: > Subject: Re: NetBSD/FreeBSD (pthreads) > > I implemented a simple version of plan9 rfork() a little while ago (well, > a year ago). You could rfork and end up with shared data space and file > table. I also implemented a very simple lock/unlock primitive that was > [ ... ] > > For my money this is about as good as kernel threads. There's not the > additional complexity in the kernel (have you ever seen what LWP did to > sunos? No? good.). > > This code has been available gratis for a year. I can't convince anyone > to pull it into core for netbsd or freebsd, but I'll make the offer > again: you want it, let me know. The code, btw, is less than 100 lines > for each change. In fact the fastlock code is something like 25 lines. > I've implemented them as LKMs and directly as part of the kernel. I've been really surprised that there hasn't been a great deal more interest in this (than I've seen anyway). Rob Pike argues pretty well, I think, that kernel threads are a really bad idea, and that the rfork paradigm is more efficient, more powerful, and much simplier to implement (this is that hard to find combination for which I use the adjective "elegant"). His argument goes something like: any time you put threads in the kernel you've fixed the "weight" of the thread, i.e., what is shared between the threads. While with rfork you essentially create "variable weight" threads -- sharing the attributes between processes that are needed for that particular problem. He also noted that adding kernel threads adds a significant "weight" to the process. Larry McVoy has argued that putting "lightweight threads" in the Solaris 2 kernel has made threads about as heavy as normal processes, and Solaris 2 processes now are very heavy, and so is strongly in favor of the rfork concept. There's other evidence that the rfork concept is a good one. After the fact (of making the decision to use rfork in Plan-9 rather than traditional threads), a survey was conducted on the source on the system, and it was found that rfork was almost always called with different attributes being shared, confirming that the flexibility of user defined attribute sharing is used in practice. I haven't thought about it a lot yet, but I'd expect that a user-land library could easily be written using rfork that looks just like pthreads. And I haven't seen or been able to think of any drawbacks or weaknesses to the rfork approach. In any case, I think Ron's rfork implementation for FreeBSD deserves a close and careful look before the kernel gets burdened with a traditional "thread" addition. For those interested in reading more, the Plan-9 overview paper at http://plan9.att.com/plan9/doc/9.html has a section on rfork and its rational. Also there are other documents at ftp://plan9.att.com/plan9/doc/* that probably discuss this more (I'm not sure what's there any more as it has had a fairly major reorganization). --alan