From 8a3a36fc056950f2d5aa3bc6b9587fc5e2984ca2 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Tue, 21 May 2013 02:29:46 +0200 Subject: 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. --- sys/src/9/port/allocb.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sys/src/9/port/allocb.c b/sys/src/9/port/allocb.c index c6989452b..97176d76d 100644 --- a/sys/src/9/port/allocb.c +++ b/sys/src/9/port/allocb.c @@ -64,10 +64,16 @@ allocb(int size) */ 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)); -- cgit v1.2.3