Lines Matching refs:vd
93 static int vmisfree(Vmdata_t* vd, Block_t* b)
95 static int vmisfree(vd,b)
96 Vmdata_t* vd;
103 if(b == vd->wild)
107 return vmonlist(TINY(vd)[INDEX(SIZE(b))], b);
109 if(vd->root)
110 return vmintree(vd->root, b);
117 static int vmisjunk(Vmdata_t* vd, Block_t* b)
119 static int vmisjunk(vd,b)
120 Vmdata_t* vd;
129 if(b == vd->free) /* recently freed */
133 for(t = CACHE(vd)[C_INDEX(SIZE(b))]; t; t = LINK(t))
139 for(t = CACHE(vd)[S_CACHE]; t; t = LINK(t))
177 int _vmbestcheck(Vmdata_t* vd, Block_t* freeb)
179 int _vmbestcheck(vd, freeb)
180 Vmdata_t* vd;
192 if(vd->root && vmchktree(vd->root) < 0 )
195 for(seg = vd->seg; seg && rv == 0; seg = seg->next)
219 if(b != freeb && !vmisfree(vd, b) )
233 !vmisfree(vd, LAST(b)) )
237 if(ISJUNK(SIZE(b)) && !vmisjunk(vd, b))
254 static Block_t* bestsearch(Vmdata_t* vd, reg size_t size, Block_t* wanted)
256 static Block_t* bestsearch(vd, size, wanted)
257 Vmdata_t* vd;
275 else TINY(vd)[0] = r;
277 seg = vd->seg;
291 /**/ASSERT(!vd->root || vmchktree(vd->root) == 0);
295 if((root = vd->root) ) do
360 vd->root = r; /**/ASSERT(!r || !ISBITS(SIZE(r)));
362 /**/ASSERT(!vd->root || vmchktree(vd->root) == 0);
370 static int bestreclaim(reg Vmdata_t* vd, Block_t* wanted, int c)
372 static int bestreclaim(vd, wanted, c)
373 reg Vmdata_t* vd;
384 /**/ASSERT(_vmbestcheck(vd, NIL(Block_t*)) == 0);
386 if((fp = vd->free) )
387 { LINK(fp) = CACHE(vd)[S_CACHE]; CACHE(vd)[S_CACHE] = fp;
388 vd->free = NIL(Block_t*);
393 { list = CACHE(vd)[n]; CACHE(vd)[n] = NIL(Block_t*);
419 for(seg = vd->seg; seg; seg = seg->next)
438 REMOVE(vd,fp,INDEX(s),t,bestsearch);
455 if(np == vd->wild)
456 vd->wild = NIL(Block_t*);
457 else REMOVE(vd,np,INDEX(s),t,bestsearch);
484 if(np->body.data >= vd->seg->baddr)
485 { vd->wild = fp;
492 np = LINK(fp) = TINY(vd)[s];
504 TINY(vd)[s] = fp;
509 if(!(np = vd->root) ) /* inserting into an empty tree */
510 { vd->root = fp;
552 /**/ASSERT(_vmbestcheck(vd, wanted) == 0);
567 reg Vmdata_t* vd = vm->data;
569 SETINUSE(vd, inuse);
571 if(!(local = vd->mode&VM_TRUST) )
572 { GETLOCAL(vd,local);
573 if(ISLOCK(vd,local))
574 { CLRINUSE(vd, inuse);
577 SETLOCK(vd,local);
580 bestreclaim(vd,NIL(Block_t*),0);
582 for(seg = vd->seg; seg; seg = next)
589 bp = LAST(bp); /**/ASSERT(vmisfree(vd,bp));
591 if(bp == vd->wild)
598 if(size > COMPACT*vd->incr && vd->incr > round)
599 vd->incr /= 2;
602 ** to return raw memory too early. vd->pool has an
608 if(size <= COMPACT*vd->incr || size <= COMPACT*vd->pool)
611 vd->wild = NIL(Block_t*);
612 vd->pool = 0;
614 else REMOVE(vd,bp,INDEX(size),t,bestsearch);
633 /**/ ASSERT(!vd->root || !vmintree(vd->root,bp));
635 LINK(bp) = CACHE(vd)[C_INDEX(SIZE(bp))];
636 CACHE(vd)[C_INDEX(SIZE(bp))] = bp;
640 if(!local && _Vmtrace && (vd->mode&VM_TRACE) && VMETHOD(vd) == VM_MTBEST)
643 CLRLOCK(vd,local); /**/ASSERT(_vmbestcheck(vd, NIL(Block_t*)) == 0);
645 CLRINUSE(vd, inuse);
657 reg Vmdata_t* vd = vm->data;
668 SETINUSE(vd, inuse);
670 if(!(local = vd->mode&VM_TRUST))
671 { GETLOCAL(vd,local); /**/ASSERT(!ISLOCK(vd,local));
672 if(ISLOCK(vd,local) )
673 { CLRINUSE(vd, inuse);
676 SETLOCK(vd,local);
680 /**/ASSERT(_vmbestcheck(vd, NIL(Block_t*)) == 0);
692 if((tp = vd->free) ) /* reuse last free piece if appropriate */
697 vd->free = NIL(Block_t*);
704 vd->free = np;
711 LINK(tp) = CACHE(vd)[S_CACHE];
712 CACHE(vd)[S_CACHE] = tp;
717 { bestreclaim(vd,NIL(Block_t*),n);
718 if(vd->root && (tp = bestsearch(vd,size,NIL(Block_t*))) )
722 /**/ASSERT(!vd->free);
723 if((tp = vd->wild) && SIZE(tp) >= size)
725 vd->wild = NIL(Block_t*);
732 else if(vd->mode&VM_AGAIN)
733 vd->mode &= ~VM_AGAIN;
735 { CLRLOCK(vd,local);
736 CLRINUSE(vd, inuse);
745 /**/ ASSERT(!vd->free);
757 if(VMWILD(vd,np))
761 vd->wild = np;
763 else vd->free = np;
769 if(!local && (vd->mode&VM_TRACE) && _Vmtrace && VMETHOD(vd) == VM_MTBEST)
772 /**/ASSERT(_vmbestcheck(vd, NIL(Block_t*)) == 0);
773 CLRLOCK(vd,local);
776 CLRINUSE(vd, inuse);
791 reg Vmdata_t* vd = vm->data;
794 SETINUSE(vd, inuse);
796 if(!(local = vd->mode&VM_TRUST) )
797 { GETLOCAL(vd,local); /**/ASSERT(!ISLOCK(vd,local));
798 if(ISLOCK(vd,local))
799 { CLRINUSE(vd, inuse);
802 SETLOCK(vd,local);
806 for(seg = vd->seg; seg; seg = seg->next)
814 if(local && !(vd->mode&VM_TRUST) ) /* from bestfree or bestresize */
838 CLRLOCK(vd,local);
839 CLRINUSE(vd, inuse);
851 reg Vmdata_t* vd = vm->data;
860 _vmbestcheck(vd, NIL(Block_t*));
871 SETINUSE(vd, inuse);
873 if(!(local = vd->mode&VM_TRUST) )
874 { GETLOCAL(vd,local); /**/ASSERT(!ISLOCK(vd,local));
875 if(ISLOCK(vd,local) || KPVADDR(vm,data,bestaddr) != 0 )
876 { CLRINUSE(vd, inuse);
879 SETLOCK(vd,local);
882 /**/ASSERT(_vmbestcheck(vd, NIL(Block_t*)) == 0);
889 vd->pool = (vd->pool + (s&~BITS))/2;
894 { /**/ASSERT(!vmonlist(CACHE(vd)[INDEX(s)], bp) );
895 LINK(bp) = CACHE(vd)[INDEX(s)];
896 CACHE(vd)[INDEX(s)] = bp;
898 else if(!vd->free)
899 vd->free = bp;
901 { /**/ASSERT(!vmonlist(CACHE(vd)[S_CACHE], bp) );
902 LINK(bp) = CACHE(vd)[S_CACHE];
903 CACHE(vd)[S_CACHE] = bp;
907 if(SIZE(bp) >= 2*vd->incr)
908 { bestreclaim(vd,NIL(Block_t*),0);
909 if(vd->wild && SIZE(vd->wild) >= COMPACT*vd->incr)
914 if(!local && _Vmtrace && (vd->mode&VM_TRACE) && VMETHOD(vd) == VM_MTBEST )
917 /**/ASSERT(_vmbestcheck(vd, NIL(Block_t*)) == 0);
918 CLRLOCK(vd,local);
921 CLRINUSE(vd, inuse);
939 Vmdata_t *vd = vm->data;
943 SETINUSE(vd, inuse);
954 CLRINUSE(vd, inuse);
958 if(!(local = vd->mode&VM_TRUST) )
959 { GETLOCAL(vd,local); /**/ASSERT(!ISLOCK(vd,local));
960 if(ISLOCK(vd,local) || (!local && KPVADDR(vm,data,bestaddr) != 0 ) )
961 { CLRINUSE(vd, inuse);
964 SETLOCK(vd,local);
970 /**/ASSERT(_vmbestcheck(vd, NIL(Block_t*)) == 0);
978 if(np == vd->free)
979 { vd->free = NIL(Block_t*);
983 { if(!bestreclaim(vd,np,C_INDEX(s)) )
988 { if(np == vd->wild)
989 vd->wild = NIL(Block_t*);
990 else REMOVE(vd,np,INDEX(s),t,bestsearch);
999 if(SIZE(rp) < size && size > vd->incr && SEGWILD(rp) )
1002 s = (size - SIZE(rp)) + sizeof(Head_t); s = ROUND(s,vd->incr);
1038 LINK(rp) = CACHE(vd)[S_CACHE];
1039 CACHE(vd)[S_CACHE] = rp;
1040 bestreclaim(vd, NIL(Block_t*), S_CACHE);
1045 if(!local && _Vmtrace && data && (vd->mode&VM_TRACE) && VMETHOD(vd) == VM_MTBEST)
1048 /**/ASSERT(_vmbestcheck(vd, NIL(Block_t*)) == 0);
1049 CLRLOCK(vd,local);
1055 CLRINUSE(vd, inuse);
1070 reg Vmdata_t* vd = vm->data;
1073 SETINUSE(vd, inuse);
1075 if(!(vd->mode&VM_TRUST) )
1076 { if(ISLOCK(vd,0))
1077 { CLRINUSE(vd, inuse);
1080 SETLOCK(vd,0);
1084 for(seg = vd->seg; seg; seg = seg->next)
1105 CLRLOCK(vd,0);
1106 CLRINUSE(vd, inuse);
1124 reg Vmdata_t* vd = vm->data;
1129 SETINUSE(vd, inuse);
1131 if(!(local = vd->mode&VM_TRUST) )
1132 { GETLOCAL(vd,local); /**/ASSERT(!ISLOCK(vd,local));
1133 if(ISLOCK(vd,local) )
1134 { CLRINUSE(vd, inuse);
1137 SETLOCK(vd,local);
1142 /**/ASSERT(_vmbestcheck(vd, NIL(Block_t*)) == 0);
1147 if(VMETHOD(vd) != VM_MTDEBUG)
1156 bestreclaim(vd,NIL(Block_t*),0);
1181 LINK(tp) = CACHE(vd)[C_INDEX(SIZE(tp))];
1182 CACHE(vd)[C_INDEX(SIZE(tp))] = tp;
1192 LINK(tp) = CACHE(vd)[C_INDEX(SIZE(tp))];
1193 CACHE(vd)[C_INDEX(SIZE(tp))] = tp;
1198 bestreclaim(vd,NIL(Block_t*),0); /* coalesce all free blocks */
1200 if(!local && !(vd->mode&VM_TRUST) && _Vmtrace && (vd->mode&VM_TRACE) )
1204 /**/ASSERT(_vmbestcheck(vd, NIL(Block_t*)) == 0);
1205 CLRLOCK(vd,local);
1208 CLRINUSE(vd, inuse);