]> git.hungrycats.org Git - linux/commitdiff
[PATCH] pid-max-2.5.33-A0
authorIngo Molnar <mingo@elte.hu>
Thu, 5 Sep 2002 01:45:49 +0000 (18:45 -0700)
committerLinus Torvalds <torvalds@home.transmeta.com>
Thu, 5 Sep 2002 01:45:49 +0000 (18:45 -0700)
This is the pid-max patch, the one i sent for 2.5.31 was botched.  I
have removed the 'once' debugging stupidity - now PIDs start at 0 again.
Also, for an unknown reason the previous patch missed the hunk that had
the declaration of 'DEFAULT_PID_MAX' which made it not compile ...

include/linux/sched.h
include/linux/sysctl.h
include/linux/threads.h
kernel/fork.c
kernel/sysctl.c

index c5c828d528972278b614c03cf32706857229f4e2..896b7f59941cbf5cd06a332b7dd1ed064fc98208 100644 (file)
@@ -455,7 +455,7 @@ extern struct task_struct init_task;
 extern struct   mm_struct init_mm;
 
 /* PID hashing. (shouldnt this be dynamic?) */
-#define PIDHASH_SZ (4096 >> 2)
+#define PIDHASH_SZ 8192
 extern struct task_struct *pidhash[PIDHASH_SZ];
 
 #define pid_hashfn(x)  ((((x) >> 8) ^ (x)) & (PIDHASH_SZ - 1))
index 4c598d745e2e47db0da1d337a6a8fdfcb1a27f12..4856854660ccbac1ff982a2a96e62c34b6fde6c8 100644 (file)
@@ -127,6 +127,7 @@ enum
        KERN_CORE_USES_PID=52,          /* int: use core or core.%pid */
        KERN_TAINTED=53,        /* int: various kernel tainted flags */
        KERN_CADPID=54,         /* int: PID of the process to notify on CAD */
+       KERN_PIDMAX=55,         /* int: PID # limit */
 };
 
 
index 6804ee73640fff7adedae54efa58b90a1ace2f7a..8e0ddb9605244cfb14810595fb30e92820d884d9 100644 (file)
@@ -19,7 +19,6 @@
 /*
  * This controls the maximum pid allocated to a process
  */
-#define PID_MASK 0x3fffffff
-#define PID_MAX (PID_MASK+1)
+#define DEFAULT_PID_MAX 0x8000
 
 #endif
index f06b869ba95827781a0b1e14ffae555548151804..7c9dc7841aa2745f05b27498595222774735e887 100644 (file)
@@ -46,6 +46,14 @@ int nr_threads;
 
 int max_threads;
 unsigned long total_forks;     /* Handle normal Linux uptimes. */
+
+/*
+ * Protects next_safe, last_pid and pid_max:
+ */
+spinlock_t lastpid_lock = SPIN_LOCK_UNLOCKED;
+
+static int next_safe = DEFAULT_PID_MAX;
+int pid_max = DEFAULT_PID_MAX;
 int last_pid;
 
 struct task_struct *pidhash[PIDHASH_SZ];
@@ -151,11 +159,8 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
        return tsk;
 }
 
-spinlock_t lastpid_lock = SPIN_LOCK_UNLOCKED;
-
 static int get_pid(unsigned long flags)
 {
-       static int next_safe = PID_MAX;
        struct task_struct *p;
        int pid;
 
@@ -163,34 +168,35 @@ static int get_pid(unsigned long flags)
                return 0;
 
        spin_lock(&lastpid_lock);
-       if((++last_pid) & ~PID_MASK) {
+       if (++last_pid > pid_max) {
                last_pid = 300;         /* Skip daemons etc. */
                goto inside;
        }
-       if(last_pid >= next_safe) {
+
+       if (last_pid >= next_safe) {
 inside:
-               next_safe = PID_MAX;
+               next_safe = pid_max;
                read_lock(&tasklist_lock);
        repeat:
                for_each_task(p) {
-                       if(p->pid == last_pid   ||
+                       if (p->pid == last_pid  ||
                           p->pgrp == last_pid  ||
                           p->tgid == last_pid  ||
                           p->session == last_pid) {
-                               if(++last_pid >= next_safe) {
-                                       if(last_pid & ~PID_MASK)
+                               if (++last_pid >= next_safe) {
+                                       if (last_pid >= pid_max)
                                                last_pid = 300;
-                                       next_safe = PID_MAX;
+                                       next_safe = pid_max;
                                }
                                goto repeat;
                        }
-                       if(p->pid > last_pid && next_safe > p->pid)
+                       if (p->pid > last_pid && next_safe > p->pid)
                                next_safe = p->pid;
-                       if(p->pgrp > last_pid && next_safe > p->pgrp)
+                       if (p->pgrp > last_pid && next_safe > p->pgrp)
                                next_safe = p->pgrp;
-                       if(p->tgid > last_pid && next_safe > p->tgid)
+                       if (p->tgid > last_pid && next_safe > p->tgid)
                                next_safe = p->tgid;
-                       if(p->session > last_pid && next_safe > p->session)
+                       if (p->session > last_pid && next_safe > p->session)
                                next_safe = p->session;
                }
                read_unlock(&tasklist_lock);
index 4b9619033b07467fc7b4af32918f1b7cf6698404..f678f46e7a8f3dae21b751702719affc00db406c 100644 (file)
@@ -51,6 +51,7 @@ extern int max_queued_signals;
 extern int sysrq_enabled;
 extern int core_uses_pid;
 extern int cad_pid;
+extern int pid_max;
 
 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
 static int maxolduid = 65535;
@@ -255,6 +256,8 @@ static ctl_table kern_table[] = {
        {KERN_S390_USER_DEBUG_LOGGING,"userprocess_debug",
         &sysctl_userprocess_debug,sizeof(int),0644,NULL,&proc_dointvec},
 #endif
+       {KERN_PIDMAX, "pid_max", &pid_max, sizeof (int),
+        0600, NULL, &proc_dointvec},
        {0}
 };