* [PATCH] 2.4.18-rc2 Fix for get_pid hang
@ 2002-02-22 22:29 Paul Larson
2002-02-23 0:29 ` Alan Cox
0 siblings, 1 reply; 6+ messages in thread
From: Paul Larson @ 2002-02-22 22:29 UTC (permalink / raw)
To: marcelo; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 277 bytes --]
Marcelo,
This was made against 2.4.18-rc2 but applies cleanly against
2.4.18-rc4. This is a fix for a problem where if we run out of
available pids, get_pid will hang the system while it searches through
the tasks for an available pid forever.
Thanks,
Paul Larson
[-- Attachment #2: getpid.patch --]
[-- Type: text/x-patch, Size: 1652 bytes --]
diff -Naur linux-2.4.18-rc2/kernel/fork.c linux-getpid/kernel/fork.c
--- linux-2.4.18-rc2/kernel/fork.c Wed Feb 20 09:54:39 2002
+++ linux-getpid/kernel/fork.c Fri Feb 22 15:52:52 2002
@@ -20,6 +20,7 @@
#include <linux/vmalloc.h>
#include <linux/completion.h>
#include <linux/personality.h>
+#include <linux/compiler.h>
#include <asm/pgtable.h>
#include <asm/pgalloc.h>
@@ -85,12 +86,13 @@
{
static int next_safe = PID_MAX;
struct task_struct *p;
- int pid;
+ int pid, beginpid;
if (flags & CLONE_PID)
return current->pid;
spin_lock(&lastpid_lock);
+ beginpid = last_pid;
if((++last_pid) & 0xffff8000) {
last_pid = 300; /* Skip daemons etc. */
goto inside;
@@ -110,12 +112,16 @@
last_pid = 300;
next_safe = PID_MAX;
}
+ if(unlikely(last_pid == beginpid))
+ goto nomorepids;
goto repeat;
}
if(p->pid > last_pid && next_safe > p->pid)
next_safe = p->pid;
if(p->pgrp > last_pid && next_safe > p->pgrp)
next_safe = p->pgrp;
+ if(p->tgid > last_pid && next_safe > p->tgid)
+ next_safe = p->tgid;
if(p->session > last_pid && next_safe > p->session)
next_safe = p->session;
}
@@ -125,6 +131,11 @@
spin_unlock(&lastpid_lock);
return pid;
+
+nomorepids:
+ read_unlock(&tasklist_lock);
+ spin_unlock(&lastpid_lock);
+ return 0;
}
static inline int dup_mmap(struct mm_struct * mm)
@@ -620,6 +631,8 @@
copy_flags(clone_flags, p);
p->pid = get_pid(clone_flags);
+ if (p->pid == 0 && current->pid != 0)
+ goto bad_fork_cleanup;
p->run_list.next = NULL;
p->run_list.prev = NULL;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] 2.4.18-rc2 Fix for get_pid hang
2002-02-23 0:29 ` Alan Cox
@ 2002-02-23 0:26 ` Rik van Riel
2002-02-23 0:41 ` William Lee Irwin III
2002-02-25 13:41 ` Paul Larson
2 siblings, 0 replies; 6+ messages in thread
From: Rik van Riel @ 2002-02-23 0:26 UTC (permalink / raw)
To: Alan Cox; +Cc: Paul Larson, marcelo, linux-kernel
On Sat, 23 Feb 2002, Alan Cox wrote:
> > This was made against 2.4.18-rc2 but applies cleanly against
> > 2.4.18-rc4. This is a fix for a problem where if we run out of
> > available pids, get_pid will hang the system while it searches through
> > the tasks for an available pid forever.
>
> Wouldn't it be a much cleaner patch to limit the maximum number of
> processes to less than the number of pids available. You seem to be
> fixing a non problem by adding branches to the innards of a loop.
The problem here is that thread and process groups share
the pid namespace, so you the number of processes at which
you run out of pids varies between 10700 and 32000 ...
regards,
Rik
--
"Linux holds advantages over the single-vendor commercial OS"
-- Microsoft's "Competing with Linux" document
http://www.surriel.com/ http://distro.conectiva.com/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] 2.4.18-rc2 Fix for get_pid hang
2002-02-22 22:29 [PATCH] 2.4.18-rc2 Fix for get_pid hang Paul Larson
@ 2002-02-23 0:29 ` Alan Cox
2002-02-23 0:26 ` Rik van Riel
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Alan Cox @ 2002-02-23 0:29 UTC (permalink / raw)
To: Paul Larson; +Cc: marcelo, linux-kernel
> This was made against 2.4.18-rc2 but applies cleanly against
> 2.4.18-rc4. This is a fix for a problem where if we run out of
> available pids, get_pid will hang the system while it searches through
> the tasks for an available pid forever.
Wouldn't it be a much cleaner patch to limit the maximum number of processes
to less than the number of pids available. You seem to be fixing a non
problem by adding branches to the innards of a loop.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] 2.4.18-rc2 Fix for get_pid hang
2002-02-23 0:29 ` Alan Cox
2002-02-23 0:26 ` Rik van Riel
@ 2002-02-23 0:41 ` William Lee Irwin III
2002-02-25 13:41 ` Paul Larson
2 siblings, 0 replies; 6+ messages in thread
From: William Lee Irwin III @ 2002-02-23 0:41 UTC (permalink / raw)
To: Alan Cox; +Cc: Paul Larson, marcelo, linux-kernel, manfred
At some point in the past, Paul Larson wrote:
>> This was made against 2.4.18-rc2 but applies cleanly against
>> 2.4.18-rc4. This is a fix for a problem where if we run out of
>> available pids, get_pid will hang the system while it searches
>> through the tasks for an available pid forever.
On Sat, Feb 23, 2002 at 12:29:47AM +0000, Alan Cox wrote:
> Wouldn't it be a much cleaner patch to limit the maximum number of
> processes to less than the number of pids available. You seem to be
> fixing a non problem by adding branches to the innards of a loop.
I've seen this one before. It seems to kick in at 11K processes, where
one would normally expect it much higher... so I'm not sure a constant
upper bound on that counter suffices. Maybe clashes of pid's with pgrp's
and sessions and tgrps are what does that, maybe it's something else.
and of course:
#include <stdgeek.h> /* Any hope of a non-O(tasks) solution? */
Cheers,
Bill
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] 2.4.18-rc2 Fix for get_pid hang
2002-02-23 0:29 ` Alan Cox
2002-02-23 0:26 ` Rik van Riel
2002-02-23 0:41 ` William Lee Irwin III
@ 2002-02-25 13:41 ` Paul Larson
2002-02-25 14:20 ` Alan Cox
2 siblings, 1 reply; 6+ messages in thread
From: Paul Larson @ 2002-02-25 13:41 UTC (permalink / raw)
To: Alan Cox; +Cc: Marcelo Tosati, lkml
On Fri, 2002-02-22 at 18:29, Alan Cox wrote:
> > This was made against 2.4.18-rc2 but applies cleanly against
> > 2.4.18-rc4. This is a fix for a problem where if we run out of
> > available pids, get_pid will hang the system while it searches through
> > the tasks for an available pid forever.
>
> Wouldn't it be a much cleaner patch to limit the maximum number of processes
> to less than the number of pids available. You seem to be fixing a non
> problem by adding branches to the innards of a loop.
>
That was my original thought, but as Rik and WLI already pointed out, it
won't account for process groups, tgids, etc. This isn't a purely
theoretical problem either, as we have run up against it many times.
Thanks,
Paul Larson
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] 2.4.18-rc2 Fix for get_pid hang
2002-02-25 13:41 ` Paul Larson
@ 2002-02-25 14:20 ` Alan Cox
0 siblings, 0 replies; 6+ messages in thread
From: Alan Cox @ 2002-02-25 14:20 UTC (permalink / raw)
To: Paul Larson; +Cc: Alan Cox, Marcelo Tosati, lkml
> > to less than the number of pids available. You seem to be fixing a non
> > problem by adding branches to the innards of a loop.
> >
> That was my original thought, but as Rik and WLI already pointed out, it
> won't account for process groups, tgids, etc. This isn't a purely
> theoretical problem either, as we have run up against it many times.
Agreed - and I don't have any better solutions except 32bit pid_t - which
I suspect one day we are going to need. At least the O(1) scheduler now
makes it feasible 8)
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2002-02-25 14:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-02-22 22:29 [PATCH] 2.4.18-rc2 Fix for get_pid hang Paul Larson
2002-02-23 0:29 ` Alan Cox
2002-02-23 0:26 ` Rik van Riel
2002-02-23 0:41 ` William Lee Irwin III
2002-02-25 13:41 ` Paul Larson
2002-02-25 14:20 ` Alan Cox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox