Ptal, I followed what lucio/forsyth suggested and added a delta variable. Reference: /n/patches.lsub.org/patch/realloc Date: Thu Apr 19 16:16:58 CES 2012 Signed-off-by: paurea@lsub.org --- /sys/src/nix/k10/qmalloc.c Thu Apr 12 12:26:28 2012 +++ /sys/src/nix/k10/qmalloc.c Thu Apr 19 15:26:32 2012 @@ -556,6 +556,7 @@ Header *p; ulong osize; uint nunits, ounits; + int delta; /* * Easy stuff: @@ -588,26 +589,20 @@ * adjust the tailptr. */ MLOCK; - if(tailptr != nil && p+ounits == tailptr){ - if(ounits > nunits){ + delta = ounits - nunits; + if(tailptr != nil && p+ounits == tailptr && (delta > 0 || tailsize <= delta)){ p->s.size = nunits; - tailsize += ounits-nunits; + tailsize += delta; + tailptr -= delta; MUNLOCK; return ap; - } - if(tailsize >= nunits-ounits){ - p->s.size = nunits; - tailsize -= nunits-ounits; - MUNLOCK; - return ap; - } } MUNLOCK; /* * Worth doing if it's a small reduction? * Do it anyway if <= NQUICK? - if((ounits-nunits) < 2) + if(delta < 2) return ap; */