Lines Matching defs:pCache

17134   PCache *pCache;                /* PRIVATE: Cache that owns this page */
17144 ** Elements above, except pCache, are public. All that follow are
17146 ** pCache is grouped with the public elements for efficiency.
17244 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
17292 SQLITE_PRIVATE int sqlite3PCacheIsDirty(PCache *pCache);
23194 Bool colCache:1; /* pCache pointer is initialized and non-NULL */
23235 VdbeTxtBlbCache *pCache; /* Cache of large TEXT or BLOB values */
23257 ** VdbeCursor using the pCache field.
54271 sqlite3_pcache *pCache; /* Pluggable cache module */
54301 static void pcacheDump(PCache *pCache){
54307 if( pCache->pCache==0 ) return;
54308 N = sqlite3PcachePagecount(pCache);
54311 pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
54314 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
54325 ** Return 1 if pPg is on the dirty list for pCache. Return 0 if not.
54329 static int pageOnDirtyList(PCache *pCache, PgHdr *pPg){
54331 for(p=pCache->pDirty; p; p=p->pDirtyNext){
54336 static int pageNotOnDirtyList(PCache *pCache, PgHdr *pPg){
54338 for(p=pCache->pDirty; p; p=p->pDirtyNext){
54359 PCache *pCache;
54362 pCache = pPg->pCache;
54363 assert( pCache!=0 ); /* Every page has an associated PCache */
54366 assert( pageNotOnDirtyList(pCache, pPg) );/* CLEAN pages not on dirtylist */
54371 assert( pPg->pDirtyPrev!=0 || pCache->pDirty==pPg );
54372 assert( pageOnDirtyList(pCache, pPg) );
54414 PCache *p = pPage->pCache;
54484 if( p->pCache->bPurgeable ){
54485 pcacheTrace(("%p.UNPIN %d\n", p->pCache, p->pgno));
54486 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
54487 pcacheDump(p->pCache);
54577 SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
54578 assert( pCache->nRefSum==0 && pCache->pDirty==0 );
54579 if( pCache->szPage ){
54582 szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
54583 pCache->bPurgeable
54586 sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache));
54587 if( pCache->pCache ){
54588 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
54590 pCache->pCache = pNew;
54591 pCache->szPage = szPage;
54592 pcacheTrace(("%p.PAGESIZE %d\n",pCache,szPage));
54622 PCache *pCache, /* Obtain the page from this cache */
54629 assert( pCache!=0 );
54630 assert( pCache->pCache!=0 );
54632 assert( pCache->eCreate==((pCache->bPurgeable && pCache->pDirty) ? 1 : 2) );
54641 eCreate = createFlag & pCache->eCreate;
54643 assert( createFlag==0 || pCache->eCreate==eCreate );
54644 assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
54645 pRes = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
54646 pcacheTrace(("%p.FETCH %d%s (result: %p) ",pCache,pgno,
54664 PCache *pCache, /* Obtain the page from this cache */
54669 if( pCache->eCreate==2 ) return 0;
54671 if( sqlite3PcachePagecount(pCache)>pCache->szSpill ){
54681 for(pPg=pCache->pSynced;
54685 pCache->pSynced = pPg;
54687 for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
54695 sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache),
54696 numberOfCachePages(pCache));
54698 pcacheTrace(("%p.SPILL %d\n",pCache,pPg->pgno));
54699 rc = pCache->xStress(pCache->pStress, pPg);
54700 pcacheDump(pCache);
54706 *ppPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, 2);
54720 PCache *pCache, /* Obtain the page from this cache */
54733 pPgHdr->pCache = pCache;
54736 return sqlite3PcacheFetchFinish(pCache,pgno,pPage);
54746 PCache *pCache, /* Obtain the page from this cache */
54756 return pcacheFetchFinishWithInit(pCache, pgno, pPage);
54758 pCache->nRefSum++;
54770 p->pCache->nRefSum--;
54788 p->pCache->nRefSum++;
54802 p->pCache->nRefSum--;
54803 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
54817 pcacheTrace(("%p.DIRTY %d\n",p->pCache,p->pgno));
54837 pcacheTrace(("%p.CLEAN %d\n",p->pCache,p->pgno));
54847 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
54849 pcacheTrace(("%p.CLEAN-ALL\n",pCache));
54850 while( (p = pCache->pDirty)!=0 ){
54858 SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache *pCache){
54860 pcacheTrace(("%p.CLEAR-WRITEABLE\n",pCache));
54861 for(p=pCache->pDirty; p; p=p->pDirtyNext){
54864 pCache->pSynced = pCache->pDirtyTail;
54870 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){
54872 for(p=pCache->pDirty; p; p=p->pDirtyNext){
54875 pCache->pSynced = pCache->pDirtyTail;
54882 PCache *pCache = p->pCache;
54887 pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno));
54888 pOther = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, newPgno, 0);
54893 pCache->nRefSum++;
54896 sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
54913 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
54914 if( pCache->pCache ){
54917 pcacheTrace(("%p.TRUNCATE %d\n",pCache,pgno));
54918 for(p=pCache->pDirty; p; p=pNext){
54930 if( pgno==0 && pCache->nRefSum ){
54932 pPage1 = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache,1,0);
54934 ** pCache->nRefSum>0 */
54935 memset(pPage1->pBuf, 0, pCache->szPage);
54939 sqlite3GlobalConfig.pcache2.xTruncate(pCache->pCache, pgno+1);
54946 SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
54947 assert( pCache->pCache!=0 );
54948 pcacheTrace(("%p.CLOSE\n",pCache));
54949 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
54955 SQLITE_PRIVATE void sqlite3PcacheClear(PCache *pCache){
54956 sqlite3PcacheTruncate(pCache, 0);
55035 SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
55037 for(p=pCache->pDirty; p; p=p->pDirtyNext){
55040 return pcacheSortDirtyList(pCache->pDirty);
55049 SQLITE_PRIVATE i64 sqlite3PcacheRefCount(PCache *pCache){
55050 return pCache->nRefSum;
55063 SQLITE_PRIVATE int sqlite3PcachePagecount(PCache *pCache){
55064 assert( pCache->pCache!=0 );
55065 return sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache);
55072 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *pCache){
55073 return numberOfCachePages(pCache);
55080 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){
55081 assert( pCache->pCache!=0 );
55082 pCache->szCache = mxPage;
55083 sqlite3GlobalConfig.pcache2.xCachesize(pCache->pCache,
55084 numberOfCachePages(pCache));
55094 assert( p->pCache!=0 );
55109 SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){
55110 assert( pCache->pCache!=0 );
55111 sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache);
55124 SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache *pCache){
55127 int nCache = numberOfCachePages(pCache);
55128 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext) nDirty++;
55136 SQLITE_PRIVATE int sqlite3PCacheIsDirty(PCache *pCache){
55137 return (pCache->pDirty!=0);
55147 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *)){
55149 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext){
55249 ** structure. A buffer of PgHdr1.pCache->szPage bytes is allocated
55279 PCache1 *pCache; /* Cache that currently owns this page */
55454 ** Try to initialize the pCache->pFree and pCache->pBulk fields. Return
55455 ** true if pCache->pFree ends up containing one or more free pages.
55457 static int pcache1InitBulk(PCache1 *pCache){
55462 if( pCache->nMax<3 ) return 0;
55465 szBulk = pCache->szAlloc * (i64)pcache1.nInitPage;
55469 if( szBulk > pCache->szAlloc*(i64)pCache->nMax ){
55470 szBulk = pCache->szAlloc*(i64)pCache->nMax;
55472 zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
55475 int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
55477 PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
55482 pX->pNext = pCache->pFree;
55484 pCache->pFree = pX;
55485 zBulk += pCache->szAlloc;
55488 return pCache->pFree!=0;
55586 ** Allocate a new page object initially associated with cache pCache.
55588 static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc){
55592 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
55593 if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){
55594 assert( pCache->pFree!=0 );
55595 p = pCache->pFree;
55596 pCache->pFree = p->pNext;
55604 assert( pCache->pGroup==&pcache1.grp );
55605 pcache1LeaveMutex(pCache->pGroup);
55608 pPg = pcache1Alloc(pCache->szAlloc);
55611 pcache1EnterMutex(pCache->pGroup);
55614 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
55621 (*pCache->pnPurgeable)++;
55629 PCache1 *pCache;
55631 pCache = p->pCache;
55632 assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
55634 p->pNext = pCache->pFree;
55635 pCache->pFree = p;
55639 (*pCache->pnPurgeable)--;
55676 static int pcache1UnderMemoryPressure(PCache1 *pCache){
55677 if( pcache1.nSlot && (pCache->szPage+pCache->szExtra)<=pcache1.szSlot ){
55739 assert( sqlite3_mutex_held(pPage->pCache->pGroup->mutex) );
55746 assert( pPage->pCache->pGroup->lru.isAnchor==1 );
55747 pPage->pCache->nRecyclable--;
55761 PCache1 *pCache = pPage->pCache;
55764 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
55765 h = pPage->iKey % pCache->nHash;
55766 for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
55769 pCache->nPage--;
55777 static void pcache1EnforceMaxPage(PCache1 *pCache){
55778 PGroup *pGroup = pCache->pGroup;
55784 assert( p->pCache->pGroup==pGroup );
55789 if( pCache->nPage==0 && pCache->pBulk ){
55790 sqlite3_free(pCache->pBulk);
55791 pCache->pBulk = pCache->pFree = 0;
55796 ** Discard all pages from cache pCache with a page number (key value)
55803 PCache1 *pCache, /* The cache to truncate */
55806 TESTONLY( int nPage = 0; ) /* To assert pCache->nPage is correct */
55808 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
55809 assert( pCache->iMaxKey >= iLimit );
55810 assert( pCache->nHash > 0 );
55811 if( pCache->iMaxKey - iLimit < pCache->nHash ){
55816 h = iLimit % pCache->nHash;
55817 iStop = pCache->iMaxKey % pCache->nHash;
55818 TESTONLY( nPage = -10; ) /* Disable the pCache->nPage validity check */
55822 h = pCache->nHash/2;
55828 assert( h<pCache->nHash );
55829 pp = &pCache->apHash[h];
55832 pCache->nPage--;
55842 h = (h+1) % pCache->nHash;
55844 assert( nPage<0 || pCache->nPage==(unsigned)nPage );
55921 PCache1 *pCache; /* The newly created page cache */
55929 pCache = (PCache1 *)sqlite3MallocZero(sz);
55930 if( pCache ){
55932 pGroup = (PGroup*)&pCache[1];
55942 pCache->pGroup = pGroup;
55943 pCache->szPage = szPage;
55944 pCache->szExtra = szExtra;
55945 pCache->szAlloc = szPage + szExtra + ROUND8(sizeof(PgHdr1));
55946 pCache->bPurgeable = (bPurgeable ? 1 : 0);
55947 pcache1ResizeHash(pCache);
55949 pCache->nMin = 10;
55950 pGroup->nMinPage += pCache->nMin;
55952 pCache->pnPurgeable = &pGroup->nPurgeable;
55954 pCache->pnPurgeable = &pCache->nPurgeableDummy;
55957 if( pCache->nHash==0 ){
55958 pcache1Destroy((sqlite3_pcache*)pCache);
55959 pCache = 0;
55962 return (sqlite3_pcache *)pCache;
55971 PCache1 *pCache = (PCache1 *)p;
55974 if( pCache->bPurgeable ){
55975 PGroup *pGroup = pCache->pGroup;
55978 if( n > 0x7fff0000 - pGroup->nMaxPage + pCache->nMax ){
55979 n = 0x7fff0000 - pGroup->nMaxPage + pCache->nMax;
55981 pGroup->nMaxPage += (n - pCache->nMax);
55983 pCache->nMax = n;
55984 pCache->n90pct = pCache->nMax*9/10;
55985 pcache1EnforceMaxPage(pCache);
55996 PCache1 *pCache = (PCache1*)p;
55997 if( pCache->bPurgeable ){
55998 PGroup *pGroup = pCache->pGroup;
56003 pcache1EnforceMaxPage(pCache);
56014 PCache1 *pCache = (PCache1*)p;
56015 pcache1EnterMutex(pCache->pGroup);
56016 n = pCache->nPage;
56017 pcache1LeaveMutex(pCache->pGroup);
56031 PCache1 *pCache,
56036 PGroup *pGroup = pCache->pGroup;
56040 assert( pCache->nPage >= pCache->nRecyclable );
56041 nPinned = pCache->nPage - pCache->nRecyclable;
56043 assert( pCache->n90pct == pCache->nMax*9/10 );
56046 || nPinned>=pCache->n90pct
56047 || (pcache1UnderMemoryPressure(pCache) && pCache->nRecyclable<nPinned)
56052 if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
56053 assert( pCache->nHash>0 && pCache->apHash );
56056 if( pCache->bPurgeable
56058 && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
56065 pOther = pPage->pCache;
56066 if( pOther->szAlloc != pCache->szAlloc ){
56070 pGroup->nPurgeable -= (pOther->bPurgeable - pCache->bPurgeable);
56078 pPage = pcache1AllocPage(pCache, createFlag==1);
56082 unsigned int h = iKey % pCache->nHash;
56083 pCache->nPage++;
56085 pPage->pNext = pCache->apHash[h];
56086 pPage->pCache = pCache;
56091 pCache->apHash[h] = pPage;
56092 if( iKey>pCache->iMaxKey ){
56093 pCache->iMaxKey = iKey;
56163 PCache1 *pCache = (PCache1 *)p;
56167 pPage = pCache->apHash[iKey % pCache->nHash];
56182 return pcache1FetchStage2(pCache, iKey, createFlag);
56193 PCache1 *pCache = (PCache1 *)p;
56196 pcache1EnterMutex(pCache->pGroup);
56198 assert( pPage==0 || pCache->iMaxKey>=iKey );
56199 pcache1LeaveMutex(pCache->pGroup);
56209 PCache1 *pCache = (PCache1 *)p;
56213 assert( pCache->bPurgeable || createFlag!=1 );
56214 assert( pCache->bPurgeable || pCache->nMin==0 );
56215 assert( pCache->bPurgeable==0 || pCache->nMin==10 );
56216 assert( pCache->nMin==0 || pCache->bPurgeable );
56217 assert( pCache->nHash>0 );
56219 if( pCache->pGroup->mutex ){
56239 PCache1 *pCache = (PCache1 *)p;
56241 PGroup *pGroup = pCache->pGroup;
56243 assert( pPage->pCache==pCache );
56260 pCache->nRecyclable++;
56263 pcache1LeaveMutex(pCache->pGroup);
56275 PCache1 *pCache = (PCache1 *)p;
56280 assert( pPage->pCache==pCache );
56283 pcache1EnterMutex(pCache->pGroup);
56286 hOld = iOld%pCache->nHash;
56287 pp = &pCache->apHash[hOld];
56294 hNew = iNew%pCache->nHash;
56296 pPage->pNext = pCache->apHash[hNew];
56297 pCache->apHash[hNew] = pPage;
56298 if( iNew>pCache->iMaxKey ){
56299 pCache->iMaxKey = iNew;
56302 pcache1LeaveMutex(pCache->pGroup);
56313 PCache1 *pCache = (PCache1 *)p;
56314 pcache1EnterMutex(pCache->pGroup);
56315 if( iLimit<=pCache->iMaxKey ){
56316 pcache1TruncateUnsafe(pCache, iLimit);
56317 pCache->iMaxKey = iLimit-1;
56319 pcache1LeaveMutex(pCache->pGroup);
56328 PCache1 *pCache = (PCache1 *)p;
56329 PGroup *pGroup = pCache->pGroup;
56330 assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) );
56332 if( pCache->nPage ) pcache1TruncateUnsafe(pCache, 0);
56333 assert( pGroup->nMaxPage >= pCache->nMax );
56334 pGroup->nMaxPage -= pCache->nMax;
56335 assert( pGroup->nMinPage >= pCache->nMin );
56336 pGroup->nMinPage -= pCache->nMin;
56338 pcache1EnforceMaxPage(pCache);
56340 sqlite3_free(pCache->pBulk);
56341 sqlite3_free(pCache->apHash);
56342 sqlite3_free(pCache);
87564 VdbeTxtBlbCache *pCache = pCx->pCache;
87567 pCx->pCache = 0;
87568 if( pCache->pCValue ){
87569 sqlite3RCStrUnref(pCache->pCValue);
87570 pCache->pCValue = 0;
87572 sqlite3DbFree(p->db, pCache);
93846 VdbeTxtBlbCache *pCache;
93849 pC->pCache = sqlite3DbMallocZero(db, sizeof(VdbeTxtBlbCache) );
93850 if( pC->pCache==0 ) return SQLITE_NOMEM;
93853 pCache = pC->pCache;
93854 if( pCache->pCValue==0
93855 || pCache->iCol!=iCol
93856 || pCache->cacheStatus!=cacheStatus
93857 || pCache->colCacheCtr!=colCacheCtr
93858 || pCache->iOffset!=sqlite3BtreeOffset(pC->uc.pCursor)
93860 if( pCache->pCValue ) sqlite3RCStrUnref(pCache->pCValue);
93861 pBuf = pCache->pCValue = sqlite3RCStrNew( len+3 );
93868 pCache->iCol = iCol;
93869 pCache->cacheStatus = cacheStatus;
93870 pCache->colCacheCtr = colCacheCtr;
93871 pCache->iOffset = sqlite3BtreeOffset(pC->uc.pCursor);
93873 pBuf = pCache->pCValue;