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
This commit is contained in:
Mateusz Guzik 2019-08-17 17:42:01 +00:00
parent 60df116853
commit b05641b6bd

View File

@ -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) ||