summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2021-10-12 11:30:42 +0000
committercinap_lenrek <cinap_lenrek@felloff.net>2021-10-12 11:30:42 +0000
commit03d870e0283299404b0eb46689d13f8538e83a2f (patch)
treea4e9cce06b75f06aaeffb74c53b9c0ea5804621c
parentb3c3c3e63df2958dfc3f972abefa8f892d8345d3 (diff)
kernel: return error from sysrfork instead of waiting and retrying
The old strategy of wait and retry doesnt seem to work very well as it keeps all the forking parents stuck waiting in the kernel worsening the situation. The idea with this change is to have rfork() return error quickly; and without whining; as most callers would just react with a sysfatal() which might be better for surviving this.
-rw-r--r--sys/src/9/port/pgrp.c2
-rw-r--r--sys/src/9/port/proc.c15
-rw-r--r--sys/src/9/port/sysproc.c3
3 files changed, 8 insertions, 12 deletions
diff --git a/sys/src/9/port/pgrp.c b/sys/src/9/port/pgrp.c
index 14bfc9ef5..afb50d9cf 100644
--- a/sys/src/9/port/pgrp.c
+++ b/sys/src/9/port/pgrp.c
@@ -268,7 +268,7 @@ resrcwait(char *reason)
char *p;
if(up == nil)
- panic("resrcwait");
+ panic("resrcwait: %s", reason);
p = up->psstate;
if(reason != nil) {
diff --git a/sys/src/9/port/proc.c b/sys/src/9/port/proc.c
index 567ab0756..782abc795 100644
--- a/sys/src/9/port/proc.c
+++ b/sys/src/9/port/proc.c
@@ -630,19 +630,13 @@ canpage(Proc *p)
Proc*
newproc(void)
{
- char msg[64];
Proc *p;
lock(&procalloc);
- for(;;) {
- if((p = procalloc.free) != nil)
- break;
-
- snprint(msg, sizeof msg, "no procs; %s forking",
- up != nil ? up->text: "kernel");
+ p = procalloc.free;
+ if(p == nil){
unlock(&procalloc);
- resrcwait(msg);
- lock(&procalloc);
+ return nil;
}
procalloc.free = p->qnext;
p->qnext = nil;
@@ -1409,7 +1403,8 @@ kproc(char *name, void (*func)(void *), void *arg)
static Pgrp *kpgrp;
Proc *p;
- p = newproc();
+ while((p = newproc()) == nil)
+ resrcwait("no procs for kproc");
qlock(&p->debug);
if(up != nil){
diff --git a/sys/src/9/port/sysproc.c b/sys/src/9/port/sysproc.c
index 6e0af5332..f451e047d 100644
--- a/sys/src/9/port/sysproc.c
+++ b/sys/src/9/port/sysproc.c
@@ -84,7 +84,8 @@ sysrfork(va_list list)
return 0;
}
- p = newproc();
+ if((p = newproc()) == nil)
+ error("no procs");
qlock(&p->debug);