Commit acdc721f authored by Ingo Molnar's avatar Ingo Molnar Committed by Linus Torvalds

[PATCH] pid-max-2.5.33-A0

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 ...
parent ccfe3b20
......@@ -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))
......
......@@ -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 */
};
......
......@@ -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
......@@ -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);
......
......@@ -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}
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment