Lines Matching refs:mem5

16189 /************** Begin file mem5.c ********************************************/
16262 ** Maximum size of any allocation is ((1<<LOGMAX)*mem5.szAtom). Since
16263 ** mem5.szAtom is always at least 8 and 32-bit integers are used,
16269 ** Masks used for mem5.aCtrl[] elements.
16276 ** into a single structure named "mem5". This is to keep the
16307 ** size mem5.szAtom. aiFreelist[1] holds blocks of size szAtom*2.
16318 } mem5;
16323 #define mem5 GLOBAL(struct Mem5Global, mem5)
16326 ** Assuming mem5.zPool is divided up into an array of Mem5Link
16329 #define MEM5LINK(idx) ((Mem5Link *)(&mem5.zPool[(idx)*mem5.szAtom]))
16332 ** Unlink the chunk at mem5.aPool[i] from list it is currently
16333 ** on. It should be found on mem5.aiFreelist[iLogsize].
16337 assert( i>=0 && i<mem5.nBlock );
16339 assert( (mem5.aCtrl[i] & CTRL_LOGSIZE)==iLogsize );
16344 mem5.aiFreelist[iLogsize] = next;
16354 ** Link the chunk at mem5.aPool[i] so that is on the iLogsize
16359 assert( sqlite3_mutex_held(mem5.mutex) );
16360 assert( i>=0 && i<mem5.nBlock );
16362 assert( (mem5.aCtrl[i] & CTRL_LOGSIZE)==iLogsize );
16364 x = MEM5LINK(i)->next = mem5.aiFreelist[iLogsize];
16367 assert( x<mem5.nBlock );
16370 mem5.aiFreelist[iLogsize] = i;
16379 sqlite3_mutex_enter(mem5.mutex);
16382 sqlite3_mutex_leave(mem5.mutex);
16393 int i = ((u8 *)p-mem5.zPool)/mem5.szAtom;
16394 assert( i>=0 && i<mem5.nBlock );
16395 iSize = mem5.szAtom * (1 << (mem5.aCtrl[i]&CTRL_LOGSIZE));
16409 i = iFirst = mem5.aiFreelist[iLogsize];
16430 int i; /* Index of a mem5.aPool[] slot */
16431 int iBin; /* Index into mem5.aiFreelist[] */
16440 if( (u32)nByte>mem5.maxRequest ){
16441 mem5.maxRequest = nByte;
16452 for(iFullSz=mem5.szAtom, iLogsize=0; iFullSz<nByte; iFullSz *= 2, iLogsize++){}
16454 /* Make sure mem5.aiFreelist[iLogsize] contains at least one free
16458 for(iBin=iLogsize; mem5.aiFreelist[iBin]<0 && iBin<=LOGMAX; iBin++){}
16470 mem5.aCtrl[i+newSize] = CTRL_FREE | iBin;
16473 mem5.aCtrl[i] = iLogsize;
16476 mem5.nAlloc++;
16477 mem5.totalAlloc += iFullSz;
16478 mem5.totalExcess += iFullSz - nByte;
16479 mem5.currentCount++;
16480 mem5.currentOut += iFullSz;
16481 if( mem5.maxCount<mem5.currentCount ) mem5.maxCount = mem5.currentCount;
16482 if( mem5.maxOut<mem5.currentOut ) mem5.maxOut = mem5.currentOut;
16485 return (void*)&mem5.zPool[i*mem5.szAtom];
16496 ** the array of mem5.szAtom byte blocks pointed to by mem5.zPool.
16498 iBlock = ((u8 *)pOld-mem5.zPool)/mem5.szAtom;
16501 assert( iBlock>=0 && iBlock<mem5.nBlock );
16502 assert( ((u8 *)pOld-mem5.zPool)%mem5.szAtom==0 );
16503 assert( (mem5.aCtrl[iBlock] & CTRL_FREE)==0 );
16505 iLogsize = mem5.aCtrl[iBlock] & CTRL_LOGSIZE;
16507 assert( iBlock+size-1<(u32)mem5.nBlock );
16509 mem5.aCtrl[iBlock] |= CTRL_FREE;
16510 mem5.aCtrl[iBlock+size-1] |= CTRL_FREE;
16511 assert( mem5.currentCount>0 );
16512 assert( mem5.currentOut>=(size*mem5.szAtom) );
16513 mem5.currentCount--;
16514 mem5.currentOut -= size*mem5.szAtom;
16515 assert( mem5.currentOut>0 || mem5.currentCount==0 );
16516 assert( mem5.currentCount>0 || mem5.currentOut==0 );
16518 mem5.aCtrl[iBlock] = CTRL_FREE | iLogsize;
16527 if( (iBuddy+(1<<iLogsize))>mem5.nBlock ) break;
16528 if( mem5.aCtrl[iBuddy]!=(CTRL_FREE | iLogsize) ) break;
16532 mem5.aCtrl[iBuddy] = CTRL_FREE | iLogsize;
16533 mem5.aCtrl[iBlock] = 0;
16536 mem5.aCtrl[iBlock] = CTRL_FREE | iLogsize;
16537 mem5.aCtrl[iBuddy] = 0;
16617 for(iFullSz=mem5.szAtom; iFullSz<n; iFullSz *= 2);
16648 int iOffset; /* An offset into mem5.aCtrl[] */
16653 mem5.mutex = 0;
16666 mem5.szAtom = (1<<nMinLog);
16667 while( (int)sizeof(Mem5Link)>mem5.szAtom ){
16668 mem5.szAtom = mem5.szAtom << 1;
16671 mem5.nBlock = (nByte / (mem5.szAtom+sizeof(u8)));
16672 mem5.zPool = zByte;
16673 mem5.aCtrl = (u8 *)&mem5.zPool[mem5.nBlock*mem5.szAtom];
16676 mem5.aiFreelist[ii] = -1;
16682 if( (iOffset+nAlloc)<=mem5.nBlock ){
16683 mem5.aCtrl[iOffset] = ii | CTRL_FREE;
16687 assert((iOffset+nAlloc)>mem5.nBlock);
16692 mem5.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
16703 mem5.mutex = 0;
16728 nMinLog = memsys5Log(mem5.szAtom);
16730 for(n=0, j=mem5.aiFreelist[i]; j>=0; j = MEM5LINK(j)->next, n++){}
16731 fprintf(out, "freelist items of size %d: %d\n", mem5.szAtom << i, n);
16733 fprintf(out, "mem5.nAlloc = %llu\n", mem5.nAlloc);
16734 fprintf(out, "mem5.totalAlloc = %llu\n", mem5.totalAlloc);
16735 fprintf(out, "mem5.totalExcess = %llu\n", mem5.totalExcess);
16736 fprintf(out, "mem5.currentOut = %u\n", mem5.currentOut);
16737 fprintf(out, "mem5.currentCount = %u\n", mem5.currentCount);
16738 fprintf(out, "mem5.maxOut = %u\n", mem5.maxOut);
16739 fprintf(out, "mem5.maxCount = %u\n", mem5.maxCount);
16740 fprintf(out, "mem5.maxRequest = %u\n", mem5.maxRequest);
16771 /************** End of mem5.c ************************************************/
110548 ** mem5.c/mem3.c methods. If neither ENABLE_MEMSYS3 nor