svn commit: r351173 - head/sys/kern

Mateusz Guzik mjg at FreeBSD.org
Sat Aug 17 17:42:02 UTC 2019


Author: mjg
Date: Sat Aug 17 17:42:01 2019
New Revision: 351173
URL: https://svnweb.freebsd.org/changeset/base/351173

Log:
  fork: stop skipping < 100 ids on wrap around
  
  Code doing this is commented with a claim that these IDs are occupied by
  daemons, but that's demonstrably false. To an extent the range is used by init
  and kernel processes (and on sufficiently big machines it indeed is fully
  populated).
  
  On a sample box 40-way box the highest id in the range is 63. On a different one
  it is 23. Just use the range.
  
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/sys/kern/kern_fork.c

Modified: head/sys/kern/kern_fork.c
==============================================================================
--- head/sys/kern/kern_fork.c	Sat Aug 17 17:22:08 2019	(r351172)
+++ head/sys/kern/kern_fork.c	Sat Aug 17 17:42:01 2019	(r351173)
@@ -258,20 +258,13 @@ fork_findpid(int flags)
 	}
 	mtx_lock(&procid_lock);
 retry:
-	/*
-	 * If the process ID prototype has wrapped around,
-	 * restart somewhat above 0, as the low-numbered procs
-	 * tend to include daemons that don't exit.
-	 */
-	if (trypid >= pid_max) {
-		trypid = trypid % pid_max;
-		if (trypid < 100)
-			trypid += 100;
-	}
+	if (trypid >= pid_max)
+		trypid = 2;
 
 	bit_ffc_at(&proc_id_pidmap, trypid, pid_max, &result);
 	if (result == -1) {
-		trypid = 100;
+		KASSERT(trypid != 2, ("unexpectedly ran out of IDs"));
+		trypid = 2;
 		goto retry;
 	}
 	if (bit_test(&proc_id_grpidmap, result) ||


More information about the svn-src-head mailing list