shithub: plan9front

Download patch

ref: 03d870e0283299404b0eb46689d13f8538e83a2f
parent: b3c3c3e63df2958dfc3f972abefa8f892d8345d3
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Oct 12 07:30:42 EDT 2021

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.

--- a/sys/src/9/port/pgrp.c	Mon Oct 11 23:06:20 2021
+++ b/sys/src/9/port/pgrp.c	Tue Oct 12 07:30:42 2021
@@ -268,7 +268,7 @@
 	char *p;
 
 	if(up == nil)
-		panic("resrcwait");
+		panic("resrcwait: %s", reason);
 
 	p = up->psstate;
 	if(reason != nil) {
--- a/sys/src/9/port/proc.c	Mon Oct 11 23:06:20 2021
+++ b/sys/src/9/port/proc.c	Tue Oct 12 07:30:42 2021
@@ -630,19 +630,13 @@
 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 @@
 	static Pgrp *kpgrp;
 	Proc *p;
 
-	p = newproc();
+	while((p = newproc()) == nil)
+		resrcwait("no procs for kproc");
 
 	qlock(&p->debug);
 	if(up != nil){
--- a/sys/src/9/port/sysproc.c	Mon Oct 11 23:06:20 2021
+++ b/sys/src/9/port/sysproc.c	Tue Oct 12 07:30:42 2021
@@ -84,7 +84,8 @@
 		return 0;
 	}
 
-	p = newproc();
+	if((p = newproc()) == nil)
+		error("no procs");
 
 	qlock(&p->debug);