Lines Matching refs:pCache

16508   PCache *pCache;                /* PRIVATE: Cache that owns this page */
16518 ** Elements above, except pCache, are public. All that follow are
16520 ** pCache is grouped with the public elements for efficiency.
16618 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
16666 SQLITE_PRIVATE int sqlite3PCacheIsDirty(PCache *pCache);
52662 sqlite3_pcache *pCache; /* Pluggable cache module */
52688 static void pcacheDump(PCache *pCache){
52694 if( pCache->pCache==0 ) return;
52695 N = sqlite3PcachePagecount(pCache);
52698 pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
52702 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
52713 ** Return 1 if pPg is on the dirty list for pCache. Return 0 if not.
52717 static int pageOnDirtyList(PCache *pCache, PgHdr *pPg){
52719 for(p=pCache->pDirty; p; p=p->pDirtyNext){
52737 PCache *pCache;
52740 pCache = pPg->pCache;
52741 assert( pCache!=0 ); /* Every page has an associated PCache */
52744 assert( !pageOnDirtyList(pCache, pPg) );/* CLEAN pages not on dirty list */
52749 assert( pPg->pDirtyPrev!=0 || pCache->pDirty==pPg );
52750 assert( pageOnDirtyList(pCache, pPg) );
52792 PCache *p = pPage->pCache;
52862 if( p->pCache->bPurgeable ){
52863 pcacheTrace(("%p.UNPIN %d\n", p->pCache, p->pgno));
52864 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
52865 pcacheDump(p->pCache);
52955 SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
52956 assert( pCache->nRefSum==0 && pCache->pDirty==0 );
52957 if( pCache->szPage ){
52960 szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
52961 pCache->bPurgeable
52964 sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache));
52965 if( pCache->pCache ){
52966 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
52968 pCache->pCache = pNew;
52969 pCache->szPage = szPage;
52970 pcacheTrace(("%p.PAGESIZE %d\n",pCache,szPage));
53000 PCache *pCache, /* Obtain the page from this cache */
53007 assert( pCache!=0 );
53008 assert( pCache->pCache!=0 );
53010 assert( pCache->eCreate==((pCache->bPurgeable && pCache->pDirty) ? 1 : 2) );
53019 eCreate = createFlag & pCache->eCreate;
53021 assert( createFlag==0 || pCache->eCreate==eCreate );
53022 assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
53023 pRes = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
53024 pcacheTrace(("%p.FETCH %d%s (result: %p) ",pCache,pgno,
53042 PCache *pCache, /* Obtain the page from this cache */
53047 if( pCache->eCreate==2 ) return 0;
53049 if( sqlite3PcachePagecount(pCache)>pCache->szSpill ){
53059 for(pPg=pCache->pSynced;
53063 pCache->pSynced = pPg;
53065 for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
53073 sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache),
53074 numberOfCachePages(pCache));
53076 pcacheTrace(("%p.SPILL %d\n",pCache,pPg->pgno));
53077 rc = pCache->xStress(pCache->pStress, pPg);
53078 pcacheDump(pCache);
53084 *ppPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, 2);
53098 PCache *pCache, /* Obtain the page from this cache */
53111 pPgHdr->pCache = pCache;
53114 return sqlite3PcacheFetchFinish(pCache,pgno,pPage);
53124 PCache *pCache, /* Obtain the page from this cache */
53134 return pcacheFetchFinishWithInit(pCache, pgno, pPage);
53136 pCache->nRefSum++;
53148 p->pCache->nRefSum--;
53166 p->pCache->nRefSum++;
53180 p->pCache->nRefSum--;
53181 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
53195 pcacheTrace(("%p.DIRTY %d\n",p->pCache,p->pgno));
53215 pcacheTrace(("%p.CLEAN %d\n",p->pCache,p->pgno));
53225 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
53227 pcacheTrace(("%p.CLEAN-ALL\n",pCache));
53228 while( (p = pCache->pDirty)!=0 ){
53236 SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache *pCache){
53238 pcacheTrace(("%p.CLEAR-WRITEABLE\n",pCache));
53239 for(p=pCache->pDirty; p; p=p->pDirtyNext){
53242 pCache->pSynced = pCache->pDirtyTail;
53248 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){
53250 for(p=pCache->pDirty; p; p=p->pDirtyNext){
53253 pCache->pSynced = pCache->pDirtyTail;
53260 PCache *pCache = p->pCache;
53265 pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno));
53266 pOther = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, newPgno, 0);
53271 pCache->nRefSum++;
53274 sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
53291 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
53292 if( pCache->pCache ){
53295 pcacheTrace(("%p.TRUNCATE %d\n",pCache,pgno));
53296 for(p=pCache->pDirty; p; p=pNext){
53308 if( pgno==0 && pCache->nRefSum ){
53310 pPage1 = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache,1,0);
53312 ** pCache->nRefSum>0 */
53313 memset(pPage1->pBuf, 0, pCache->szPage);
53317 sqlite3GlobalConfig.pcache2.xTruncate(pCache->pCache, pgno+1);
53324 SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
53325 assert( pCache->pCache!=0 );
53326 pcacheTrace(("%p.CLOSE\n",pCache));
53327 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
53333 SQLITE_PRIVATE void sqlite3PcacheClear(PCache *pCache){
53334 sqlite3PcacheTruncate(pCache, 0);
53413 SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
53415 for(p=pCache->pDirty; p; p=p->pDirtyNext){
53418 return pcacheSortDirtyList(pCache->pDirty);
53427 SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *pCache){
53428 return pCache->nRefSum;
53441 SQLITE_PRIVATE int sqlite3PcachePagecount(PCache *pCache){
53442 assert( pCache->pCache!=0 );
53443 return sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache);
53450 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *pCache){
53451 return numberOfCachePages(pCache);
53458 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){
53459 assert( pCache->pCache!=0 );
53460 pCache->szCache = mxPage;
53461 sqlite3GlobalConfig.pcache2.xCachesize(pCache->pCache,
53462 numberOfCachePages(pCache));
53472 assert( p->pCache!=0 );
53487 SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){
53488 assert( pCache->pCache!=0 );
53489 sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache);
53502 SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache *pCache){
53505 int nCache = numberOfCachePages(pCache);
53506 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext) nDirty++;
53514 SQLITE_PRIVATE int sqlite3PCacheIsDirty(PCache *pCache){
53515 return (pCache->pDirty!=0);
53525 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *)){
53527 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext){
53627 ** structure. A buffer of PgHdr1.pCache->szPage bytes is allocated
53657 PCache1 *pCache; /* Cache that currently owns this page */
53832 ** Try to initialize the pCache->pFree and pCache->pBulk fields. Return
53833 ** true if pCache->pFree ends up containing one or more free pages.
53835 static int pcache1InitBulk(PCache1 *pCache){
53840 if( pCache->nMax<3 ) return 0;
53843 szBulk = pCache->szAlloc * (i64)pcache1.nInitPage;
53847 if( szBulk > pCache->szAlloc*(i64)pCache->nMax ){
53848 szBulk = pCache->szAlloc*(i64)pCache->nMax;
53850 zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
53853 int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
53855 PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
53860 pX->pNext = pCache->pFree;
53862 pCache->pFree = pX;
53863 zBulk += pCache->szAlloc;
53866 return pCache->pFree!=0;
53964 ** Allocate a new page object initially associated with cache pCache.
53966 static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc){
53970 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
53971 if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){
53972 assert( pCache->pFree!=0 );
53973 p = pCache->pFree;
53974 pCache->pFree = p->pNext;
53982 assert( pCache->pGroup==&pcache1.grp );
53983 pcache1LeaveMutex(pCache->pGroup);
53986 pPg = pcache1Alloc(pCache->szAlloc);
53989 pcache1EnterMutex(pCache->pGroup);
53992 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
53999 (*pCache->pnPurgeable)++;
54007 PCache1 *pCache;
54009 pCache = p->pCache;
54010 assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
54012 p->pNext = pCache->pFree;
54013 pCache->pFree = p;
54017 (*pCache->pnPurgeable)--;
54054 static int pcache1UnderMemoryPressure(PCache1 *pCache){
54055 if( pcache1.nSlot && (pCache->szPage+pCache->szExtra)<=pcache1.szSlot ){
54117 assert( sqlite3_mutex_held(pPage->pCache->pGroup->mutex) );
54124 assert( pPage->pCache->pGroup->lru.isAnchor==1 );
54125 pPage->pCache->nRecyclable--;
54139 PCache1 *pCache = pPage->pCache;
54142 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
54143 h = pPage->iKey % pCache->nHash;
54144 for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
54147 pCache->nPage--;
54155 static void pcache1EnforceMaxPage(PCache1 *pCache){
54156 PGroup *pGroup = pCache->pGroup;
54162 assert( p->pCache->pGroup==pGroup );
54167 if( pCache->nPage==0 && pCache->pBulk ){
54168 sqlite3_free(pCache->pBulk);
54169 pCache->pBulk = pCache->pFree = 0;
54174 ** Discard all pages from cache pCache with a page number (key value)
54181 PCache1 *pCache, /* The cache to truncate */
54184 TESTONLY( int nPage = 0; ) /* To assert pCache->nPage is correct */
54186 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
54187 assert( pCache->iMaxKey >= iLimit );
54188 assert( pCache->nHash > 0 );
54189 if( pCache->iMaxKey - iLimit < pCache->nHash ){
54194 h = iLimit % pCache->nHash;
54195 iStop = pCache->iMaxKey % pCache->nHash;
54196 TESTONLY( nPage = -10; ) /* Disable the pCache->nPage validity check */
54200 h = pCache->nHash/2;
54206 assert( h<pCache->nHash );
54207 pp = &pCache->apHash[h];
54210 pCache->nPage--;
54220 h = (h+1) % pCache->nHash;
54222 assert( nPage<0 || pCache->nPage==(unsigned)nPage );
54299 PCache1 *pCache; /* The newly created page cache */
54307 pCache = (PCache1 *)sqlite3MallocZero(sz);
54308 if( pCache ){
54310 pGroup = (PGroup*)&pCache[1];
54320 pCache->pGroup = pGroup;
54321 pCache->szPage = szPage;
54322 pCache->szExtra = szExtra;
54323 pCache->szAlloc = szPage + szExtra + ROUND8(sizeof(PgHdr1));
54324 pCache->bPurgeable = (bPurgeable ? 1 : 0);
54325 pcache1ResizeHash(pCache);
54327 pCache->nMin = 10;
54328 pGroup->nMinPage += pCache->nMin;
54330 pCache->pnPurgeable = &pGroup->nPurgeable;
54332 pCache->pnPurgeable = &pCache->nPurgeableDummy;
54335 if( pCache->nHash==0 ){
54336 pcache1Destroy((sqlite3_pcache*)pCache);
54337 pCache = 0;
54340 return (sqlite3_pcache *)pCache;
54349 PCache1 *pCache = (PCache1 *)p;
54352 if( pCache->bPurgeable ){
54353 PGroup *pGroup = pCache->pGroup;
54356 if( n > 0x7fff0000 - pGroup->nMaxPage + pCache->nMax ){
54357 n = 0x7fff0000 - pGroup->nMaxPage + pCache->nMax;
54359 pGroup->nMaxPage += (n - pCache->nMax);
54361 pCache->nMax = n;
54362 pCache->n90pct = pCache->nMax*9/10;
54363 pcache1EnforceMaxPage(pCache);
54374 PCache1 *pCache = (PCache1*)p;
54375 if( pCache->bPurgeable ){
54376 PGroup *pGroup = pCache->pGroup;
54381 pcache1EnforceMaxPage(pCache);
54392 PCache1 *pCache = (PCache1*)p;
54393 pcache1EnterMutex(pCache->pGroup);
54394 n = pCache->nPage;
54395 pcache1LeaveMutex(pCache->pGroup);
54409 PCache1 *pCache,
54414 PGroup *pGroup = pCache->pGroup;
54418 assert( pCache->nPage >= pCache->nRecyclable );
54419 nPinned = pCache->nPage - pCache->nRecyclable;
54421 assert( pCache->n90pct == pCache->nMax*9/10 );
54424 || nPinned>=pCache->n90pct
54425 || (pcache1UnderMemoryPressure(pCache) && pCache->nRecyclable<nPinned)
54430 if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
54431 assert( pCache->nHash>0 && pCache->apHash );
54434 if( pCache->bPurgeable
54436 && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
54443 pOther = pPage->pCache;
54444 if( pOther->szAlloc != pCache->szAlloc ){
54448 pGroup->nPurgeable -= (pOther->bPurgeable - pCache->bPurgeable);
54456 pPage = pcache1AllocPage(pCache, createFlag==1);
54460 unsigned int h = iKey % pCache->nHash;
54461 pCache->nPage++;
54463 pPage->pNext = pCache->apHash[h];
54464 pPage->pCache = pCache;
54469 pCache->apHash[h] = pPage;
54470 if( iKey>pCache->iMaxKey ){
54471 pCache->iMaxKey = iKey;
54541 PCache1 *pCache = (PCache1 *)p;
54545 pPage = pCache->apHash[iKey % pCache->nHash];
54560 return pcache1FetchStage2(pCache, iKey, createFlag);
54571 PCache1 *pCache = (PCache1 *)p;
54574 pcache1EnterMutex(pCache->pGroup);
54576 assert( pPage==0 || pCache->iMaxKey>=iKey );
54577 pcache1LeaveMutex(pCache->pGroup);
54587 PCache1 *pCache = (PCache1 *)p;
54591 assert( pCache->bPurgeable || createFlag!=1 );
54592 assert( pCache->bPurgeable || pCache->nMin==0 );
54593 assert( pCache->bPurgeable==0 || pCache->nMin==10 );
54594 assert( pCache->nMin==0 || pCache->bPurgeable );
54595 assert( pCache->nHash>0 );
54597 if( pCache->pGroup->mutex ){
54617 PCache1 *pCache = (PCache1 *)p;
54619 PGroup *pGroup = pCache->pGroup;
54621 assert( pPage->pCache==pCache );
54638 pCache->nRecyclable++;
54641 pcache1LeaveMutex(pCache->pGroup);
54653 PCache1 *pCache = (PCache1 *)p;
54658 assert( pPage->pCache==pCache );
54661 pcache1EnterMutex(pCache->pGroup);
54664 hOld = iOld%pCache->nHash;
54665 pp = &pCache->apHash[hOld];
54672 hNew = iNew%pCache->nHash;
54674 pPage->pNext = pCache->apHash[hNew];
54675 pCache->apHash[hNew] = pPage;
54676 if( iNew>pCache->iMaxKey ){
54677 pCache->iMaxKey = iNew;
54680 pcache1LeaveMutex(pCache->pGroup);
54691 PCache1 *pCache = (PCache1 *)p;
54692 pcache1EnterMutex(pCache->pGroup);
54693 if( iLimit<=pCache->iMaxKey ){
54694 pcache1TruncateUnsafe(pCache, iLimit);
54695 pCache->iMaxKey = iLimit-1;
54697 pcache1LeaveMutex(pCache->pGroup);
54706 PCache1 *pCache = (PCache1 *)p;
54707 PGroup *pGroup = pCache->pGroup;
54708 assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) );
54710 if( pCache->nPage ) pcache1TruncateUnsafe(pCache, 0);
54711 assert( pGroup->nMaxPage >= pCache->nMax );
54712 pGroup->nMaxPage -= pCache->nMax;
54713 assert( pGroup->nMinPage >= pCache->nMin );
54714 pGroup->nMinPage -= pCache->nMin;
54716 pcache1EnforceMaxPage(pCache);
54718 sqlite3_free(pCache->pBulk);
54719 sqlite3_free(pCache->apHash);
54720 sqlite3_free(pCache);