From owner-freebsd-hackers@FreeBSD.ORG Fri Sep 12 20:58:19 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 164EB16A4BF for ; Fri, 12 Sep 2003 20:58:19 -0700 (PDT) Received: from arbornet.org (m-net.arbornet.org [209.142.209.161]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5869643FF7 for ; Fri, 12 Sep 2003 20:58:18 -0700 (PDT) (envelope-from junsu@m-net.arbornet.org) Received: from m-net.arbornet.org (localhost [127.0.0.1]) by arbornet.org (8.12.3p2/8.11.2) with ESMTP id h8D3wpcE018710 for ; Fri, 12 Sep 2003 23:58:51 -0400 (EDT) (envelope-from junsu@m-net.arbornet.org) Received: (from junsu@localhost) by m-net.arbornet.org (8.12.3p2/8.12.3/Submit) id h8D3wpTR018707; Fri, 12 Sep 2003 23:58:51 -0400 (EDT) Date: Fri, 12 Sep 2003 23:58:51 -0400 (EDT) Message-Id: <200309130358.h8D3wpTR018707@m-net.arbornet.org> From: Jun Su To: hackers@freebsd.org Subject: FW: new pid allocation code X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Sep 2003 03:58:19 -0000 Did anyone looke at this new allocation code in the NETBSD. Is it worth porting it to -Current? You can read the major diff here: http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/kern/kern_proc.c.diff?r1=1.60&r2=1.61&f=h Thanks, Jun Su ====================================== Subject: new pid allocation code To: None From: David Laight List: tech-kern Date: 03/11/2003 14:36:30 Hackers, The code below implements a different pid allocation and proc/pgrp lookup algorithm. The main benefits are: - pid and pgrp lookup (by id) doesn't require a search - no dependency on MAXUSERS - automatically scales well to large numbers of processes - small data footprint for small systems - ability to enumerate through all the processes without holding a lock for the entire duration, or having very messy locking rules. (the allproc list and p_list fields could be depracted later). - Largely MP clean The basic idea is to ensure that you allocate a pid number which references an empty slot in the lookup table. To do this a FIFO freelist is linked through the free slots of the lookup table. To avoid reusing pid numbers, the top bits of the pid are incremented each time the slot is reused (the last value is kept in the table). If the table is getting full (ie a pid would be reused in a relatively small number of forks), then the table size is doubled. Orphaned pgrps correctly stop the pid being reused, orphaned sessions keep the pgrp allocated. Below is the main part of the change, there are other bits lurking in fork and exit. If people think this code is ok, I'll sort out a full diff against 'current' (and fix for sparc64). (I've been running this code for months!) David