Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 12 Sep 2003 23:58:51 -0400 (EDT)
From:      Jun Su <junsu@m-net.arbornet.org>
To:        hackers@freebsd.org
Subject:   FW: new pid allocation code
Message-ID:  <200309130358.h8D3wpTR018707@m-net.arbornet.org>

next in thread | raw e-mail | index | archive | help
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 <tech-kern@netbsd.org>
From: David Laight <david@l8s.co.uk>
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



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