Lines Matching defs:mem3
14869 /************** Begin file mem3.c ********************************************/
14933 ** We often identify a chunk by its index in mem3.aPool[]. When
14941 ** Pointers to the head of the list are stored in mem3.aiSmall[]
14942 ** for smaller chunks and mem3.aiHash[] for larger chunks.
14956 u32 next; /* Index in mem3.aPool[] of next free chunk */
14957 u32 prev; /* Index in mem3.aPool[] of previous free chunk */
14964 ** into a single structure named "mem3". This is to keep the
15007 } mem3 = { 97535575 };
15009 #define mem3 GLOBAL(struct Mem3Global, mem3)
15012 ** Unlink the chunk at mem3.aPool[i] from list it is currently
15016 u32 next = mem3.aPool[i].u.list.next;
15017 u32 prev = mem3.aPool[i].u.list.prev;
15018 assert( sqlite3_mutex_held(mem3.mutex) );
15022 mem3.aPool[prev].u.list.next = next;
15025 mem3.aPool[next].u.list.prev = prev;
15027 mem3.aPool[i].u.list.next = 0;
15028 mem3.aPool[i].u.list.prev = 0;
15037 assert( sqlite3_mutex_held(mem3.mutex) );
15038 assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 );
15040 size = mem3.aPool[i-1].u.hdr.size4x/4;
15041 assert( size==mem3.aPool[i+size-1].u.hdr.prevSize );
15044 memsys3UnlinkFromList(i, &mem3.aiSmall[size-2]);
15047 memsys3UnlinkFromList(i, &mem3.aiHash[hash]);
15052 ** Link the chunk at mem3.aPool[i] so that is on the list rooted
15056 assert( sqlite3_mutex_held(mem3.mutex) );
15057 mem3.aPool[i].u.list.next = *pRoot;
15058 mem3.aPool[i].u.list.prev = 0;
15060 mem3.aPool[*pRoot].u.list.prev = i;
15071 assert( sqlite3_mutex_held(mem3.mutex) );
15073 assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 );
15074 size = mem3.aPool[i-1].u.hdr.size4x/4;
15075 assert( size==mem3.aPool[i+size-1].u.hdr.prevSize );
15078 memsys3LinkIntoList(i, &mem3.aiSmall[size-2]);
15081 memsys3LinkIntoList(i, &mem3.aiHash[hash]);
15091 if( sqlite3GlobalConfig.bMemstat==0 && mem3.mutex==0 ){
15092 mem3.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
15094 sqlite3_mutex_enter(mem3.mutex);
15097 sqlite3_mutex_leave(mem3.mutex);
15104 if( !mem3.alarmBusy ){
15105 mem3.alarmBusy = 1;
15106 assert( sqlite3_mutex_held(mem3.mutex) );
15107 sqlite3_mutex_leave(mem3.mutex);
15109 sqlite3_mutex_enter(mem3.mutex);
15110 mem3.alarmBusy = 0;
15122 assert( sqlite3_mutex_held(mem3.mutex) );
15124 assert( mem3.aPool[i-1].u.hdr.size4x/4==nBlock );
15125 assert( mem3.aPool[i+nBlock-1].u.hdr.prevSize==nBlock );
15126 x = mem3.aPool[i-1].u.hdr.size4x;
15127 mem3.aPool[i-1].u.hdr.size4x = nBlock*4 | 1 | (x&2);
15128 mem3.aPool[i+nBlock-1].u.hdr.prevSize = nBlock;
15129 mem3.aPool[i+nBlock-1].u.hdr.size4x |= 2;
15130 return &mem3.aPool[i];
15134 ** Carve a piece off of the end of the mem3.iMaster free chunk.
15139 assert( sqlite3_mutex_held(mem3.mutex) );
15140 assert( mem3.szMaster>=nBlock );
15141 if( nBlock>=mem3.szMaster-1 ){
15143 void *p = memsys3Checkout(mem3.iMaster, mem3.szMaster);
15144 mem3.iMaster = 0;
15145 mem3.szMaster = 0;
15146 mem3.mnMaster = 0;
15151 newi = mem3.iMaster + mem3.szMaster - nBlock;
15152 assert( newi > mem3.iMaster+1 );
15153 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = nBlock;
15154 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x |= 2;
15155 mem3.aPool[newi-1].u.hdr.size4x = nBlock*4 + 1;
15156 mem3.szMaster -= nBlock;
15157 mem3.aPool[newi-1].u.hdr.prevSize = mem3.szMaster;
15158 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
15159 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
15160 if( mem3.szMaster < mem3.mnMaster ){
15161 mem3.mnMaster = mem3.szMaster;
15163 return (void*)&mem3.aPool[newi];
15170 ** mem3.aiSmall[] or mem3.aiHash[].
15175 ** If it sees a chunk that is larger than mem3.iMaster, it replaces
15176 ** the current mem3.iMaster with the new larger chunk. In order for
15177 ** this mem3.iMaster replacement to work, the master chunk must be
15186 assert( sqlite3_mutex_held(mem3.mutex) );
15188 iNext = mem3.aPool[i].u.list.next;
15189 size = mem3.aPool[i-1].u.hdr.size4x;
15193 assert( i > mem3.aPool[i-1].u.hdr.prevSize );
15194 prev = i - mem3.aPool[i-1].u.hdr.prevSize;
15196 iNext = mem3.aPool[prev].u.list.next;
15200 x = mem3.aPool[prev-1].u.hdr.size4x & 2;
15201 mem3.aPool[prev-1].u.hdr.size4x = size*4 | x;
15202 mem3.aPool[prev+size-1].u.hdr.prevSize = size;
15208 if( size>mem3.szMaster ){
15209 mem3.iMaster = i;
15210 mem3.szMaster = size;
15227 assert( sqlite3_mutex_held(mem3.mutex) );
15242 i = mem3.aiSmall[nBlock-2];
15244 memsys3UnlinkFromList(i, &mem3.aiSmall[nBlock-2]);
15249 for(i=mem3.aiHash[hash]; i>0; i=mem3.aPool[i].u.list.next){
15250 if( mem3.aPool[i-1].u.hdr.size4x/4==nBlock ){
15251 memsys3UnlinkFromList(i, &mem3.aiHash[hash]);
15261 if( mem3.szMaster>=nBlock ){
15273 for(toFree=nBlock*16; toFree<(mem3.nPool*16); toFree *= 2){
15275 if( mem3.iMaster ){
15276 memsys3Link(mem3.iMaster);
15277 mem3.iMaster = 0;
15278 mem3.szMaster = 0;
15281 memsys3Merge(&mem3.aiHash[i]);
15284 memsys3Merge(&mem3.aiSmall[i]);
15286 if( mem3.szMaster ){
15287 memsys3Unlink(mem3.iMaster);
15288 if( mem3.szMaster>=nBlock ){
15308 assert( sqlite3_mutex_held(mem3.mutex) );
15309 assert( p>mem3.aPool && p<&mem3.aPool[mem3.nPool] );
15310 i = p - mem3.aPool;
15311 assert( (mem3.aPool[i-1].u.hdr.size4x&1)==1 );
15312 size = mem3.aPool[i-1].u.hdr.size4x/4;
15313 assert( i+size<=mem3.nPool+1 );
15314 mem3.aPool[i-1].u.hdr.size4x &= ~1;
15315 mem3.aPool[i+size-1].u.hdr.prevSize = size;
15316 mem3.aPool[i+size-1].u.hdr.size4x &= ~2;
15320 if( mem3.iMaster ){
15321 while( (mem3.aPool[mem3.iMaster-1].u.hdr.size4x&2)==0 ){
15322 size = mem3.aPool[mem3.iMaster-1].u.hdr.prevSize;
15323 mem3.iMaster -= size;
15324 mem3.szMaster += size;
15325 memsys3Unlink(mem3.iMaster);
15326 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
15327 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
15328 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = mem3.szMaster;
15330 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
15331 while( (mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x&1)==0 ){
15332 memsys3Unlink(mem3.iMaster+mem3.szMaster);
15333 mem3.szMaster += mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x/4;
15334 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
15335 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = mem3.szMaster;
15426 /* Store a pointer to the memory block in global structure mem3. */
15428 mem3.aPool = (Mem3Block *)sqlite3GlobalConfig.pHeap;
15429 mem3.nPool = (sqlite3GlobalConfig.nHeap / sizeof(Mem3Block)) - 2;
15432 mem3.szMaster = mem3.nPool;
15433 mem3.mnMaster = mem3.szMaster;
15434 mem3.iMaster = 1;
15435 mem3.aPool[0].u.hdr.size4x = (mem3.szMaster<<2) + 2;
15436 mem3.aPool[mem3.nPool].u.hdr.prevSize = mem3.nPool;
15437 mem3.aPool[mem3.nPool].u.hdr.size4x = 1;
15447 mem3.mutex = 0;
15474 for(i=1; i<=mem3.nPool; i+=size/4){
15475 size = mem3.aPool[i-1].u.hdr.size4x;
15477 fprintf(out, "%p size error\n", &mem3.aPool[i]);
15481 if( (size&1)==0 && mem3.aPool[i+size/4-1].u.hdr.prevSize!=size/4 ){
15482 fprintf(out, "%p tail size does not match\n", &mem3.aPool[i]);
15486 if( ((mem3.aPool[i+size/4-1].u.hdr.size4x&2)>>1)!=(size&1) ){
15487 fprintf(out, "%p tail checkout bit is incorrect\n", &mem3.aPool[i]);
15492 fprintf(out, "%p %6d bytes checked out\n", &mem3.aPool[i], (size/4)*8-8);
15494 fprintf(out, "%p %6d bytes free%s\n", &mem3.aPool[i], (size/4)*8-8,
15495 i==mem3.iMaster ? " **master**" : "");
15499 if( mem3.aiSmall[i]==0 ) continue;
15501 for(j = mem3.aiSmall[i]; j>0; j=mem3.aPool[j].u.list.next){
15502 fprintf(out, " %p(%d)", &mem3.aPool[j],
15503 (mem3.aPool[j-1].u.hdr.size4x/4)*8-8);
15508 if( mem3.aiHash[i]==0 ) continue;
15510 for(j = mem3.aiHash[i]; j>0; j=mem3.aPool[j].u.list.next){
15511 fprintf(out, " %p(%d)", &mem3.aPool[j],
15512 (mem3.aPool[j-1].u.hdr.size4x/4)*8-8);
15516 fprintf(out, "master=%d\n", mem3.iMaster);
15517 fprintf(out, "nowUsed=%d\n", mem3.nPool*8 - mem3.szMaster*8);
15518 fprintf(out, "mxUsed=%d\n", mem3.nPool*8 - mem3.mnMaster*8);
15519 sqlite3_mutex_leave(mem3.mutex);
15557 /************** End of mem3.c ************************************************/
105201 ** mem5.c/mem3.c methods. If neither ENABLE_MEMSYS3 nor