Lines Matching refs:mem3

15109 /************** Begin file mem3.c ********************************************/
15173 ** We often identify a chunk by its index in mem3.aPool[]. When
15181 ** Pointers to the head of the list are stored in mem3.aiSmall[]
15182 ** for smaller chunks and mem3.aiHash[] for larger chunks.
15196 u32 next; /* Index in mem3.aPool[] of next free chunk */
15197 u32 prev; /* Index in mem3.aPool[] of previous free chunk */
15204 ** into a single structure named "mem3". This is to keep the
15247 } mem3 = { 97535575 };
15249 #define mem3 GLOBAL(struct Mem3Global, mem3)
15252 ** Unlink the chunk at mem3.aPool[i] from list it is currently
15256 u32 next = mem3.aPool[i].u.list.next;
15257 u32 prev = mem3.aPool[i].u.list.prev;
15258 assert( sqlite3_mutex_held(mem3.mutex) );
15262 mem3.aPool[prev].u.list.next = next;
15265 mem3.aPool[next].u.list.prev = prev;
15267 mem3.aPool[i].u.list.next = 0;
15268 mem3.aPool[i].u.list.prev = 0;
15277 assert( sqlite3_mutex_held(mem3.mutex) );
15278 assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 );
15280 size = mem3.aPool[i-1].u.hdr.size4x/4;
15281 assert( size==mem3.aPool[i+size-1].u.hdr.prevSize );
15284 memsys3UnlinkFromList(i, &mem3.aiSmall[size-2]);
15287 memsys3UnlinkFromList(i, &mem3.aiHash[hash]);
15292 ** Link the chunk at mem3.aPool[i] so that is on the list rooted
15296 assert( sqlite3_mutex_held(mem3.mutex) );
15297 mem3.aPool[i].u.list.next = *pRoot;
15298 mem3.aPool[i].u.list.prev = 0;
15300 mem3.aPool[*pRoot].u.list.prev = i;
15311 assert( sqlite3_mutex_held(mem3.mutex) );
15313 assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 );
15314 size = mem3.aPool[i-1].u.hdr.size4x/4;
15315 assert( size==mem3.aPool[i+size-1].u.hdr.prevSize );
15318 memsys3LinkIntoList(i, &mem3.aiSmall[size-2]);
15321 memsys3LinkIntoList(i, &mem3.aiHash[hash]);
15331 if( sqlite3GlobalConfig.bMemstat==0 && mem3.mutex==0 ){
15332 mem3.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
15334 sqlite3_mutex_enter(mem3.mutex);
15337 sqlite3_mutex_leave(mem3.mutex);
15344 if( !mem3.alarmBusy ){
15345 mem3.alarmBusy = 1;
15346 assert( sqlite3_mutex_held(mem3.mutex) );
15347 sqlite3_mutex_leave(mem3.mutex);
15349 sqlite3_mutex_enter(mem3.mutex);
15350 mem3.alarmBusy = 0;
15362 assert( sqlite3_mutex_held(mem3.mutex) );
15364 assert( mem3.aPool[i-1].u.hdr.size4x/4==nBlock );
15365 assert( mem3.aPool[i+nBlock-1].u.hdr.prevSize==nBlock );
15366 x = mem3.aPool[i-1].u.hdr.size4x;
15367 mem3.aPool[i-1].u.hdr.size4x = nBlock*4 | 1 | (x&2);
15368 mem3.aPool[i+nBlock-1].u.hdr.prevSize = nBlock;
15369 mem3.aPool[i+nBlock-1].u.hdr.size4x |= 2;
15370 return &mem3.aPool[i];
15374 ** Carve a piece off of the end of the mem3.iMaster free chunk.
15379 assert( sqlite3_mutex_held(mem3.mutex) );
15380 assert( mem3.szMaster>=nBlock );
15381 if( nBlock>=mem3.szMaster-1 ){
15383 void *p = memsys3Checkout(mem3.iMaster, mem3.szMaster);
15384 mem3.iMaster = 0;
15385 mem3.szMaster = 0;
15386 mem3.mnMaster = 0;
15391 newi = mem3.iMaster + mem3.szMaster - nBlock;
15392 assert( newi > mem3.iMaster+1 );
15393 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = nBlock;
15394 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x |= 2;
15395 mem3.aPool[newi-1].u.hdr.size4x = nBlock*4 + 1;
15396 mem3.szMaster -= nBlock;
15397 mem3.aPool[newi-1].u.hdr.prevSize = mem3.szMaster;
15398 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
15399 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
15400 if( mem3.szMaster < mem3.mnMaster ){
15401 mem3.mnMaster = mem3.szMaster;
15403 return (void*)&mem3.aPool[newi];
15410 ** mem3.aiSmall[] or mem3.aiHash[].
15415 ** If it sees a chunk that is larger than mem3.iMaster, it replaces
15416 ** the current mem3.iMaster with the new larger chunk. In order for
15417 ** this mem3.iMaster replacement to work, the master chunk must be
15426 assert( sqlite3_mutex_held(mem3.mutex) );
15428 iNext = mem3.aPool[i].u.list.next;
15429 size = mem3.aPool[i-1].u.hdr.size4x;
15433 assert( i > mem3.aPool[i-1].u.hdr.prevSize );
15434 prev = i - mem3.aPool[i-1].u.hdr.prevSize;
15436 iNext = mem3.aPool[prev].u.list.next;
15440 x = mem3.aPool[prev-1].u.hdr.size4x & 2;
15441 mem3.aPool[prev-1].u.hdr.size4x = size*4 | x;
15442 mem3.aPool[prev+size-1].u.hdr.prevSize = size;
15448 if( size>mem3.szMaster ){
15449 mem3.iMaster = i;
15450 mem3.szMaster = size;
15467 assert( sqlite3_mutex_held(mem3.mutex) );
15482 i = mem3.aiSmall[nBlock-2];
15484 memsys3UnlinkFromList(i, &mem3.aiSmall[nBlock-2]);
15489 for(i=mem3.aiHash[hash]; i>0; i=mem3.aPool[i].u.list.next){
15490 if( mem3.aPool[i-1].u.hdr.size4x/4==nBlock ){
15491 memsys3UnlinkFromList(i, &mem3.aiHash[hash]);
15501 if( mem3.szMaster>=nBlock ){
15513 for(toFree=nBlock*16; toFree<(mem3.nPool*16); toFree *= 2){
15515 if( mem3.iMaster ){
15516 memsys3Link(mem3.iMaster);
15517 mem3.iMaster = 0;
15518 mem3.szMaster = 0;
15521 memsys3Merge(&mem3.aiHash[i]);
15524 memsys3Merge(&mem3.aiSmall[i]);
15526 if( mem3.szMaster ){
15527 memsys3Unlink(mem3.iMaster);
15528 if( mem3.szMaster>=nBlock ){
15548 assert( sqlite3_mutex_held(mem3.mutex) );
15549 assert( p>mem3.aPool && p<&mem3.aPool[mem3.nPool] );
15550 i = p - mem3.aPool;
15551 assert( (mem3.aPool[i-1].u.hdr.size4x&1)==1 );
15552 size = mem3.aPool[i-1].u.hdr.size4x/4;
15553 assert( i+size<=mem3.nPool+1 );
15554 mem3.aPool[i-1].u.hdr.size4x &= ~1;
15555 mem3.aPool[i+size-1].u.hdr.prevSize = size;
15556 mem3.aPool[i+size-1].u.hdr.size4x &= ~2;
15560 if( mem3.iMaster ){
15561 while( (mem3.aPool[mem3.iMaster-1].u.hdr.size4x&2)==0 ){
15562 size = mem3.aPool[mem3.iMaster-1].u.hdr.prevSize;
15563 mem3.iMaster -= size;
15564 mem3.szMaster += size;
15565 memsys3Unlink(mem3.iMaster);
15566 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
15567 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
15568 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = mem3.szMaster;
15570 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
15571 while( (mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x&1)==0 ){
15572 memsys3Unlink(mem3.iMaster+mem3.szMaster);
15573 mem3.szMaster += mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x/4;
15574 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
15575 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = mem3.szMaster;
15666 /* Store a pointer to the memory block in global structure mem3. */
15668 mem3.aPool = (Mem3Block *)sqlite3GlobalConfig.pHeap;
15669 mem3.nPool = (sqlite3GlobalConfig.nHeap / sizeof(Mem3Block)) - 2;
15672 mem3.szMaster = mem3.nPool;
15673 mem3.mnMaster = mem3.szMaster;
15674 mem3.iMaster = 1;
15675 mem3.aPool[0].u.hdr.size4x = (mem3.szMaster<<2) + 2;
15676 mem3.aPool[mem3.nPool].u.hdr.prevSize = mem3.nPool;
15677 mem3.aPool[mem3.nPool].u.hdr.size4x = 1;
15687 mem3.mutex = 0;
15714 for(i=1; i<=mem3.nPool; i+=size/4){
15715 size = mem3.aPool[i-1].u.hdr.size4x;
15717 fprintf(out, "%p size error\n", &mem3.aPool[i]);
15721 if( (size&1)==0 && mem3.aPool[i+size/4-1].u.hdr.prevSize!=size/4 ){
15722 fprintf(out, "%p tail size does not match\n", &mem3.aPool[i]);
15726 if( ((mem3.aPool[i+size/4-1].u.hdr.size4x&2)>>1)!=(size&1) ){
15727 fprintf(out, "%p tail checkout bit is incorrect\n", &mem3.aPool[i]);
15732 fprintf(out, "%p %6d bytes checked out\n", &mem3.aPool[i], (size/4)*8-8);
15734 fprintf(out, "%p %6d bytes free%s\n", &mem3.aPool[i], (size/4)*8-8,
15735 i==mem3.iMaster ? " **master**" : "");
15739 if( mem3.aiSmall[i]==0 ) continue;
15741 for(j = mem3.aiSmall[i]; j>0; j=mem3.aPool[j].u.list.next){
15742 fprintf(out, " %p(%d)", &mem3.aPool[j],
15743 (mem3.aPool[j-1].u.hdr.size4x/4)*8-8);
15748 if( mem3.aiHash[i]==0 ) continue;
15750 for(j = mem3.aiHash[i]; j>0; j=mem3.aPool[j].u.list.next){
15751 fprintf(out, " %p(%d)", &mem3.aPool[j],
15752 (mem3.aPool[j-1].u.hdr.size4x/4)*8-8);
15756 fprintf(out, "master=%d\n", mem3.iMaster);
15757 fprintf(out, "nowUsed=%d\n", mem3.nPool*8 - mem3.szMaster*8);
15758 fprintf(out, "mxUsed=%d\n", mem3.nPool*8 - mem3.mnMaster*8);
15759 sqlite3_mutex_leave(mem3.mutex);
15797 /************** End of mem3.c ************************************************/
107639 ** mem5.c/mem3.c methods. If neither ENABLE_MEMSYS3 nor