Home | History | Annotate | Download | only in dist

Lines Matching defs:mem3

15988 /************** Begin file mem3.c ********************************************/
16052 ** We often identify a chunk by its index in mem3.aPool[]. When
16060 ** Pointers to the head of the list are stored in mem3.aiSmall[]
16061 ** for smaller chunks and mem3.aiHash[] for larger chunks.
16075 u32 next; /* Index in mem3.aPool[] of next free chunk */
16076 u32 prev; /* Index in mem3.aPool[] of previous free chunk */
16083 ** into a single structure named "mem3". This is to keep the
16126 } mem3 = { 97535575 };
16128 #define mem3 GLOBAL(struct Mem3Global, mem3)
16131 ** Unlink the chunk at mem3.aPool[i] from list it is currently
16135 u32 next = mem3.aPool[i].u.list.next;
16136 u32 prev = mem3.aPool[i].u.list.prev;
16137 assert( sqlite3_mutex_held(mem3.mutex) );
16141 mem3.aPool[prev].u.list.next = next;
16144 mem3.aPool[next].u.list.prev = prev;
16146 mem3.aPool[i].u.list.next = 0;
16147 mem3.aPool[i].u.list.prev = 0;
16156 assert( sqlite3_mutex_held(mem3.mutex) );
16157 assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 );
16159 size = mem3.aPool[i-1].u.hdr.size4x/4;
16160 assert( size==mem3.aPool[i+size-1].u.hdr.prevSize );
16163 memsys3UnlinkFromList(i, &mem3.aiSmall[size-2]);
16166 memsys3UnlinkFromList(i, &mem3.aiHash[hash]);
16171 ** Link the chunk at mem3.aPool[i] so that is on the list rooted
16175 assert( sqlite3_mutex_held(mem3.mutex) );
16176 mem3.aPool[i].u.list.next = *pRoot;
16177 mem3.aPool[i].u.list.prev = 0;
16179 mem3.aPool[*pRoot].u.list.prev = i;
16190 mem3.mutex) );
16192 assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 );
16193 size = mem3.aPool[i-1].u.hdr.size4x/4;
16194 assert( size==mem3.aPool[i+size-1].u.hdr.prevSize );
16197 memsys3LinkIntoList(i, &mem3.aiSmall[size-2]);
16200 memsys3LinkIntoList(i, &mem3.aiHash[hash]);
16210 if( sqlite3GlobalConfig.bMemstat==0 && mem3.mutex==0 ){
16211 mem3.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
16213 sqlite3_mutex_enter(mem3.mutex);
16216 sqlite3_mutex_leave(mem3.mutex);
16223 if( !mem3.alarmBusy ){
16224 mem3.alarmBusy = 1;
16225 assert( sqlite3_mutex_held(mem3.mutex) );
16226 sqlite3_mutex_leave(mem3.mutex);
16228 sqlite3_mutex_enter(mem3.mutex);
16229 mem3.alarmBusy = 0;
16241 assert( sqlite3_mutex_held(mem3.mutex) );
16243 assert( mem3.aPool[i-1].u.hdr.size4x/4==nBlock );
16244 assert( mem3.aPool[i+nBlock-1].u.hdr.prevSize==nBlock );
16245 x = mem3.aPool[i-1].u.hdr.size4x;
16246 mem3.aPool[i-1].u.hdr.size4x = nBlock*4 | 1 | (x&2);
16247 mem3.aPool[i+nBlock-1].u.hdr.prevSize = nBlock;
16248 mem3.aPool[i+nBlock-1].u.hdr.size4x |= 2;
16249 return &mem3.aPool[i];
16253 ** Carve a piece off of the end of the mem3.iMaster free chunk.
16258 assert( sqlite3_mutex_held(mem3.mutex) );
16259 assert( mem3.szMaster>=nBlock );
16260 if( nBlock>=mem3.szMaster-1 ){
16262 void *p = memsys3Checkout(mem3.iMaster, mem3.szMaster);
16263 mem3.iMaster = 0;
16264 mem3.szMaster = 0;
16265 mem3.mnMaster = 0;
16270 newi = mem3.iMaster + mem3.szMaster - nBlock;
16271 assert( newi > mem3.iMaster+1 );
16272 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = nBlock;
16273 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x |= 2;
16274 mem3.aPool[newi-1].u.hdr.size4x = nBlock*4 + 1;
16275 mem3.szMaster -= nBlock;
16276 mem3.aPool[newi-1].u.hdr.prevSize = mem3.szMaster;
16277 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
16278 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
16279 if( mem3.szMaster < mem3.mnMaster ){
16280 mem3.mnMaster = mem3.szMaster;
16282 return (void*)&mem3.aPool[newi];
16289 ** mem3.aiSmall[] or mem3.aiHash[].
16294 ** If it sees a chunk that is larger than mem3.iMaster, it replaces
16295 ** the current mem3.iMaster with the new larger chunk. In order for
16296 ** this mem3.iMaster replacement to work, the master chunk must be
16305 assert( sqlite3_mutex_held(mem3.mutex) );
16307 iNext = mem3.aPool[i].u.list.next;
16308 size = mem3.aPool[i-1].u.hdr.size4x;
16312 assert( i > mem3.aPool[i-1].u.hdr.prevSize );
16313 prev = i - mem3.aPool[i-1].u.hdr.prevSize;
16315 iNext = mem3.aPool[prev].u.list.next;
16319 x = mem3.aPool[prev-1].u.hdr.size4x & 2;
16320 mem3.aPool[prev-1].u.hdr.size4x = size*4 | x;
16321 mem3.aPool[prev+size-1].u.hdr.prevSize = size;
16327 if( size>mem3.szMaster ){
16328 mem3.iMaster = i;
16329 mem3.szMaster = size;
16346 assert( sqlite3_mutex_held(mem3.mutex) );
16361 i = mem3.aiSmall[nBlock-2];
16363 memsys3UnlinkFromList(i, &mem3.aiSmall[nBlock-2]);
16368 for(i=mem3.aiHash[hash]; i>0; i=mem3.aPool[i].u.list.next){
16369 if( mem3.aPool[i-1].u.hdr.size4x/4==nBlock ){
16370 memsys3UnlinkFromList(i, &mem3.aiHash[hash]);
16380 if( mem3.szMaster>=nBlock ){
16392 for(toFree=nBlock*16; toFree<(mem3.nPool*16); toFree *= 2){
16394 if( mem3.iMaster ){
16395 memsys3Link(mem3.iMaster);
16396 mem3.iMaster = 0;
16397 mem3.szMaster = 0;
16400 memsys3Merge(&mem3.aiHash[i]);
16403 memsys3Merge(&mem3.aiSmall[i]);
16405 if( mem3.szMaster ){
16406 memsys3Unlink(mem3.iMaster);
16407 if( mem3.szMaster>=nBlock ){
16427 assert( sqlite3_mutex_held(mem3.mutex) );
16428 assert( p>mem3.aPool && p<&mem3.aPool[mem3.nPool] );
16429 i = p - mem3.aPool;
16430 assert( (mem3.aPool[i-1].u.hdr.size4x&1)==1 );
16431 size = mem3.aPool[i-1].u.hdr.size4x/4;
16432 assert( i+size<=mem3.nPool+1 );
16433 mem3.aPool[i-1].u.hdr.size4x &= ~1;
16434 mem3.aPool[i+size-1].u.hdr.prevSize = size;
16435 mem3.aPool[i+size-1].u.hdr.size4x &= ~2;
16439 if( mem3.iMaster ){
16440 while( (mem3.aPool[mem3.iMaster-1].u.hdr.size4x&2)==0 ){
16441 size = mem3.aPool[mem3.iMaster-1].u.hdr.prevSize;
16442 mem3.iMaster -= size;
16443 mem3.szMaster += size;
16444 memsys3Unlink(mem3.iMaster);
16445 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
16446 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
16447 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = mem3.szMaster;
16449 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
16450 while( (mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x&1)==0 ){
16451 memsys3Unlink(mem3.iMaster+mem3.szMaster);
16452 mem3.szMaster += mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x/4;
16453 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
16454 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = mem3.szMaster;
16545 /* Store a pointer to the memory block in global structure mem3. */
16547 mem3.aPool = (Mem3Block *)sqlite3GlobalConfig.pHeap;
16548 mem3.nPool = (sqlite3GlobalConfig.nHeap / sizeof(Mem3Block)) - 2;
16551 mem3.szMaster = mem3.nPool;
16552 mem3.mnMaster = mem3.szMaster;
16553 mem3.iMaster = 1;
16554 mem3.aPool[0].u.hdr.size4x = (mem3.szMaster<<2) + 2;
16555 mem3.aPool[mem3.nPool].u.hdr.prevSize = mem3.nPool;
16556 mem3.aPool[mem3.nPool].u.hdr.size4x = 1;
16566 mem3.mutex = 0;
16593 for(i=1; i<=mem3.nPool; i+=size/4){
16594 size = mem3.aPool[i-1].u.hdr.size4x;
16596 fprintf(out, "%p size error\n", &mem3.aPool[i]);
16600 if( (size&1)==0 && mem3.aPool[i+size/4-1].u.hdr.prevSize!=size/4 ){
16601 fprintf(out, "%p tail size does not match\n", &mem3.aPool[i]);
16605 if( ((mem3.aPool[i+size/4-1].u.hdr.size4x&2)>>1)!=(size&1) ){
16606 fprintf(out, "%p tail checkout bit is incorrect\n", &mem3.aPool[i]);
16611 fprintf(out, "%p %6d bytes checked out\n", &mem3.aPool[i], (size/4)*8-8);
16613 fprintf(out, "%p %6d bytes free%s\n", &mem3.aPool[i], (size/4)*8-8,
16614 i==mem3.iMaster ? " **master**" : "");
16618 if( mem3.aiSmall[i]==0 ) continue;
16620 for(j = mem3.aiSmall[i]; j>0; j=mem3.aPool[j].u.list.next){
16621 fprintf(out, " %p(%d)", &mem3.aPool[j],
16622 (mem3.aPool[j-1].u.hdr.size4x/4)*8-8);
16627 if( mem3.aiHash[i]==0 ) continue;
16629 for(j = mem3.aiHash[i]; j>0; j=mem3.aPool[j].u.list.next){
16630 fprintf(out, " %p(%d)", &mem3.aPool[j],
16631 (mem3.aPool[j-1].u.hdr.size4x/4)*8-8);
16635 fprintf(out, "master=%d\n", mem3.iMaster);
16636 fprintf(out, "nowUsed=%d\n", mem3.nPool*8 - mem3.szMaster*8);
16637 fprintf(out, "mxUsed=%d\n", mem3.nPool*8 - mem3.mnMaster*8);
16638 sqlite3_mutex_leave(mem3.mutex);
16676 /************** End of mem3.c ************************************************/
112889 ** mem5.c/mem3.c methods. If neither ENABLE_MEMSYS3 nor