Lines Matching defs:mem5
26980 /************** Begin file mem5.c ********************************************/
27054 ** Maximum size of any allocation is ((1<<LOGMAX)*mem5.szAtom). Since
27055 ** mem5.szAtom is always at least 8 and 32-bit integers are used,
27061 ** Masks used for mem5.aCtrl[] elements.
27068 ** into a single structure named "mem5". This is to keep the
27101 ** size mem5.szAtom. aiFreelist[1] holds blocks of size szAtom*2.
27112 } mem5;
27117 #define mem5 GLOBAL(struct Mem5Global, mem5)
27120 ** Assuming mem5.zPool is divided up into an array of Mem5Link
27123 #define MEM5LINK(idx) ((Mem5Link *)(&mem5.zPool[(idx)*mem5.szAtom]))
27126 ** Unlink the chunk at mem5.aPool[i] from list it is currently
27127 ** on. It should be found on mem5.aiFreelist[iLogsize].
27131 assert( i>=0 && i<mem5.nBlock );
27133 assert( (mem5.aCtrl[i] & CTRL_LOGSIZE)==iLogsize );
27138 mem5.aiFreelist[iLogsize] = next;
27148 ** Link the chunk at mem5.aPool[i] so that is on the iLogsize
27153 assert( sqlite3_mutex_held(mem5.mutex) );
27154 assert( i>=0 && i<mem5.nBlock );
27156 assert( (mem5.aCtrl[i] & CTRL_LOGSIZE)==iLogsize );
27158 x = MEM5LINK(i)->next = mem5.aiFreelist[iLogsize];
27161 assert( x<mem5.nBlock );
27164 mem5.aiFreelist[iLogsize] = i;
27171 sqlite3_mutex_enter(mem5.mutex);
27174 sqlite3_mutex_leave(mem5.mutex);
27184 i = (int)(((u8 *)p-mem5.zPool)/mem5.szAtom);
27185 assert( i>=0 && i<mem5.nBlock );
27186 iSize = mem5.szAtom * (1 << (mem5.aCtrl[i]&CTRL_LOGSIZE));
27201 int i; /* Index of a mem5.aPool[] slot */
27202 int iBin; /* Index into mem5.aiFreelist[] */
27215 if( (u32)nByte>mem5.maxRequest ){
27216 mem5.maxRequest = nByte;
27222 for(iFullSz=mem5.szAtom,iLogsize=0; iFullSz<nByte; iFullSz*=2,iLogsize++){}
27224 /* Make sure mem5.aiFreelist[iLogsize] contains at least one free
27228 for(iBin=iLogsize; iBin<=LOGMAX && mem5.aiFreelist[iBin]<0; iBin++){}
27234 i = mem5.aiFreelist[iBin];
27241 mem5.aCtrl[i+newSize] = CTRL_FREE | iBin;
27244 mem5.aCtrl[i] = iLogsize;
27248 mem5.nAlloc++;
27249 mem5.totalAlloc += iFullSz;
27250 mem5.totalExcess += iFullSz - nByte;
27251 mem5.currentCount++;
27252 mem5.currentOut += iFullSz;
27253 if( mem5.maxCount<mem5.currentCount ) mem5.maxCount = mem5.currentCount;
27254 if( mem5.maxOut<mem5.currentOut ) mem5.maxOut = mem5.currentOut;
27260 memset(&mem5.zPool[i*mem5.szAtom], 0xAA, iFullSz);
27264 return (void*)&mem5.zPool[i*mem5.szAtom];
27275 ** the array of mem5.szAtom byte blocks pointed to by mem5.zPool.
27277 iBlock = (int)(((u8 *)pOld-mem5.zPool)/mem5.szAtom);
27280 assert( iBlock>=0 && iBlock<mem5.nBlock );
27281 assert( ((u8 *)pOld-mem5.zPool)%mem5.szAtom==0 );
27282 assert( (mem5.aCtrl[iBlock] & CTRL_FREE)==0 );
27284 iLogsize = mem5.aCtrl[iBlock] & CTRL_LOGSIZE;
27286 assert( iBlock+size-1<(u32)mem5.nBlock );
27288 mem5.aCtrl[iBlock] |= CTRL_FREE;
27289 mem5.aCtrl[iBlock+size-1] |= CTRL_FREE;
27292 assert( mem5.currentCount>0 );
27293 assert( mem5.currentOut>=(size*mem5.szAtom) );
27294 mem5.currentCount--;
27295 mem5.currentOut -= size*mem5.szAtom;
27296 assert( mem5.currentOut>0 || mem5.currentCount==0 );
27297 assert( mem5.currentCount>0 || mem5.currentOut==0 );
27300 mem5.aCtrl[iBlock] = CTRL_FREE | iLogsize;
27308 if( iBuddy>=mem5.nBlock ) break;
27310 if( mem5.aCtrl[iBuddy]!=(CTRL_FREE | iLogsize) ) break;
27314 mem5.aCtrl[iBuddy] = CTRL_FREE | iLogsize;
27315 mem5.aCtrl[iBlock] = 0;
27318 mem5.aCtrl[iBlock] = CTRL_FREE | iLogsize;
27319 mem5.aCtrl[iBuddy] = 0;
27327 memset(&mem5.zPool[iBlock*mem5.szAtom], 0x55, size);
27403 if( n<=mem5.szAtom*2 ){
27404 if( n<=mem5.szAtom ) return mem5.szAtom;
27405 return mem5.szAtom*2;
27412 for(iFullSz=mem5.szAtom*8; iFullSz<n; iFullSz *= 4);
27444 int iOffset; /* An offset into mem5.aCtrl[] */
27449 mem5.mutex = 0;
27462 mem5.szAtom = (1<<nMinLog);
27463 while( (int)sizeof(Mem5Link)>mem5.szAtom ){
27464 mem5.szAtom = mem5.szAtom << 1;
27467 mem5.nBlock = (nByte / (mem5.szAtom+sizeof(u8)));
27468 mem5.zPool = zByte;
27469 mem5.aCtrl = (u8 *)&mem5.zPool[mem5.nBlock*mem5.szAtom];
27472 mem5.aiFreelist[ii] = -1;
27478 if( (iOffset+nAlloc)<=mem5.nBlock ){
27479 mem5.aCtrl[iOffset] = ii | CTRL_FREE;
27483 assert((iOffset+nAlloc)>mem5.nBlock);
27488 mem5.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
27499 mem5.mutex = 0;
27524 nMinLog = memsys5Log(mem5.szAtom);
27526 for(n=0, j=mem5.aiFreelist[i]; j>=0; j = MEM5LINK(j)->next, n++){}
27527 fprintf(out, "freelist items of size %d: %d\n", mem5.szAtom << i, n);
27529 fprintf(out, "mem5.nAlloc = %llu\n", mem5.nAlloc);
27530 fprintf(out, "mem5.totalAlloc = %llu\n", mem5.totalAlloc);
27531 fprintf(out, "mem5.totalExcess = %llu\n", mem5.totalExcess);
27532 fprintf(out, "mem5.currentOut = %u\n", mem5.currentOut);
27533 fprintf(out, "mem5.currentCount = %u\n", mem5.currentCount);
27534 fprintf(out, "mem5.maxOut = %u\n", mem5.maxOut);
27535 fprintf(out, "mem5.maxCount = %u\n", mem5.maxCount);
27536 fprintf(out, "mem5.maxRequest = %u\n", mem5.maxRequest);
27567 /************** End of mem5.c ************************************************/