Lines Matching refs:pCache

123   PCache1 *pCache;          /* Cache that currently owns this page */  member
301 static int pcache1InitBulk(PCache1 *pCache){ in pcache1InitBulk() argument
306 if( pCache->nMax<3 ) return 0; in pcache1InitBulk()
309 szBulk = pCache->szAlloc * (i64)pcache1.nInitPage; in pcache1InitBulk()
313 if( szBulk > pCache->szAlloc*(i64)pCache->nMax ){ in pcache1InitBulk()
314 szBulk = pCache->szAlloc*(i64)pCache->nMax; in pcache1InitBulk()
316 zBulk = pCache->pBulk = sqlite3Malloc( szBulk ); in pcache1InitBulk()
319 int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc; in pcache1InitBulk()
321 PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage]; in pcache1InitBulk()
326 pX->pNext = pCache->pFree; in pcache1InitBulk()
328 pCache->pFree = pX; in pcache1InitBulk()
329 zBulk += pCache->szAlloc; in pcache1InitBulk()
332 return pCache->pFree!=0; in pcache1InitBulk()
432 static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc){ in pcache1AllocPage() argument
436 assert( sqlite3_mutex_held(pCache->pGroup->mutex) ); in pcache1AllocPage()
437 if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){ in pcache1AllocPage()
438 assert( pCache->pFree!=0 ); in pcache1AllocPage()
439 p = pCache->pFree; in pcache1AllocPage()
440 pCache->pFree = p->pNext; in pcache1AllocPage()
448 assert( pCache->pGroup==&pcache1.grp ); in pcache1AllocPage()
449 pcache1LeaveMutex(pCache->pGroup); in pcache1AllocPage()
452 pPg = pcache1Alloc(pCache->szAlloc); in pcache1AllocPage()
455 pcache1EnterMutex(pCache->pGroup); in pcache1AllocPage()
458 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage]; in pcache1AllocPage()
465 (*pCache->pnPurgeable)++; in pcache1AllocPage()
473 PCache1 *pCache; in pcache1FreePage() local
475 pCache = p->pCache; in pcache1FreePage()
476 assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) ); in pcache1FreePage()
478 p->pNext = pCache->pFree; in pcache1FreePage()
479 pCache->pFree = p; in pcache1FreePage()
483 (*pCache->pnPurgeable)--; in pcache1FreePage()
520 static int pcache1UnderMemoryPressure(PCache1 *pCache){ in pcache1UnderMemoryPressure() argument
521 if( pcache1.nSlot && (pCache->szPage+pCache->szExtra)<=pcache1.szSlot ){ in pcache1UnderMemoryPressure()
583 assert( sqlite3_mutex_held(pPage->pCache->pGroup->mutex) ); in pcache1PinPage()
590 assert( pPage->pCache->pGroup->lru.isAnchor==1 ); in pcache1PinPage()
591 pPage->pCache->nRecyclable--; in pcache1PinPage()
605 PCache1 *pCache = pPage->pCache; in pcache1RemoveFromHash() local
608 assert( sqlite3_mutex_held(pCache->pGroup->mutex) ); in pcache1RemoveFromHash()
609 h = pPage->iKey % pCache->nHash; in pcache1RemoveFromHash()
610 for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext); in pcache1RemoveFromHash()
613 pCache->nPage--; in pcache1RemoveFromHash()
621 static void pcache1EnforceMaxPage(PCache1 *pCache){ in pcache1EnforceMaxPage() argument
622 PGroup *pGroup = pCache->pGroup; in pcache1EnforceMaxPage()
628 assert( p->pCache->pGroup==pGroup ); in pcache1EnforceMaxPage()
633 if( pCache->nPage==0 && pCache->pBulk ){ in pcache1EnforceMaxPage()
634 sqlite3_free(pCache->pBulk); in pcache1EnforceMaxPage()
635 pCache->pBulk = pCache->pFree = 0; in pcache1EnforceMaxPage()
647 PCache1 *pCache, /* The cache to truncate */ in pcache1TruncateUnsafe() argument
652 assert( sqlite3_mutex_held(pCache->pGroup->mutex) ); in pcache1TruncateUnsafe()
653 assert( pCache->iMaxKey >= iLimit ); in pcache1TruncateUnsafe()
654 assert( pCache->nHash > 0 ); in pcache1TruncateUnsafe()
655 if( pCache->iMaxKey - iLimit < pCache->nHash ){ in pcache1TruncateUnsafe()
660 h = iLimit % pCache->nHash; in pcache1TruncateUnsafe()
661 iStop = pCache->iMaxKey % pCache->nHash; in pcache1TruncateUnsafe()
666 h = pCache->nHash/2; in pcache1TruncateUnsafe()
672 assert( h<pCache->nHash ); in pcache1TruncateUnsafe()
673 pp = &pCache->apHash[h]; in pcache1TruncateUnsafe()
676 pCache->nPage--; in pcache1TruncateUnsafe()
686 h = (h+1) % pCache->nHash; in pcache1TruncateUnsafe()
688 assert( nPage<0 || pCache->nPage==(unsigned)nPage ); in pcache1TruncateUnsafe()
765 PCache1 *pCache; /* The newly created page cache */ in pcache1Create() local
773 pCache = (PCache1 *)sqlite3MallocZero(sz); in pcache1Create()
774 if( pCache ){ in pcache1Create()
776 pGroup = (PGroup*)&pCache[1]; in pcache1Create()
786 pCache->pGroup = pGroup; in pcache1Create()
787 pCache->szPage = szPage; in pcache1Create()
788 pCache->szExtra = szExtra; in pcache1Create()
789 pCache->szAlloc = szPage + szExtra + ROUND8(sizeof(PgHdr1)); in pcache1Create()
790 pCache->bPurgeable = (bPurgeable ? 1 : 0); in pcache1Create()
791 pcache1ResizeHash(pCache); in pcache1Create()
793 pCache->nMin = 10; in pcache1Create()
794 pGroup->nMinPage += pCache->nMin; in pcache1Create()
796 pCache->pnPurgeable = &pGroup->nPurgeable; in pcache1Create()
798 pCache->pnPurgeable = &pCache->nPurgeableDummy; in pcache1Create()
801 if( pCache->nHash==0 ){ in pcache1Create()
802 pcache1Destroy((sqlite3_pcache*)pCache); in pcache1Create()
803 pCache = 0; in pcache1Create()
806 return (sqlite3_pcache *)pCache; in pcache1Create()
815 PCache1 *pCache = (PCache1 *)p; in pcache1Cachesize() local
818 if( pCache->bPurgeable ){ in pcache1Cachesize()
819 PGroup *pGroup = pCache->pGroup; in pcache1Cachesize()
822 if( n > 0x7fff0000 - pGroup->nMaxPage + pCache->nMax ){ in pcache1Cachesize()
823 n = 0x7fff0000 - pGroup->nMaxPage + pCache->nMax; in pcache1Cachesize()
825 pGroup->nMaxPage += (n - pCache->nMax); in pcache1Cachesize()
827 pCache->nMax = n; in pcache1Cachesize()
828 pCache->n90pct = pCache->nMax*9/10; in pcache1Cachesize()
829 pcache1EnforceMaxPage(pCache); in pcache1Cachesize()
840 PCache1 *pCache = (PCache1*)p; in pcache1Shrink() local
841 if( pCache->bPurgeable ){ in pcache1Shrink()
842 PGroup *pGroup = pCache->pGroup; in pcache1Shrink()
847 pcache1EnforceMaxPage(pCache); in pcache1Shrink()
858 PCache1 *pCache = (PCache1*)p; in pcache1Pagecount() local
859 pcache1EnterMutex(pCache->pGroup); in pcache1Pagecount()
860 n = pCache->nPage; in pcache1Pagecount()
861 pcache1LeaveMutex(pCache->pGroup); in pcache1Pagecount()
875 PCache1 *pCache, in pcache1FetchStage2() argument
880 PGroup *pGroup = pCache->pGroup; in pcache1FetchStage2()
884 assert( pCache->nPage >= pCache->nRecyclable ); in pcache1FetchStage2()
885 nPinned = pCache->nPage - pCache->nRecyclable; in pcache1FetchStage2()
887 assert( pCache->n90pct == pCache->nMax*9/10 ); in pcache1FetchStage2()
890 || nPinned>=pCache->n90pct in pcache1FetchStage2()
891 || (pcache1UnderMemoryPressure(pCache) && pCache->nRecyclable<nPinned) in pcache1FetchStage2()
896 if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache); in pcache1FetchStage2()
897 assert( pCache->nHash>0 && pCache->apHash ); in pcache1FetchStage2()
900 if( pCache->bPurgeable in pcache1FetchStage2()
902 && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache)) in pcache1FetchStage2()
909 pOther = pPage->pCache; in pcache1FetchStage2()
910 if( pOther->szAlloc != pCache->szAlloc ){ in pcache1FetchStage2()
914 pGroup->nPurgeable -= (pOther->bPurgeable - pCache->bPurgeable); in pcache1FetchStage2()
922 pPage = pcache1AllocPage(pCache, createFlag==1); in pcache1FetchStage2()
926 unsigned int h = iKey % pCache->nHash; in pcache1FetchStage2()
927 pCache->nPage++; in pcache1FetchStage2()
929 pPage->pNext = pCache->apHash[h]; in pcache1FetchStage2()
930 pPage->pCache = pCache; in pcache1FetchStage2()
935 pCache->apHash[h] = pPage; in pcache1FetchStage2()
936 if( iKey>pCache->iMaxKey ){ in pcache1FetchStage2()
937 pCache->iMaxKey = iKey; in pcache1FetchStage2()
1007 PCache1 *pCache = (PCache1 *)p; in pcache1FetchNoMutex() local
1011 pPage = pCache->apHash[iKey % pCache->nHash]; in pcache1FetchNoMutex()
1026 return pcache1FetchStage2(pCache, iKey, createFlag); in pcache1FetchNoMutex()
1037 PCache1 *pCache = (PCache1 *)p; in pcache1FetchWithMutex() local
1040 pcache1EnterMutex(pCache->pGroup); in pcache1FetchWithMutex()
1042 assert( pPage==0 || pCache->iMaxKey>=iKey ); in pcache1FetchWithMutex()
1043 pcache1LeaveMutex(pCache->pGroup); in pcache1FetchWithMutex()
1053 PCache1 *pCache = (PCache1 *)p; in pcache1Fetch() local
1057 assert( pCache->bPurgeable || createFlag!=1 ); in pcache1Fetch()
1058 assert( pCache->bPurgeable || pCache->nMin==0 ); in pcache1Fetch()
1059 assert( pCache->bPurgeable==0 || pCache->nMin==10 ); in pcache1Fetch()
1060 assert( pCache->nMin==0 || pCache->bPurgeable ); in pcache1Fetch()
1061 assert( pCache->nHash>0 ); in pcache1Fetch()
1063 if( pCache->pGroup->mutex ){ in pcache1Fetch()
1083 PCache1 *pCache = (PCache1 *)p; in pcache1Unpin() local
1085 PGroup *pGroup = pCache->pGroup; in pcache1Unpin()
1087 assert( pPage->pCache==pCache ); in pcache1Unpin()
1104 pCache->nRecyclable++; in pcache1Unpin()
1107 pcache1LeaveMutex(pCache->pGroup); in pcache1Unpin()
1119 PCache1 *pCache = (PCache1 *)p; in pcache1Rekey() local
1124 assert( pPage->pCache==pCache ); in pcache1Rekey()
1127 pcache1EnterMutex(pCache->pGroup); in pcache1Rekey()
1130 hOld = iOld%pCache->nHash; in pcache1Rekey()
1131 pp = &pCache->apHash[hOld]; in pcache1Rekey()
1138 hNew = iNew%pCache->nHash; in pcache1Rekey()
1140 pPage->pNext = pCache->apHash[hNew]; in pcache1Rekey()
1141 pCache->apHash[hNew] = pPage; in pcache1Rekey()
1142 if( iNew>pCache->iMaxKey ){ in pcache1Rekey()
1143 pCache->iMaxKey = iNew; in pcache1Rekey()
1146 pcache1LeaveMutex(pCache->pGroup); in pcache1Rekey()
1157 PCache1 *pCache = (PCache1 *)p; in pcache1Truncate() local
1158 pcache1EnterMutex(pCache->pGroup); in pcache1Truncate()
1159 if( iLimit<=pCache->iMaxKey ){ in pcache1Truncate()
1160 pcache1TruncateUnsafe(pCache, iLimit); in pcache1Truncate()
1161 pCache->iMaxKey = iLimit-1; in pcache1Truncate()
1163 pcache1LeaveMutex(pCache->pGroup); in pcache1Truncate()
1172 PCache1 *pCache = (PCache1 *)p; in pcache1Destroy() local
1173 PGroup *pGroup = pCache->pGroup; in pcache1Destroy()
1174 assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) ); in pcache1Destroy()
1176 if( pCache->nPage ) pcache1TruncateUnsafe(pCache, 0); in pcache1Destroy()
1177 assert( pGroup->nMaxPage >= pCache->nMax ); in pcache1Destroy()
1178 pGroup->nMaxPage -= pCache->nMax; in pcache1Destroy()
1179 assert( pGroup->nMinPage >= pCache->nMin ); in pcache1Destroy()
1180 pGroup->nMinPage -= pCache->nMin; in pcache1Destroy()
1182 pcache1EnforceMaxPage(pCache); in pcache1Destroy()
1184 sqlite3_free(pCache->pBulk); in pcache1Destroy()
1185 sqlite3_free(pCache->apHash); in pcache1Destroy()
1186 sqlite3_free(pCache); in pcache1Destroy()