Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Aug 2019 17:42:01 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r351173 - head/sys/kern
Message-ID:  <201908171742.x7HHg1x5070234@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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) ||



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