Re: [Patch 1/1] init: Provide a kernel start parameter to increasepid_max v2
From: Linus Torvalds
Date: Sun Apr 25 2010 - 13:29:46 EST
On Sun, 25 Apr 2010, Linus Torvalds wrote:
>
> Iirc, some _really_ old code used 'short' for pid_t, and we wanted to be
> really safe when we raised the limits.
.. I dug into the history, and this is from August 2002..
We used to limit it to sixteen bits, but that was too tight even then for
some people, so first we did this:
Author: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxx>
Date: Thu Aug 8 03:57:42 2002 -0700
Make pid allocation use 30 of the 32 bits, instead of 15.
diff --git a/include/linux/threads.h b/include/linux/threads.h
index 880b990..6804ee7 100644
--- a/include/linux/threads.h
+++ b/include/linux/threads.h
@@ -19,6 +19,7 @@
/*
* This controls the maximum pid allocated to a process
*/
-#define PID_MAX 0x8000
+#define PID_MASK 0x3fffffff
+#define PID_MAX (PID_MASK+1)
#endif
diff --git a/kernel/fork.c b/kernel/fork.c
index d40d246..017740d 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -142,7 +142,7 @@ static int get_pid(unsigned long flags)
return 0;
spin_lock(&lastpid_lock);
- if((++last_pid) & 0xffff8000) {
+ if((++last_pid) & ~PID_MASK) {
last_pid = 300; /* Skip daemons etc. */
goto inside;
}
@@ -157,7 +157,7 @@ inside:
p->tgid == last_pid ||
p->session == last_pid) {
if(++last_pid >= next_safe) {
- if(last_pid & 0xffff8000)
+ if(last_pid & ~PID_MASK)
last_pid = 300;
next_safe = PID_MAX;
}
which just upped the limits. That, in turn, _did_ end up breaking some
silly old binaries, so then a month later Ingo did a "pid-max" patch
that made the maximum dynamic, with a default of the old 15-bit limit,
and a sysctl to raise it.
And then a couple of weeks later, Ingo did another patch to fix the
scalability problems we had with lots of pids (avoiding the whole
"for_each_task()" crud to figure out which pids were ok, and using a
'struct pid' instead).
So the whole worry about > 15-bit pids goes back to 2002. I think we're
pretty safe now.
Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/