Lines Matching defs:mem5
28154 /************** Begin file mem5.c ********************************************/
28228 ** Maximum size of any allocation is ((1<<LOGMAX)*mem5.szAtom). Since
28229 ** mem5.szAtom is always at least 8 and 32-bit integers are used,
28235 ** Masks used for mem5.aCtrl[] elements.
28242 ** into a single structure named "mem5". This is to keep the
28275 ** size mem5.szAtom. aiFreelist[1] holds blocks of size szAtom*2.
28286 } mem5;
28291 #define mem5 GLOBAL(struct Mem5Global, mem5)
28294 ** Assuming mem5.zPool is divided up into an array of Mem5Link
28297 #define MEM5LINK(idx) ((Mem5Link *)(&mem5.zPool[(idx)*mem5.szAtom]))
28300 ** Unlink the chunk at mem5.aPool[i] from list it is currently
28301 ** on. It should be found on mem5.aiFreelist[iLogsize].
28305 assert( i>=0 && i<mem5.nBlock );
28307 assert( (mem5.aCtrl[i] & CTRL_LOGSIZE)==iLogsize );
28312 mem5.aiFreelist[iLogsize] = next;
28322 ** Link the chunk at mem5.aPool[i] so that is on the iLogsize
28327 assert( sqlite3_mutex_held(mem5.mutex) );
28328 assert( i>=0 && i<mem5.nBlock );
28330 assert( (mem5.aCtrl[i] & CTRL_LOGSIZE)==iLogsize );
28332 x = MEM5LINK(i)->next = mem5.aiFreelist[iLogsize];
28335 assert( x<mem5.nBlock );
28338 mem5.aiFreelist[iLogsize] = i;
28345 sqlite3_mutex_enter(mem5.mutex);
28348 sqlite3_mutex_leave(mem5.mutex);
28358 i = (int)(((u8 *)p-mem5.zPool)/mem5.szAtom);
28359 assert( i>=0 && i<mem5.nBlock );
28360 iSize = mem5.szAtom * (1 << (mem5.aCtrl[i]&CTRL_LOGSIZE));
28375 int i; /* Index of a mem5.aPool[] slot */
28376 int iBin; /* Index into mem5.aiFreelist[] */
28389 if( (u32)nByte>mem5.maxRequest ){
28390 mem5.maxRequest = nByte;
28396 for(iFullSz=mem5.szAtom,iLogsize=0; iFullSz<nByte; iFullSz*=2,iLogsize++){}
28398 /* Make sure mem5.aiFreelist[iLogsize] contains at least one free
28402 for(iBin=iLogsize; iBin<=LOGMAX && mem5.aiFreelist[iBin]<0; iBin++){}
28408 i = mem5.aiFreelist[iBin];
28415 mem5.aCtrl[i+newSize] = CTRL_FREE | iBin;
28418 mem5.aCtrl[i] = iLogsize;
28422 mem5.nAlloc++;
28423 mem5.totalAlloc += iFullSz;
28424 mem5.totalExcess += iFullSz - nByte;
28425 mem5.currentCount++;
28426 mem5.currentOut += iFullSz;
28427 if( mem5.maxCount<mem5.currentCount ) mem5.maxCount = mem5.currentCount;
28428 if( mem5.maxOut<mem5.currentOut ) mem5.maxOut = mem5.currentOut;
28434 memset(&mem5.zPool[i*mem5.szAtom], 0xAA, iFullSz);
28438 return (void*)&mem5.zPool[i*mem5.szAtom];
28449 ** the array of mem5.szAtom byte blocks pointed to by mem5.zPool.
28451 iBlock = (int)(((u8 *)pOld-mem5.zPool)/mem5.szAtom);
28454 assert( iBlock>=0 && iBlock<mem5.nBlock );
28455 assert( ((u8 *)pOld-mem5.zPool)%mem5.szAtom==0 );
28456 assert( (mem5.aCtrl[iBlock] & CTRL_FREE)==0 );
28458 iLogsize = mem5.aCtrl[iBlock] & CTRL_LOGSIZE;
28460 assert( iBlock+size-1<(u32)mem5.nBlock );
28462 mem5.aCtrl[iBlock] |= CTRL_FREE;
28463 mem5.aCtrl[iBlock+size-1] |= CTRL_FREE;
28466 assert( mem5.currentCount>0 );
28467 assert( mem5.currentOut>=(size*mem5.szAtom) );
28468 mem5.currentCount--;
28469 mem5.currentOut -= size*mem5.szAtom;
28470 assert( mem5.currentOut>0 || mem5.currentCount==0 );
28471 assert( mem5.currentCount>0 || mem5.currentOut==0 );
28474 mem5.aCtrl[iBlock] = CTRL_FREE | iLogsize;
28482 if( iBuddy>=mem5.nBlock ) break;
28484 if( mem5.aCtrl[iBuddy]!=(CTRL_FREE | iLogsize) ) break;
28488 mem5.aCtrl[iBuddy] = CTRL_FREE | iLogsize;
28489 mem5.aCtrl[iBlock] = 0;
28492 mem5.aCtrl[iBlock] = CTRL_FREE | iLogsize;
28493 mem5.aCtrl[iBuddy] = 0;
28501 memset(&mem5.zPool[iBlock*mem5.szAtom], 0x55, size);
28577 if( n<=mem5.szAtom*2 ){
28578 if( n<=mem5.szAtom ) return mem5.szAtom;
28579 return mem5.szAtom*2;
28586 for(iFullSz=mem5.szAtom*8; iFullSz<n; iFullSz *= 4);
28618 int iOffset; /* An offset into mem5.aCtrl[] */
28623 mem5.mutex = 0;
28636 mem5.szAtom = (1<<nMinLog);
28637 while( (int)sizeof(Mem5Link)>mem5.szAtom ){
28638 mem5.szAtom = mem5.szAtom << 1;
28641 mem5.nBlock = (nByte / (mem5.szAtom+sizeof(u8)));
28642 mem5.zPool = zByte;
28643 mem5.aCtrl = (u8 *)&mem5.zPool[mem5.nBlock*mem5.szAtom];
28646 mem5.aiFreelist[ii] = -1;
28652 if( (iOffset+nAlloc)<=mem5.nBlock ){
28653 mem5.aCtrl[iOffset] = ii | CTRL_FREE;
28657 assert((iOffset+nAlloc)>mem5.nBlock);
28662 mem5.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
28673 mem5.mutex = 0;
28698 nMinLog = memsys5Log(mem5.szAtom);
28700 for(n=0, j=mem5.aiFreelist[i]; j>=0; j = MEM5LINK(j)->next, n++){}
28701 fprintf(out, "freelist items of size %d: %d\n", mem5.szAtom << i, n);
28703 fprintf(out, "mem5.nAlloc = %llu\n", mem5.nAlloc);
28704 fprintf(out, "mem5.totalAlloc = %llu\n", mem5.totalAlloc);
28705 fprintf(out, "mem5.totalExcess = %llu\n", mem5.totalExcess);
28706 fprintf(out, "mem5.currentOut = %u\n", mem5.currentOut);
28707 fprintf(out, "mem5.currentCount = %u\n", mem5.currentCount);
28708 fprintf(out, "mem5.maxOut = %u\n", mem5.maxOut);
28709 fprintf(out, "mem5.maxCount = %u\n", mem5.maxCount);
28710 fprintf(out, "mem5.maxRequest = %u\n", mem5.maxRequest);
28741 /************** End of mem5.c ************************************************/