Home | History | Annotate | Download | only in dist

Lines Matching refs:mem3

21533 /************** Begin file mem3.c ********************************************/
21598 ** We often identify a chunk by its index in mem3.aPool[]. When
21606 ** Pointers to the head of the list are stored in mem3.aiSmall[]
21607 ** for smaller chunks and mem3.aiHash[] for larger chunks.
21621 u32 next; /* Index in mem3.aPool[] of next free chunk */
21622 u32 prev; /* Index in mem3.aPool[] of previous free chunk */
21629 ** into a single structure named "mem3". This is to keep the
21672 } mem3 = { 97535575 };
21674 #define mem3 GLOBAL(struct Mem3Global, mem3)
21677 ** Unlink the chunk at mem3.aPool[i] from list it is currently
21681 u32 next = mem3.aPool[i].u.list.next;
21682 u32 prev = mem3.aPool[i].u.list.prev;
21683 assert( sqlite3_mutex_held(mem3.mutex) );
21687 mem3.aPool[prev].u.list.next = next;
21690 mem3.aPool[next].u.list.prev = prev;
21692 mem3.aPool[i].u.list.next = 0;
21693 mem3.aPool[i].u.list.prev = 0;
21702 assert( sqlite3_mutex_held(mem3.mutex) );
21703 assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 );
21705 size = mem3.aPool[i-1].u.hdr.size4x/4;
21706 assert( size==mem3.aPool[i+size-1].u.hdr.prevSize );
21709 memsys3UnlinkFromList(i, &mem3.aiSmall[size-2]);
21712 memsys3UnlinkFromList(i, &mem3.aiHash[hash]);
21717 ** Link the chunk at mem3.aPool[i] so that is on the list rooted
21721 assert( sqlite3_mutex_held(mem3.mutex) );
21722 mem3.aPool[i].u.list.next = *pRoot;
21723 mem3.aPool[i].u.list.prev = 0;
21725 mem3.aPool[*pRoot].u.list.prev = i;
21736 assert( sqlite3_mutex_held(mem3.mutex) );
21738 assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 );
21739 size = mem3.aPool[i-1].u.hdr.size4x/4;
21740 assert( size==mem3.aPool[i+size-1].u.hdr.prevSize );
21743 memsys3LinkIntoList(i, &mem3.aiSmall[size-2]);
21746 memsys3LinkIntoList(i, &mem3.aiHash[hash]);
21756 if( sqlite3GlobalConfig.bMemstat==0 && mem3.mutex==0 ){
21757 mem3.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
21759 sqlite3_mutex_enter(mem3.mutex);
21762 sqlite3_mutex_leave(mem3.mutex);
21769 if( !mem3.alarmBusy ){
21770 mem3.alarmBusy = 1;
21771 assert( sqlite3_mutex_held(mem3.mutex) );
21772 sqlite3_mutex_leave(mem3.mutex);
21774 sqlite3_mutex_enter(mem3.mutex);
21775 mem3.alarmBusy = 0;
21787 assert( sqlite3_mutex_held(mem3.mutex) );
21789 assert( mem3.aPool[i-1].u.hdr.size4x/4==nBlock );
21790 assert( mem3.aPool[i+nBlock-1].u.hdr.prevSize==nBlock );
21791 x = mem3.aPool[i-1].u.hdr.size4x;
21792 mem3.aPool[i-1].u.hdr.size4x = nBlock*4 | 1 | (x&2);
21793 mem3.aPool[i+nBlock-1].u.hdr.prevSize = nBlock;
21794 mem3.aPool[i+nBlock-1].u.hdr.size4x |= 2;
21795 return &mem3.aPool[i];
21799 ** Carve a piece off of the end of the mem3.iMaster free chunk.
21804 assert( sqlite3_mutex_held(mem3.mutex) );
21805 assert( mem3.szMaster>=nBlock );
21806 if( nBlock>=mem3.szMaster-1 ){
21808 void *p = memsys3Checkout(mem3.iMaster, mem3.szMaster);
21809 mem3.iMaster = 0;
21810 mem3.szMaster = 0;
21811 mem3.mnMaster = 0;
21816 newi = mem3.iMaster + mem3.szMaster - nBlock;
21817 assert( newi > mem3.iMaster+1 );
21818 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = nBlock;
21819 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x |= 2;
21820 mem3.aPool[newi-1].u.hdr.size4x = nBlock*4 + 1;
21821 mem3.szMaster -= nBlock;
21822 mem3.aPool[newi-1].u.hdr.prevSize = mem3.szMaster;
21823 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
21824 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
21825 if( mem3.szMaster < mem3.mnMaster ){
21826 mem3.mnMaster = mem3.szMaster;
21828 return (void*)&mem3.aPool[newi];
21835 ** mem3.aiSmall[] or mem3.aiHash[].
21840 ** If it sees a chunk that is larger than mem3.iMaster, it replaces
21841 ** the current mem3.iMaster with the new larger chunk. In order for
21842 ** this mem3.iMaster replacement to work, the master chunk must be
21851 assert( sqlite3_mutex_held(mem3.mutex) );
21853 iNext = mem3.aPool[i].u.list.next;
21854 size = mem3.aPool[i-1].u.hdr.size4x;
21858 assert( i > mem3.aPool[i-1].u.hdr.prevSize );
21859 prev = i - mem3.aPool[i-1].u.hdr.prevSize;
21861 iNext = mem3.aPool[prev].u.list.next;
21865 x = mem3.aPool[prev-1].u.hdr.size4x & 2;
21866 mem3.aPool[prev-1].u.hdr.size4x = size*4 | x;
21867 mem3.aPool[prev+size-1].u.hdr.prevSize = size;
21873 if( size>mem3.szMaster ){
21874 mem3.iMaster = i;
21875 mem3.szMaster = size;
21892 assert( sqlite3_mutex_held(mem3.mutex) );
21907 i = mem3.aiSmall[nBlock-2];
21909 memsys3UnlinkFromList(i, &mem3.aiSmall[nBlock-2]);
21914 for(i=mem3.aiHash[hash]; i>0; i=mem3.aPool[i].u.list.next){
21915 if( mem3.aPool[i-1].u.hdr.size4x/4==nBlock ){
21916 memsys3UnlinkFromList(i, &mem3.aiHash[hash]);
21926 if( mem3.szMaster>=nBlock ){
21938 for(toFree=nBlock*16; toFree<(mem3.nPool*16); toFree *= 2){
21940 if( mem3.iMaster ){
21941 memsys3Link(mem3.iMaster);
21942 mem3.iMaster = 0;
21943 mem3.szMaster = 0;
21946 memsys3Merge(&mem3.aiHash[i]);
21949 memsys3Merge(&mem3.aiSmall[i]);
21951 if( mem3.szMaster ){
21952 memsys3Unlink(mem3.iMaster);
21953 if( mem3.szMaster>=nBlock ){
21973 assert( sqlite3_mutex_held(mem3.mutex) );
21974 assert( p>mem3.aPool && p<&mem3.aPool[mem3.nPool] );
21975 i = p - mem3.aPool;
21976 assert( (mem3.aPool[i-1].u.hdr.size4x&1)==1 );
21977 size = mem3.aPool[i-1].u.hdr.size4x/4;
21978 assert( i+size<=mem3.nPool+1 );
21979 mem3.aPool[i-1].u.hdr.size4x &= ~1;
21980 mem3.aPool[i+size-1].u.hdr.prevSize = size;
21981 mem3.aPool[i+size-1].u.hdr.size4x &= ~2;
21985 if( mem3.iMaster ){
21986 while( (mem3.aPool[mem3.iMaster-1].u.hdr.size4x&2)==0 ){
21987 size = mem3.aPool[mem3.iMaster-1].u.hdr.prevSize;
21988 mem3.iMaster -= size;
21989 mem3.szMaster += size;
21990 memsys3Unlink(mem3.iMaster);
21991 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
21992 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
21993 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = mem3.szMaster;
21995 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
21996 while( (mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x&1)==0 ){
21997 memsys3Unlink(mem3.iMaster+mem3.szMaster);
21998 mem3.szMaster += mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x/4;
21999 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
22000 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = mem3.szMaster;
22091 /* Store a pointer to the memory block in global structure mem3. */
22093 mem3.aPool = (Mem3Block *)sqlite3GlobalConfig.pHeap;
22094 mem3.nPool = (sqlite3GlobalConfig.nHeap / sizeof(Mem3Block)) - 2;
22097 mem3.szMaster = mem3.nPool;
22098 mem3.mnMaster = mem3.szMaster;
22099 mem3.iMaster = 1;
22100 mem3.aPool[0].u.hdr.size4x = (mem3.szMaster<<2) + 2;
22101 mem3.aPool[mem3.nPool].u.hdr.prevSize = mem3.nPool;
22102 mem3.aPool[mem3.nPool].u.hdr.size4x = 1;
22112 mem3.mutex = 0;
22139 for(i=1; i<=mem3.nPool; i+=size/4){
22140 size = mem3.aPool[i-1].u.hdr.size4x;
22142 fprintf(out, "%p size error\n", &mem3.aPool[i]);
22146 if( (size&1)==0 && mem3.aPool[i+size/4-1].u.hdr.prevSize!=size/4 ){
22147 fprintf(out, "%p tail size does not match\n", &mem3.aPool[i]);
22151 if( ((mem3.aPool[i+size/4-1].u.hdr.size4x&2)>>1)!=(size&1) ){
22152 fprintf(out, "%p tail checkout bit is incorrect\n", &mem3.aPool[i]);
22157 fprintf(out, "%p %6d bytes checked out\n", &mem3.aPool[i], (size/4)*8-8);
22159 fprintf(out, "%p %6d bytes free%s\n", &mem3.aPool[i], (size/4)*8-8,
22160 i==mem3.iMaster ? " **master**" : "");
22164 if( mem3.aiSmall[i]==0 ) continue;
22166 for(j = mem3.aiSmall[i]; j>0; j=mem3.aPool[j].u.list.next){
22167 fprintf(out, " %p(%d)", &mem3
22168 (mem3.aPool[j-1].u.hdr.size4x/4)*8-8);
22173 if( mem3.aiHash[i]==0 ) continue;
22175 for(j = mem3.aiHash[i]; j>0; j=mem3.aPool[j].u.list.next){
22176 fprintf(out, " %p(%d)", &mem3.aPool[j],
22177 (mem3.aPool[j-1].u.hdr.size4x/4)*8-8);
22181 fprintf(out, "master=%d\n", mem3.iMaster);
22182 fprintf(out, "nowUsed=%d\n", mem3.nPool*8 - mem3.szMaster*8);
22183 fprintf(out, "mxUsed=%d\n", mem3.nPool*8 - mem3.mnMaster*8);
22184 sqlite3_mutex_leave(mem3.mutex);
22222 /************** End of mem3.c ************************************************/