From owner-freebsd-arch@FreeBSD.ORG Sun Nov 30 03:07:11 2003 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9F00316A4CE; Sun, 30 Nov 2003 03:07:11 -0800 (PST) Received: from VARK.homeunix.com (adsl-68-121-163-164.dsl.pltn13.pacbell.net [68.121.163.164]) by mx1.FreeBSD.org (Postfix) with ESMTP id 761C143FEA; Sun, 30 Nov 2003 03:07:10 -0800 (PST) (envelope-from das@FreeBSD.ORG) Received: from VARK.homeunix.com (localhost [127.0.0.1]) by VARK.homeunix.com (8.12.9/8.12.9) with ESMTP id hAUB4gen034956; Sun, 30 Nov 2003 03:04:42 -0800 (PST) (envelope-from das@FreeBSD.ORG) Received: (from das@localhost) by VARK.homeunix.com (8.12.9/8.12.9/Submit) id hAUB4fe1034955; Sun, 30 Nov 2003 03:04:41 -0800 (PST) (envelope-from das@FreeBSD.ORG) Date: Sun, 30 Nov 2003 03:04:41 -0800 From: David Schultz To: Jay Sern Liew Message-ID: <20031130110441.GA34017@VARK.homeunix.com> Mail-Followup-To: Jay Sern Liew , freebsd-threads@FreeBSD.ORG References: <20031129183810.M90959@pinnacle.schulte.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20031129183810.M90959@pinnacle.schulte.org> X-Mailman-Approved-At: Mon, 01 Dec 2003 05:01:50 -0800 cc: freebsd-threads@FreeBSD.ORG Subject: Re: thread/process & memory management source code X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Nov 2003 11:07:11 -0000 [Redirected to threads@; please avoid spamming multiple lists.] On Sat, Nov 29, 2003, Jay Sern Liew wrote: > Can someone point to me the specific location in the FreeBSD kernel source > where the code for FreeBSD's thread/process & memory management are? > > Specifically, where the dispatcher and scheduler is implemented, > what kind of scheduling algorithms(short term, long term) are used, > where the dynamic storage allocation algorithm is implemented(I'll try > to figure the algorithm used from the code), etc. For short term scheduling, FreeBSD uses the standard Unix decay-usage priority scheduling. There is also an experimental scheduler called ULE, which is designed to work better on SMPs. ULE uses an ad hoc idea about how ``interactive'' a process is in order to make scheduling decisions. See kern_switch.c, sched_4bsd.c, sched_ule.c in src/sys/kern. Long term scheduling is less important than it used to be, but FreeBSD has a swapout daemon that kicks in when the system can't recover enough memory by paging alone. It will basically swap out every process it can that is idle and hasn't already been swapped out recently. Swapping in occurs according in the order of a priority that is based on the interactivity of the process, the time it has been swapped out, and its nice value. See src/sys/vm/vm_glue.c. The primary kernel memory allocator is a slab allocator. See src/sys/vm/uma_*.c, src/sys/kern/kern_malloc.c, and http://citeseer.nj.nec.com/bonwick94slab.html.