Lines Matching refs:pCache

17567   PCache *pCache;                /* PRIVATE: Cache that owns this page */  member
17677 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
17725 SQLITE_PRIVATE int sqlite3PCacheIsDirty(PCache *pCache);
23715 VdbeTxtBlbCache *pCache; /* Cache of large TEXT or BLOB values */ member
55222 sqlite3_pcache *pCache; /* Pluggable cache module */ member
55252 static void pcacheDump(PCache *pCache){
55258 if( pCache->pCache==0 ) return;
55259 N = sqlite3PcachePagecount(pCache);
55262 pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
55265 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
55280 static int pageOnDirtyList(PCache *pCache, PgHdr *pPg){
55282 for(p=pCache->pDirty; p; p=p->pDirtyNext){
55287 static int pageNotOnDirtyList(PCache *pCache, PgHdr *pPg){
55289 for(p=pCache->pDirty; p; p=p->pDirtyNext){
55310 PCache *pCache; local
55313 pCache = pPg->pCache;
55314 assert( pCache!=0 ); /* Every page has an associated PCache */
55317 assert( pageNotOnDirtyList(pCache, pPg) );/* CLEAN pages not on dirtylist */
55322 assert( pPg->pDirtyPrev!=0 || pCache->pDirty==pPg );
55323 assert( pageOnDirtyList(pCache, pPg) );
55365 PCache *p = pPage->pCache;
55435 if( p->pCache->bPurgeable ){
55436 pcacheTrace(("%p.UNPIN %d\n", p->pCache, p->pgno));
55437 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
55438 pcacheDump(p->pCache);
55528 SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
55529 assert( pCache->nRefSum==0 && pCache->pDirty==0 );
55530 if( pCache->szPage ){
55533 szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
55534 pCache->bPurgeable
55537 sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache));
55538 if( pCache->pCache ){
55539 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
55541 pCache->pCache = pNew;
55542 pCache->szPage = szPage;
55543 pcacheTrace(("%p.PAGESIZE %d\n",pCache,szPage));
55573 PCache *pCache, /* Obtain the page from this cache */
55580 assert( pCache!=0 );
55581 assert( pCache->pCache!=0 );
55583 assert( pCache->eCreate==((pCache->bPurgeable && pCache->pDirty) ? 1 : 2) );
55592 eCreate = createFlag & pCache->eCreate;
55594 assert( createFlag==0 || pCache->eCreate==eCreate );
55595 assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
55596 pRes = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
55597 pcacheTrace(("%p.FETCH %d%s (result: %p) ",pCache,pgno,
55615 PCache *pCache, /* Obtain the page from this cache */
55620 if( pCache->eCreate==2 ) return 0;
55622 if( sqlite3PcachePagecount(pCache)>pCache->szSpill ){
55632 for(pPg=pCache->pSynced;
55636 pCache->pSynced = pPg;
55638 for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
55646 sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache),
55647 numberOfCachePages(pCache));
55649 pcacheTrace(("%p.SPILL %d\n",pCache,pPg->pgno));
55650 rc = pCache->xStress(pCache->pStress, pPg);
55651 pcacheDump(pCache);
55657 *ppPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, 2);
55671 PCache *pCache, /* Obtain the page from this cache */
55685 pPgHdr->pCache = pCache;
55688 return sqlite3PcacheFetchFinish(pCache,pgno,pPage);
55698 PCache *pCache, /* Obtain the page from this cache */
55708 return pcacheFetchFinishWithInit(pCache, pgno, pPage);
55710 pCache->nRefSum++;
55722 p->pCache->nRefSum--;
55740 p->pCache->nRefSum++;
55754 p->pCache->nRefSum--;
55755 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
55769 pcacheTrace(("%p.DIRTY %d\n",p->pCache,p->pgno));
55789 pcacheTrace(("%p.CLEAN %d\n",p->pCache,p->pgno));
55799 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
55801 pcacheTrace(("%p.CLEAN-ALL\n",pCache));
55802 while( (p = pCache->pDirty)!=0 ){
55810 SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache *pCache){
55812 pcacheTrace(("%p.CLEAR-WRITEABLE\n",pCache));
55813 for(p=pCache->pDirty; p; p=p->pDirtyNext){
55816 pCache->pSynced = pCache->pDirtyTail;
55822 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){
55824 for(p=pCache->pDirty; p; p=p->pDirtyNext){
55827 pCache->pSynced = pCache->pDirtyTail;
55834 PCache *pCache = p->pCache; local
55839 pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno));
55840 pOther = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, newPgno, 0);
55845 pCache->nRefSum++;
55848 sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
55865 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
55866 if( pCache->pCache ){
55869 pcacheTrace(("%p.TRUNCATE %d\n",pCache,pgno));
55870 for(p=pCache->pDirty; p; p=pNext){
55882 if( pgno==0 && pCache->nRefSum ){
55884 pPage1 = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache,1,0);
55887 memset(pPage1->pBuf, 0, pCache->szPage);
55891 sqlite3GlobalConfig.pcache2.xTruncate(pCache->pCache, pgno+1);
55898 SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
55899 assert( pCache->pCache!=0 );
55900 pcacheTrace(("%p.CLOSE\n",pCache));
55901 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
55907 SQLITE_PRIVATE void sqlite3PcacheClear(PCache *pCache){
55908 sqlite3PcacheTruncate(pCache, 0);
55987 SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
55989 for(p=pCache->pDirty; p; p=p->pDirtyNext){
55992 return pcacheSortDirtyList(pCache->pDirty);
56001 SQLITE_PRIVATE i64 sqlite3PcacheRefCount(PCache *pCache){
56002 return pCache->nRefSum;
56015 SQLITE_PRIVATE int sqlite3PcachePagecount(PCache *pCache){
56016 assert( pCache->pCache!=0 );
56017 return sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache);
56024 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *pCache){
56025 return numberOfCachePages(pCache);
56032 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){
56033 assert( pCache->pCache!=0 );
56034 pCache->szCache = mxPage;
56035 sqlite3GlobalConfig.pcache2.xCachesize(pCache->pCache,
56036 numberOfCachePages(pCache));
56046 assert( p->pCache!=0 );
56061 SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){
56062 assert( pCache->pCache!=0 );
56063 sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache);
56076 SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache *pCache){
56079 int nCache = numberOfCachePages(pCache);
56080 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext) nDirty++;
56088 SQLITE_PRIVATE int sqlite3PCacheIsDirty(PCache *pCache){
56089 return (pCache->pDirty!=0);
56099 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *)){
56101 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext){
56231 PCache1 *pCache; /* Cache that currently owns this page */ member
56405 static int pcache1InitBulk(PCache1 *pCache){
56410 if( pCache->nMax<3 ) return 0;
56413 szBulk = pCache->szAlloc * (i64)pcache1.nInitPage;
56417 if( szBulk > pCache->szAlloc*(i64)pCache->nMax ){
56418 szBulk = pCache->szAlloc*(i64)pCache->nMax;
56420 zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
56423 int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
56425 PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
56431 pX->pNext = pCache->pFree;
56433 pCache->pFree = pX;
56434 zBulk += pCache->szAlloc;
56437 return pCache->pFree!=0;
56537 static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc){
56541 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
56542 if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){
56543 assert( pCache->pFree!=0 );
56544 p = pCache->pFree;
56545 pCache->pFree = p->pNext;
56553 assert( pCache->pGroup==&pcache1.grp );
56554 pcache1LeaveMutex(pCache->pGroup);
56557 pPg = pcache1Alloc(pCache->szAlloc);
56560 pcache1EnterMutex(pCache->pGroup);
56563 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
56571 (*pCache->pnPurgeable)++;
56579 PCache1 *pCache; local
56581 pCache = p->pCache;
56582 assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
56584 p->pNext = pCache->pFree;
56585 pCache->pFree = p;
56589 (*pCache->pnPurgeable)--;
56626 static int pcache1UnderMemoryPressure(PCache1 *pCache){
56627 if( pcache1.nSlot && (pCache->szPage+pCache->szExtra)<=pcache1.szSlot ){
56689 assert( sqlite3_mutex_held(pPage->pCache->pGroup->mutex) );
56696 assert( pPage->pCache->pGroup->lru.isAnchor==1 );
56697 pPage->pCache->nRecyclable--;
56711 PCache1 *pCache = pPage->pCache; local
56714 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
56715 h = pPage->iKey % pCache->nHash;
56716 for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
56719 pCache->nPage--;
56727 static void pcache1EnforceMaxPage(PCache1 *pCache){
56728 PGroup *pGroup = pCache->pGroup;
56734 assert( p->pCache->pGroup==pGroup );
56739 if( pCache->nPage==0 && pCache->pBulk ){
56740 sqlite3_free(pCache->pBulk);
56741 pCache->pBulk = pCache->pFree = 0;
56753 PCache1 *pCache, /* The cache to truncate */
56758 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
56759 assert( pCache->iMaxKey >= iLimit );
56760 assert( pCache->nHash > 0 );
56761 if( pCache->iMaxKey - iLimit < pCache->nHash ){
56766 h = iLimit % pCache->nHash;
56767 iStop = pCache->iMaxKey % pCache->nHash;
56772 h = pCache->nHash/2;
56778 assert( h<pCache->nHash );
56779 pp = &pCache->apHash[h];
56782 pCache->nPage--;
56792 h = (h+1) % pCache->nHash;
56794 assert( nPage<0 || pCache->nPage==(unsigned)nPage );
56871 PCache1 *pCache; /* The newly created page cache */ local
56879 pCache = (PCache1 *)sqlite3MallocZero(sz);
56880 if( pCache ){
56882 pGroup = (PGroup*)&pCache[1];
56892 pCache->pGroup = pGroup;
56893 pCache->szPage = szPage;
56894 pCache->szExtra = szExtra;
56895 pCache->szAlloc = szPage + szExtra + ROUND8(sizeof(PgHdr1));
56896 pCache->bPurgeable = (bPurgeable ? 1 : 0);
56897 pcache1ResizeHash(pCache);
56899 pCache->nMin = 10;
56900 pGroup->nMinPage += pCache->nMin;
56902 pCache->pnPurgeable = &pGroup->nPurgeable;
56904 pCache->pnPurgeable = &pCache->nPurgeableDummy;
56907 if( pCache->nHash==0 ){
56908 pcache1Destroy((sqlite3_pcache*)pCache);
56909 pCache = 0;
56912 return (sqlite3_pcache *)pCache;
56921 PCache1 *pCache = (PCache1 *)p; local
56924 if( pCache->bPurgeable ){
56925 PGroup *pGroup = pCache->pGroup;
56928 if( n > 0x7fff0000 - pGroup->nMaxPage + pCache->nMax ){
56929 n = 0x7fff0000 - pGroup->nMaxPage + pCache->nMax;
56931 pGroup->nMaxPage += (n - pCache->nMax);
56933 pCache->nMax = n;
56934 pCache->n90pct = pCache->nMax*9/10;
56935 pcache1EnforceMaxPage(pCache);
56946 PCache1 *pCache = (PCache1*)p; local
56947 if( pCache->bPurgeable ){
56948 PGroup *pGroup = pCache->pGroup;
56953 pcache1EnforceMaxPage(pCache);
56964 PCache1 *pCache = (PCache1*)p; local
56965 pcache1EnterMutex(pCache->pGroup);
56966 n = pCache->nPage;
56967 pcache1LeaveMutex(pCache->pGroup);
56981 PCache1 *pCache,
56986 PGroup *pGroup = pCache->pGroup;
56990 assert( pCache->nPage >= pCache->nRecyclable );
56991 nPinned = pCache->nPage - pCache->nRecyclable;
56993 assert( pCache->n90pct == pCache->nMax*9/10 );
56996 || nPinned>=pCache->n90pct
56997 || (pcache1UnderMemoryPressure(pCache) && pCache->nRecyclable<nPinned)
57002 if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
57003 assert( pCache->nHash>0 && pCache->apHash );
57006 if( pCache->bPurgeable
57008 && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
57015 pOther = pPage->pCache;
57016 if( pOther->szAlloc != pCache->szAlloc ){
57020 pGroup->nPurgeable -= (pOther->bPurgeable - pCache->bPurgeable);
57028 pPage = pcache1AllocPage(pCache, createFlag==1);
57032 unsigned int h = iKey % pCache->nHash;
57033 pCache->nPage++;
57035 pPage->pNext = pCache->apHash[h];
57036 pPage->pCache = pCache;
57041 pCache->apHash[h] = pPage;
57042 if( iKey>pCache->iMaxKey ){
57043 pCache->iMaxKey = iKey;
57113 PCache1 *pCache = (PCache1 *)p; local
57117 pPage = pCache->apHash[iKey % pCache->nHash];
57132 return pcache1FetchStage2(pCache, iKey, createFlag);
57143 PCache1 *pCache = (PCache1 *)p; local
57146 pcache1EnterMutex(pCache->pGroup);
57148 assert( pPage==0 || pCache->iMaxKey>=iKey );
57149 pcache1LeaveMutex(pCache->pGroup);
57159 PCache1 *pCache = (PCache1 *)p; local
57163 assert( pCache->bPurgeable || createFlag!=1 );
57164 assert( pCache->bPurgeable || pCache->nMin==0 );
57165 assert( pCache->bPurgeable==0 || pCache->nMin==10 );
57166 assert( pCache->nMin==0 || pCache->bPurgeable );
57167 assert( pCache->nHash>0 );
57169 if( pCache->pGroup->mutex ){
57189 PCache1 *pCache = (PCache1 *)p; local
57191 PGroup *pGroup = pCache->pGroup;
57193 assert( pPage->pCache==pCache );
57210 pCache->nRecyclable++;
57213 pcache1LeaveMutex(pCache->pGroup);
57225 PCache1 *pCache = (PCache1 *)p; local
57230 assert( pPage->pCache==pCache );
57233 pcache1EnterMutex(pCache->pGroup);
57236 hOld = iOld%pCache->nHash;
57237 pp = &pCache->apHash[hOld];
57244 hNew = iNew%pCache->nHash;
57246 pPage->pNext = pCache->apHash[hNew];
57247 pCache->apHash[hNew] = pPage;
57248 if( iNew>pCache->iMaxKey ){
57249 pCache->iMaxKey = iNew;
57252 pcache1LeaveMutex(pCache->pGroup);
57263 PCache1 *pCache = (PCache1 *)p; local
57264 pcache1EnterMutex(pCache->pGroup);
57265 if( iLimit<=pCache->iMaxKey ){
57266 pcache1TruncateUnsafe(pCache, iLimit);
57267 pCache->iMaxKey = iLimit-1;
57269 pcache1LeaveMutex(pCache->pGroup);
57278 PCache1 *pCache = (PCache1 *)p; local
57279 PGroup *pGroup = pCache->pGroup;
57280 assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) );
57282 if( pCache->nPage ) pcache1TruncateUnsafe(pCache, 0);
57283 assert( pGroup->nMaxPage >= pCache->nMax );
57284 pGroup->nMaxPage -= pCache->nMax;
57285 assert( pGroup->nMinPage >= pCache->nMin );
57286 pGroup->nMinPage -= pCache->nMin;
57288 pcache1EnforceMaxPage(pCache);
57290 sqlite3_free(pCache->pBulk);
57291 sqlite3_free(pCache->apHash);
57292 sqlite3_free(pCache);
88645 VdbeTxtBlbCache *pCache = pCx->pCache; local
88648 pCx->pCache = 0;
88649 if( pCache->pCValue ){
88650 sqlite3RCStrUnref(pCache->pCValue);
88651 pCache->pCValue = 0;
88653 sqlite3DbFree(p->db, pCache);
95083 VdbeTxtBlbCache *pCache;
95086 pC->pCache = sqlite3DbMallocZero(db, sizeof(VdbeTxtBlbCache) );
95087 if( pC->pCache==0 ) return SQLITE_NOMEM;
95090 pCache = pC->pCache;
95091 if( pCache->pCValue==0
95092 || pCache->iCol!=iCol
95093 || pCache->cacheStatus!=cacheStatus
95094 || pCache->colCacheCtr!=colCacheCtr
95095 || pCache->iOffset!=sqlite3BtreeOffset(pC->uc.pCursor)
95097 if( pCache->pCValue ) sqlite3RCStrUnref(pCache->pCValue);
95098 pBuf = pCache->pCValue = sqlite3RCStrNew( len+3 );
95105 pCache->iCol = iCol;
95106 pCache->cacheStatus = cacheStatus;
95107 pCache->colCacheCtr = colCacheCtr;
95108 pCache->iOffset = sqlite3BtreeOffset(pC->uc.pCursor);
95110 pBuf = pCache->pCValue;