I was reading kern_fork.c and noticed the oldpids array, which has a
size of 100. This means that when 'idx' in freepid() overflows, the
array index will be restarted at 95, not 99.

pid_t oldpids[100];
void
freepid(pid_t pid)
{
        static uint32_t idx;

        oldpids[idx++ % nitems(oldpids)] = pid;
}

I don't think this is really important, but if the array size was a power
of 2 this wouldn't happen. This will also permit the compiler to replace
the modulo with a binary 'and', but the array is now larger so this would
slow ispidtaken() down.


Index: kern/kern_fork.c
===================================================================
RCS file: /cvs/src/sys/kern/kern_fork.c,v
retrieving revision 1.184
diff -u -p -r1.184 kern_fork.c
--- kern/kern_fork.c    9 Oct 2015 01:10:27 -0000       1.184
+++ kern/kern_fork.c    2 Mar 2016 16:19:35 -0000
@@ -563,7 +563,7 @@ fork1(struct proc *curp, int flags, void
 /*
  * Checks for current use of a pid, either as a pid or pgid.
  */
-pid_t oldpids[100];
+pid_t oldpids[128];
 int
 ispidtaken(pid_t pid)
 {

-- 
Michal Mazurek

Reply via email to