Lines Matching refs:pCache

15681   PCache *pCache;                /* PRIVATE: Cache that owns this page */  member
15791 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
15839 SQLITE_PRIVATE int sqlite3PCacheIsDirty(PCache *pCache);
49873 sqlite3_pcache *pCache; /* Pluggable cache module */
49889 void pcacheDump(PCache *pCache){
49897 if( pCache->pCache==0 ) return;
49898 N = sqlite3PcachePagecount(pCache);
49901 pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
49909 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
49929 PCache *pCache;
49932 pCache = pPg->pCache;
49933 assert( pCache!=0 ); /* Every page has an associated PCache */
49936 assert( pCache->pDirty!=pPg ); /* CLEAN pages not on dirty list */
49937 assert( pCache->pDirtyTail!=pPg );
49979 PCache *p = pPage->pCache;
50049 if( p->pCache->bPurgeable ){
50050 pcacheTrace(("%p.UNPIN %d\n", p->pCache, p->pgno));
50051 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
50052 pcacheDump(p->pCache);
50142 SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
50143 assert( pCache->nRefSum==0 && pCache->pDirty==0 );
50144 if( pCache->szPage ){
50147 szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
50148 pCache->bPurgeable
50151 sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache));
50152 if( pCache->pCache ){
50153 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
50155 pCache->pCache = pNew;
50156 pCache->szPage = szPage;
50157 pcacheTrace(("%p.PAGESIZE %d\n",pCache,szPage));
50187 PCache *pCache, /* Obtain the page from this cache */
50194 assert( pCache!=0 );
50195 assert( pCache->pCache!=0 );
50197 assert( pCache->eCreate==((pCache->bPurgeable && pCache->pDirty) ? 1 : 2) );
50206 eCreate = createFlag & pCache->eCreate;
50208 assert( createFlag==0 || pCache->eCreate==eCreate );
50209 assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
50210 pRes = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
50211 pcacheTrace(("%p.FETCH %d%s (result: %p)\n",pCache,pgno,
50228 PCache *pCache, /* Obtain the page from this cache */
50233 if( pCache->eCreate==2 ) return 0;
50235 if( sqlite3PcachePagecount(pCache)>pCache->szSpill ){
50245 for(pPg=pCache->pSynced;
50249 pCache->pSynced = pPg;
50251 for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
50259 sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache),
50260 numberOfCachePages(pCache));
50262 pcacheTrace(("%p.SPILL %d\n",pCache,pPg->pgno));
50263 rc = pCache->xStress(pCache->pStress, pPg);
50264 pcacheDump(pCache);
50270 *ppPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, 2);
50284 PCache *pCache, /* Obtain the page from this cache */
50297 pPgHdr->pCache = pCache;
50300 return sqlite3PcacheFetchFinish(pCache,pgno,pPage);
50310 PCache *pCache, /* Obtain the page from this cache */
50320 return pcacheFetchFinishWithInit(pCache, pgno, pPage);
50322 pCache->nRefSum++;
50334 p->pCache->nRefSum--;
50351 p->pCache->nRefSum++;
50365 p->pCache->nRefSum--;
50366 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
50380 pcacheTrace(("%p.DIRTY %d\n",p->pCache,p->pgno));
50399 pcacheTrace(("%p.CLEAN %d\n",p->pCache,p->pgno));
50409 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
50411 pcacheTrace(("%p.CLEAN-ALL\n",pCache));
50412 while( (p = pCache->pDirty)!=0 ){
50420 SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache *pCache){
50422 pcacheTrace(("%p.CLEAR-WRITEABLE\n",pCache));
50423 for(p=pCache->pDirty; p; p=p->pDirtyNext){
50426 pCache->pSynced = pCache->pDirtyTail;
50432 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){
50434 for(p=pCache->pDirty; p; p=p->pDirtyNext){
50437 pCache->pSynced = pCache->pDirtyTail;
50444 PCache *pCache = p->pCache;
50448 pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno));
50449 sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
50465 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
50466 if( pCache->pCache ){
50469 pcacheTrace(("%p.TRUNCATE %d\n",pCache,pgno));
50470 for(p=pCache->pDirty; p; p=pNext){
50482 if( pgno==0 && pCache->nRefSum ){
50484 pPage1 = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache,1,0);
50487 memset(pPage1->pBuf, 0, pCache->szPage);
50491 sqlite3GlobalConfig.pcache2.xTruncate(pCache->pCache, pgno+1);
50498 SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
50499 assert( pCache->pCache!=0 );
50500 pcacheTrace(("%p.CLOSE\n",pCache));
50501 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
50507 SQLITE_PRIVATE void sqlite3PcacheClear(PCache *pCache){
50508 sqlite3PcacheTruncate(pCache, 0);
50587 SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
50589 for(p=pCache->pDirty; p; p=p->pDirtyNext){
50592 return pcacheSortDirtyList(pCache->pDirty);
50601 SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *pCache){
50602 return pCache->nRefSum;
50615 SQLITE_PRIVATE int sqlite3PcachePagecount(PCache *pCache){
50616 assert( pCache->pCache!=0 );
50617 return sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache);
50624 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *pCache){
50625 return numberOfCachePages(pCache);
50632 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){
50633 assert( pCache->pCache!=0 );
50634 pCache->szCache = mxPage;
50635 sqlite3GlobalConfig.pcache2.xCachesize(pCache->pCache,
50636 numberOfCachePages(pCache));
50646 assert( p->pCache!=0 );
50661 SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){
50662 assert( pCache->pCache!=0 );
50663 sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache);
50676 SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache *pCache){
50679 int nCache = numberOfCachePages(pCache);
50680 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext) nDirty++;
50688 SQLITE_PRIVATE int sqlite3PCacheIsDirty(PCache *pCache){
50689 return (pCache->pDirty!=0);
50699 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *)){
50701 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext){
50820 PCache1 *pCache; /* Cache that currently owns this page */
50998 static int pcache1InitBulk(PCache1 *pCache){
51003 if( pCache->nMax<3 ) return 0;
51006 szBulk = pCache->szAlloc * (i64)pcache1.nInitPage;
51010 if( szBulk > pCache->szAlloc*(i64)pCache->nMax ){
51011 szBulk = pCache->szAlloc*(i64)pCache->nMax;
51013 zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
51016 int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
51018 PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
51023 pX->pNext = pCache->pFree;
51025 pCache->pFree = pX;
51026 zBulk += pCache->szAlloc;
51029 return pCache->pFree!=0;
51129 static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc){
51133 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
51134 if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){
51135 assert( pCache->pFree!=0 );
51136 p = pCache->pFree;
51137 pCache->pFree = p->pNext;
51145 assert( pCache->pGroup==&pcache1.grp );
51146 pcache1LeaveMutex(pCache->pGroup);
51150 pPg = pcache1Alloc(pCache->szPage);
51151 p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
51158 pPg = pcache1Alloc(pCache->szAlloc);
51162 pcache1EnterMutex(pCache->pGroup);
51166 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
51174 (*pCache->pnPurgeable)++;
51182 PCache1 *pCache;
51184 pCache = p->pCache;
51185 assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
51187 p->pNext = pCache->pFree;
51188 pCache->pFree = p;
51195 (*pCache->pnPurgeable)--;
51232 static int pcache1UnderMemoryPressure(PCache1 *pCache){
51233 if( pcache1.nSlot && (pCache->szPage+pCache->szExtra)<=pcache1.szSlot ){
51295 assert( sqlite3_mutex_held(pPage->pCache->pGroup->mutex) );
51302 assert( pPage->pCache->pGroup->lru.isAnchor==1 );
51303 pPage->pCache->nRecyclable--;
51317 PCache1 *pCache = pPage->pCache;
51320 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
51321 h = pPage->iKey % pCache->nHash;
51322 for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
51325 pCache->nPage--;
51333 static void pcache1EnforceMaxPage(PCache1 *pCache){
51334 PGroup *pGroup = pCache->pGroup;
51340 assert( p->pCache->pGroup==pGroup );
51345 if( pCache->nPage==0 && pCache->pBulk ){
51346 sqlite3_free(pCache->pBulk);
51347 pCache->pBulk = pCache->pFree = 0;
51359 PCache1 *pCache, /* The cache to truncate */
51364 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
51365 assert( pCache->iMaxKey >= iLimit );
51366 assert( pCache->nHash > 0 );
51367 if( pCache->iMaxKey - iLimit < pCache->nHash ){
51372 h = iLimit % pCache->nHash;
51373 iStop = pCache->iMaxKey % pCache->nHash;
51378 h = pCache->nHash/2;
51384 assert( h<pCache->nHash );
51385 pp = &pCache->apHash[h];
51388 pCache->nPage--;
51398 h = (h+1) % pCache->nHash;
51400 assert( nPage<0 || pCache->nPage==(unsigned)nPage );
51477 PCache1 *pCache; /* The newly created page cache */
51485 pCache = (PCache1 *)sqlite3MallocZero(sz);
51486 if( pCache ){
51488 pGroup = (PGroup*)&pCache[1];
51498 pCache->pGroup = pGroup;
51499 pCache->szPage = szPage;
51500 pCache->szExtra = szExtra;
51501 pCache->szAlloc = szPage + szExtra + ROUND8(sizeof(PgHdr1));
51502 pCache->bPurgeable = (bPurgeable ? 1 : 0);
51503 pcache1ResizeHash(pCache);
51505 pCache->nMin = 10;
51506 pGroup->nMinPage += pCache->nMin;
51508 pCache->pnPurgeable = &pGroup->nPurgeable;
51510 pCache->pnPurgeable = &pCache->nPurgeableDummy;
51513 if( pCache->nHash==0 ){
51514 pcache1Destroy((sqlite3_pcache*)pCache);
51515 pCache = 0;
51518 return (sqlite3_pcache *)pCache;
51527 PCache1 *pCache = (PCache1 *)p;
51530 if( pCache->bPurgeable ){
51531 PGroup *pGroup = pCache->pGroup;
51534 if( n > 0x7fff0000 - pGroup->nMaxPage + pCache->nMax ){
51535 n = 0x7fff0000 - pGroup->nMaxPage + pCache->nMax;
51537 pGroup->nMaxPage += (n - pCache->nMax);
51539 pCache->nMax = n;
51540 pCache->n90pct = pCache->nMax*9/10;
51541 pcache1EnforceMaxPage(pCache);
51552 PCache1 *pCache = (PCache1*)p;
51553 if( pCache->bPurgeable ){
51554 PGroup *pGroup = pCache->pGroup;
51559 pcache1EnforceMaxPage(pCache);
51570 PCache1 *pCache = (PCache1*)p;
51571 pcache1EnterMutex(pCache->pGroup);
51572 n = pCache->nPage;
51573 pcache1LeaveMutex(pCache->pGroup);
51587 PCache1 *pCache,
51592 PGroup *pGroup = pCache->pGroup;
51596 assert( pCache->nPage >= pCache->nRecyclable );
51597 nPinned = pCache->nPage - pCache->nRecyclable;
51599 assert( pCache->n90pct == pCache->nMax*9/10 );
51602 || nPinned>=pCache->n90pct
51603 || (pcache1UnderMemoryPressure(pCache) && pCache->nRecyclable<nPinned)
51608 if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
51609 assert( pCache->nHash>0 && pCache->apHash );
51612 if( pCache->bPurgeable
51614 && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
51621 pOther = pPage->pCache;
51622 if( pOther->szAlloc != pCache->szAlloc ){
51626 pGroup->nPurgeable -= (pOther->bPurgeable - pCache->bPurgeable);
51634 pPage = pcache1AllocPage(pCache, createFlag==1);
51638 unsigned int h = iKey % pCache->nHash;
51639 pCache->nPage++;
51641 pPage->pNext = pCache->apHash[h];
51642 pPage->pCache = pCache;
51647 pCache->apHash[h] = pPage;
51648 if( iKey>pCache->iMaxKey ){
51649 pCache->iMaxKey = iKey;
51719 PCache1 *pCache = (PCache1 *)p;
51723 pPage = pCache->apHash[iKey % pCache->nHash];
51738 return pcache1FetchStage2(pCache, iKey, createFlag);
51749 PCache1 *pCache = (PCache1 *)p;
51752 pcache1EnterMutex(pCache->pGroup);
51754 assert( pPage==0 || pCache->iMaxKey>=iKey );
51755 pcache1LeaveMutex(pCache->pGroup);
51765 PCache1 *pCache = (PCache1 *)p;
51769 assert( pCache->bPurgeable || createFlag!=1 );
51770 assert( pCache->bPurgeable || pCache->nMin==0 );
51771 assert( pCache->bPurgeable==0 || pCache->nMin==10 );
51772 assert( pCache->nMin==0 || pCache->bPurgeable );
51773 assert( pCache->nHash>0 );
51775 if( pCache->pGroup->mutex ){
51795 PCache1 *pCache = (PCache1 *)p;
51797 PGroup *pGroup = pCache->pGroup;
51799 assert( pPage->pCache==pCache );
51816 pCache->nRecyclable++;
51819 pcache1LeaveMutex(pCache->pGroup);
51831 PCache1 *pCache = (PCache1 *)p;
51836 assert( pPage->pCache==pCache );
51838 pcache1EnterMutex(pCache->pGroup);
51840 h = iOld%pCache->nHash;
51841 pp = &pCache->apHash[h];
51847 h = iNew%pCache->nHash;
51849 pPage->pNext = pCache->apHash[h];
51850 pCache->apHash[h] = pPage;
51851 if( iNew>pCache->iMaxKey ){
51852 pCache->iMaxKey = iNew;
51855 pcache1LeaveMutex(pCache->pGroup);
51866 PCache1 *pCache = (PCache1 *)p;
51867 pcache1EnterMutex(pCache->pGroup);
51868 if( iLimit<=pCache->iMaxKey ){
51869 pcache1TruncateUnsafe(pCache, iLimit);
51870 pCache->iMaxKey = iLimit-1;
51872 pcache1LeaveMutex(pCache->pGroup);
51881 PCache1 *pCache = (PCache1 *)p;
51882 PGroup *pGroup = pCache->pGroup;
51883 assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) );
51885 if( pCache->nPage ) pcache1TruncateUnsafe(pCache, 0);
51886 assert( pGroup->nMaxPage >= pCache->nMax );
51887 pGroup->nMaxPage -= pCache->nMax;
51888 assert( pGroup->nMinPage >= pCache->nMin );
51889 pGroup->nMinPage -= pCache->nMin;
51891 pcache1EnforceMaxPage(pCache);
51893 sqlite3_free(pCache->pBulk);
51894 sqlite3_free(pCache->apHash);
51895 sqlite3_free(pCache);