git: 9front

Download patch

ref: b507b0ab0519a60b1810719aabdfb2770df6ed4e
parent: 6301d1235e973154220f1418be65de5ef72e1caa
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Mon May 20 22:29:46 EDT 2013

kernel: make allocb() wait instead of panic() when possible

as long as our process doesnt hold any locks or ilocks, we
can try to wait for the memory to become available instead of
panicing.

--- a/sys/src/9/port/allocb.c
+++ b/sys/src/9/port/allocb.c
@@ -64,10 +64,16 @@
 	 */
 	if(up == nil)
 		panic("allocb without up: %#p", getcallerpc(&size));
-	if((b = _allocb(size)) == nil){
-		xsummary();
-		mallocsummary();
-		panic("allocb: no memory for %d bytes", size);
+	while((b = _allocb(size)) == nil){
+		if(up->nlocks.ref || m->ilockdepth || !islo()){
+			xsummary();
+			mallocsummary();
+			panic("allocb: no memory for %d bytes", size);
+		}
+		if(!waserror()){
+			resrcwait("no memory for allocb");
+			poperror();
+		}
 	}
 	setmalloctag(b, getcallerpc(&size));
 
--