Failing At The 100k Problem On FreeBSD
I had the billiant idea of running 100k processes at once on FreeBSD.
So, I tried to patch the kernel.
cd /usr/src/
# patch the kernel here (see below)
make buildkernel KERNCONF=GENERIC
The patch on sys/proc.h
-#define PID_MAX 99999
-#define NO_PID 100000
+#define PID_MAX (2147483647-1)
+#define NO_PID (PID_MAX+1)
As it turns out, the FreeBSD kernel is structured in a way that there are bitarrays keeping track of every PID possible, making this configuration not compile-able.
So, I reverted to using the following script to stress test the system.
#include <unistd.h>
#include <stdio.h>
#include <sys/wait.h>
int main() {
long int count = 0;
while (1) {
int pid = rfork(RFPROC|RFTHREAD);
if (pid < 0) break;
int sig;
if (pid == 0) {
count += 1;
if (count % 1000 == 0) printf("%ld\n", count);
}
else (void)wait(&sig);
}
return 0;
}
It got stuck at 12000 and froze the whole system. Changing rfork
to fork
didn’t seem to change anything. I think the OS ran out of memory but I can’t tell because all processes freeze when there are 12000 processes, including tools like top
.
Recalling from memory, I have been able to run 40000+ process on Linux with the same amount of memory plus some simply application logic, and the system is still lively with GUI interactable. I guess Linux is still the most efficient operating system out there. For now, you can have 10k processes with Capsicum-based security on FreeBSD and allocate one security context to each user.