Lines Matching defs:mem3

17103 /************** Begin file mem3.c ********************************************/
17167 ** We often identify a chunk by its index in mem3.aPool[]. When
17175 ** Pointers to the head of the list are stored in mem3.aiSmall[]
17176 ** for smaller chunks and mem3.aiHash[] for larger chunks.
17190 u32 next; /* Index in mem3.aPool[] of next free chunk */
17191 u32 prev; /* Index in mem3.aPool[] of previous free chunk */
17198 ** into a single structure named "mem3". This is to keep the
17241 } mem3 = { 97535575 };
17243 #define mem3 GLOBAL(struct Mem3Global, mem3)
17246 ** Unlink the chunk at mem3.aPool[i] from list it is currently
17250 u32 next = mem3.aPool[i].u.list.next;
17251 u32 prev = mem3.aPool[i].u.list.prev;
17252 assert( sqlite3_mutex_held(mem3.mutex) );
17256 mem3.aPool[prev].u.list.next = next;
17259 mem3.aPool[next].u.list.prev = prev;
17261 mem3.aPool[i].u.list.next = 0;
17262 mem3.aPool[i].u.list.prev = 0;
17271 assert( sqlite3_mutex_held(mem3.mutex) );
17272 assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 );
17274 size = mem3.aPool[i-1].u.hdr.size4x/4;
17275 assert( size==mem3.aPool[i+size-1].u.hdr.prevSize );
17278 memsys3UnlinkFromList(i, &mem3.aiSmall[size-2]);
17281 memsys3UnlinkFromList(i, &mem3.aiHash[hash]);
17286 ** Link the chunk at mem3.aPool[i] so that is on the list rooted
17290 assert( sqlite3_mutex_held(mem3.mutex) );
17291 mem3.aPool[i].u.list.next = *pRoot;
17292 mem3.aPool[i].u.list.prev = 0;
17294 mem3.aPool[*pRoot].u.list.prev = i;
17305 assert( sqlite3_mutex_held(mem3.mutex) );
17307 assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 );
17308 size = mem3.aPool[i-1].u.hdr.size4x/4;
17309 assert( size==mem3.aPool[i+size-1].u.hdr.prevSize );
17312 memsys3LinkIntoList(i, &mem3.aiSmall[size-2]);
17315 memsys3LinkIntoList(i, &mem3.aiHash[hash]);
17325 if( sqlite3GlobalConfig.bMemstat==0 && mem3.mutex==0 ){
17326 mem3.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
17328 sqlite3_mutex_enter(mem3.mutex);
17331 sqlite3_mutex_leave(mem3.mutex);
17338 if( !mem3.alarmBusy ){
17339 mem3.alarmBusy = 1;
17340 assert( sqlite3_mutex_held(mem3.mutex) );
17341 sqlite3_mutex_leave(mem3.mutex);
17343 sqlite3_mutex_enter(mem3.mutex);
17344 mem3.alarmBusy = 0;
17356 assert( sqlite3_mutex_held(mem3.mutex) );
17358 assert( mem3.aPool[i-1].u.hdr.size4x/4==nBlock );
17359 assert( mem3.aPool[i+nBlock-1].u.hdr.prevSize==nBlock );
17360 x = mem3.aPool[i-1].u.hdr.size4x;
17361 mem3.aPool[i-1].u.hdr.size4x = nBlock*4 | 1 | (x&2);
17362 mem3.aPool[i+nBlock-1].u.hdr.prevSize = nBlock;
17363 mem3.aPool[i+nBlock-1].u.hdr.size4x |= 2;
17364 return &mem3.aPool[i];
17368 ** Carve a piece off of the end of the mem3.iMaster free chunk.
17373 assert( sqlite3_mutex_held(mem3.mutex) );
17374 assert( mem3.szMaster>=nBlock );
17375 if( nBlock>=mem3.szMaster-1 ){
17377 void *p = memsys3Checkout(mem3.iMaster, mem3.szMaster);
17378 mem3.iMaster = 0;
17379 mem3.szMaster = 0;
17380 mem3.mnMaster = 0;
17385 newi = mem3.iMaster + mem3.szMaster - nBlock;
17386 assert( newi > mem3.iMaster+1 );
17387 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = nBlock;
17388 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x |= 2;
17389 mem3.aPool[newi-1].u.hdr.size4x = nBlock*4 + 1;
17390 mem3.szMaster -= nBlock;
17391 mem3.aPool[newi-1].u.hdr.prevSize = mem3.szMaster;
17392 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
17393 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
17394 if( mem3.szMaster < mem3.mnMaster ){
17395 mem3.mnMaster = mem3.szMaster;
17397 return (void*)&mem3.aPool[newi];
17404 ** mem3.aiSmall[] or mem3.aiHash[].
17409 ** If it sees a chunk that is larger than mem3.iMaster, it replaces
17410 ** the current mem3.iMaster with the new larger chunk. In order for
17411 ** this mem3.iMaster replacement to work, the master chunk must be
17420 assert( sqlite3_mutex_held(mem3.mutex) );
17422 iNext = mem3.aPool[i].u.list.next;
17423 size = mem3.aPool[i-1].u.hdr.size4x;
17427 assert( i > mem3.aPool[i-1].u.hdr.prevSize );
17428 prev = i - mem3.aPool[i-1].u.hdr.prevSize;
17430 iNext = mem3.aPool[prev].u.list.next;
17434 x = mem3.aPool[prev-1].u.hdr.size4x & 2;
17435 mem3.aPool[prev-1].u.hdr.size4x = size*4 | x;
17436 mem3.aPool[prev+size-1].u.hdr.prevSize = size;
17442 if( size>mem3.szMaster ){
17443 mem3.iMaster = i;
17444 mem3.szMaster = size;
17461 assert( sqlite3_mutex_held(mem3.mutex) );
17476 i = mem3.aiSmall[nBlock-2];
17478 memsys3UnlinkFromList(i, &mem3.aiSmall[nBlock-2]);
17483 for(i=mem3.aiHash[hash]; i>0; i=mem3.aPool[i].u.list.next){
17484 if( mem3.aPool[i-1].u.hdr.size4x/4==nBlock ){
17485 memsys3UnlinkFromList(i, &mem3.aiHash[hash]);
17495 if( mem3.szMaster>=nBlock ){
17507 for(toFree=nBlock*16; toFree<(mem3.nPool*16); toFree *= 2){
17509 if( mem3.iMaster ){
17510 memsys3Link(mem3.iMaster);
17511 mem3.iMaster = 0;
17512 mem3.szMaster = 0;
17515 memsys3Merge(&mem3.aiHash[i]);
17518 memsys3Merge(&mem3.aiSmall[i]);
17520 if( mem3.szMaster ){
17521 memsys3Unlink(mem3.iMaster);
17522 if( mem3.szMaster>=nBlock ){
17542 assert( sqlite3_mutex_held(mem3.mutex) );
17543 assert( p>mem3.aPool && p<&mem3.aPool[mem3.nPool] );
17544 i = p - mem3.aPool;
17545 assert( (mem3.aPool[i-1].u.hdr.size4x&1)==1 );
17546 size = mem3.aPool[i-1].u.hdr.size4x/4;
17547 assert( i+size<=mem3.nPool+1 );
17548 mem3.aPool[i-1].u.hdr.size4x &= ~1;
17549 mem3.aPool[i+size-1].u.hdr.prevSize = size;
17550 mem3.aPool[i+size-1].u.hdr.size4x &= ~2;
17554 if( mem3.iMaster ){
17555 while( (mem3.aPool[mem3.iMaster-1].u.hdr.size4x&2)==0 ){
17556 size = mem3.aPool[mem3.iMaster-1].u.hdr.prevSize;
17557 mem3.iMaster -= size;
17558 mem3.szMaster += size;
17559 memsys3Unlink(mem3.iMaster);
17560 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
17561 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
17562 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = mem3.szMaster;
17564 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
17565 while( (mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x&1)==0 ){
17566 memsys3Unlink(mem3.iMaster+mem3.szMaster);
17567 mem3.szMaster += mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x/4;
17568 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
17569 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = mem3.szMaster;
17660 /* Store a pointer to the memory block in global structure mem3. */
17662 mem3.aPool = (Mem3Block *)sqlite3GlobalConfig.pHeap;
17663 mem3.nPool = (sqlite3GlobalConfig.nHeap / sizeof(Mem3Block)) - 2;
17666 mem3.szMaster = mem3.nPool;
17667 mem3.mnMaster = mem3.szMaster;
17668 mem3.iMaster = 1;
17669 mem3.aPool[0].u.hdr.size4x = (mem3.szMaster<<2) + 2;
17670 mem3.aPool[mem3.nPool].u.hdr.prevSize = mem3.nPool;
17671 mem3.aPool[mem3.nPool].u.hdr.size4x = 1;
17681 mem3.mutex = 0;
17708 for(i=1; i<=mem3.nPool; i+=size/4){
17709 size = mem3.aPool[i-1].u.hdr.size4x;
17711 fprintf(out, "%p size error\n", &mem3.aPool[i]);
17715 if( (size&1)==0 && mem3.aPool[i+size/4-1].u.hdr.prevSize!=size/4 ){
17716 fprintf(out, "%p tail size does not match\n", &mem3.aPool[i]);
17720 if( ((mem3.aPool[i+size/4-1].u.hdr.size4x&2)>>1)!=(size&1) ){
17721 fprintf(out, "%p tail checkout bit is incorrect\n", &mem3.aPool[i]);
17726 fprintf(out, "%p %6d bytes checked out\n", &mem3.aPool[i], (size/4)*8-8);
17728 fprintf(out, "%p %6d bytes free%s\n", &mem3.aPool[i], (size/4)*8-8,
17729 i==mem3.iMaster ? " **master**" : "");
17733 if( mem3.aiSmall[i]==0 ) continue;
17735 for(j = mem3.aiSmall[i]; j>0; j=mem3.aPool[j].u.list.next){
17736 fprintf(out, " %p(%d)", &mem3.aPool[j],
17737 (mem3.aPool[j-1].u.hdr.size4x/4)*8-8);
17742 if( mem3.aiHash[i]==0 ) continue;
17744 for(j = mem3.aiHash[i]; j>0; j=mem3.aPool[j].u.list.next){
17745 fprintf(out, " %p(%d)", &mem3.aPool[j],
17746 (mem3.aPool[j-1].u.hdr.size4x/4)*8-8);
17750 fprintf(out, "master=%d\n", mem3.iMaster);
17751 fprintf(out, "nowUsed=%d\n", mem3.nPool*8 - mem3.szMaster*8);
17752 fprintf(out, "mxUsed=%d\n", mem3.nPool*8 - mem3.mnMaster*8);
17753 sqlite3_mutex_leave(mem3.mutex);
17791 /************** End of mem3.c ************************************************/
122626 ** mem5.c/mem3.c methods. The enclosing #if guarantees at