Lines Matching refs:pCache
14491 PCache *pCache; /* PRIVATE: Cache that owns this page */ member
14601 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
45247 sqlite3_pcache *pCache; /* Pluggable cache module */
45263 void pcacheDump(PCache *pCache){
45271 if( pCache->pCache==0 ) return;
45272 N = sqlite3PcachePagecount(pCache);
45275 pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
45283 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
45303 PCache *pCache;
45306 pCache = pPg->pCache;
45307 assert( pCache!=0 ); /* Every page has an associated PCache */
45310 assert( pCache->pDirty!=pPg ); /* CLEAN pages not on dirty list */
45311 assert( pCache->pDirtyTail!=pPg );
45353 PCache *p = pPage->pCache;
45423 if( p->pCache->bPurgeable ){
45424 pcacheTrace(("%p.UNPIN %d\n", p->pCache, p->pgno));
45425 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
45426 pcacheDump(p->pCache);
45511 SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
45512 assert( pCache->nRefSum==0 && pCache->pDirty==0 );
45513 if( pCache->szPage ){
45516 szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
45517 pCache->bPurgeable
45520 sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache));
45521 if( pCache->pCache ){
45522 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
45524 pCache->pCache = pNew;
45525 pCache->szPage = szPage;
45526 pcacheTrace(("%p.PAGESIZE %d\n",pCache,szPage));
45556 PCache *pCache, /* Obtain the page from this cache */
45563 assert( pCache!=0 );
45564 assert( pCache->pCache!=0 );
45566 assert( pCache->eCreate==((pCache->bPurgeable && pCache->pDirty) ? 1 : 2) );
45575 eCreate = createFlag & pCache->eCreate;
45577 assert( createFlag==0 || pCache->eCreate==eCreate );
45578 assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
45579 pRes = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
45580 pcacheTrace(("%p.FETCH %d%s (result: %p)\n",pCache,pgno,
45597 PCache *pCache, /* Obtain the page from this cache */
45602 if( pCache->eCreate==2 ) return 0;
45604 if( sqlite3PcachePagecount(pCache)>pCache->szSpill ){
45614 for(pPg=pCache->pSynced;
45618 pCache->pSynced = pPg;
45620 for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
45628 sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache),
45629 numberOfCachePages(pCache));
45631 pcacheTrace(("%p.SPILL %d\n",pCache,pPg->pgno));
45632 rc = pCache->xStress(pCache->pStress, pPg);
45633 pcacheDump(pCache);
45639 *ppPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, 2);
45653 PCache *pCache, /* Obtain the page from this cache */
45666 pPgHdr->pCache = pCache;
45669 return sqlite3PcacheFetchFinish(pCache,pgno,pPage);
45679 PCache *pCache, /* Obtain the page from this cache */
45689 return pcacheFetchFinishWithInit(pCache, pgno, pPage);
45691 pCache->nRefSum++;
45703 p->pCache->nRefSum--;
45720 p->pCache->nRefSum++;
45734 p->pCache->nRefSum--;
45735 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
45749 pcacheTrace(("%p.DIRTY %d\n",p->pCache,p->pgno));
45768 pcacheTrace(("%p.CLEAN %d\n",p->pCache,p->pgno));
45778 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
45780 pcacheTrace(("%p.CLEAN-ALL\n",pCache));
45781 while( (p = pCache->pDirty)!=0 ){
45789 SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache *pCache){
45791 pcacheTrace(("%p.CLEAR-WRITEABLE\n",pCache));
45792 for(p=pCache->pDirty; p; p=p->pDirtyNext){
45795 pCache->pSynced = pCache->pDirtyTail;
45801 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){
45803 for(p=pCache->pDirty; p; p=p->pDirtyNext){
45806 pCache->pSynced = pCache->pDirtyTail;
45813 PCache *pCache = p->pCache;
45817 pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno));
45818 sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
45834 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
45835 if( pCache->pCache ){
45838 pcacheTrace(("%p.TRUNCATE %d\n",pCache,pgno));
45839 for(p=pCache->pDirty; p; p=pNext){
45851 if( pgno==0 && pCache->nRefSum ){
45853 pPage1 = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache,1,0);
45856 memset(pPage1->pBuf, 0, pCache->szPage);
45860 sqlite3GlobalConfig.pcache2.xTruncate(pCache->pCache, pgno+1);
45867 SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
45868 assert( pCache->pCache!=0 );
45869 pcacheTrace(("%p.CLOSE\n",pCache));
45870 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
45876 SQLITE_PRIVATE void sqlite3PcacheClear(PCache *pCache){
45877 sqlite3PcacheTruncate(pCache, 0);
45956 SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
45958 for(p=pCache->pDirty; p; p=p->pDirtyNext){
45961 return pcacheSortDirtyList(pCache->pDirty);
45970 SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *pCache){
45971 return pCache->nRefSum;
45984 SQLITE_PRIVATE int sqlite3PcachePagecount(PCache *pCache){
45985 assert( pCache->pCache!=0 );
45986 return sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache);
45993 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *pCache){
45994 return numberOfCachePages(pCache);
46001 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){
46002 assert( pCache->pCache!=0 );
46003 pCache->szCache = mxPage;
46004 sqlite3GlobalConfig.pcache2.xCachesize(pCache->pCache,
46005 numberOfCachePages(pCache));
46015 assert( p->pCache!=0 );
46030 SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){
46031 assert( pCache->pCache!=0 );
46032 sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache);
46045 SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache *pCache){
46048 int nCache = numberOfCachePages(pCache);
46049 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext) nDirty++;
46059 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *)){
46061 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext){
46170 PCache1 *pCache; /* Cache that currently owns this page */
46345 static int pcache1InitBulk(PCache1 *pCache){
46350 if( pCache->nMax<3 ) return 0;
46353 szBulk = pCache->szAlloc * (i64)pcache1.nInitPage;
46357 if( szBulk > pCache->szAlloc*(i64)pCache->nMax ){
46358 szBulk = pCache->szAlloc*(i64)pCache->nMax;
46360 zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
46363 int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
46365 PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
46370 pX->pNext = pCache->pFree;
46371 pCache->pFree = pX;
46372 zBulk += pCache->szAlloc;
46375 return pCache->pFree!=0;
46475 static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc){
46479 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
46480 if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){
46481 p = pCache->pFree;
46482 pCache->pFree = p->pNext;
46490 assert( pCache->pGroup==&pcache1.grp );
46491 pcache1LeaveMutex(pCache->pGroup);
46495 pPg = pcache1Alloc(pCache->szPage);
46496 p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
46503 pPg = pcache1Alloc(pCache->szAlloc);
46504 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
46508 pcache1EnterMutex(pCache->pGroup);
46516 (*pCache->pnPurgeable)++;
46524 PCache1 *pCache;
46526 pCache = p->pCache;
46527 assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
46529 p->pNext = pCache->pFree;
46530 pCache->pFree = p;
46537 (*pCache->pnPurgeable)--;
46573 static int pcache1UnderMemoryPressure(PCache1 *pCache){
46574 if( pcache1.nSlot && (pCache->szPage+pCache->szExtra)<=pcache1.szSlot ){
46636 assert( sqlite3_mutex_held(pPage->pCache->pGroup->mutex) );
46642 assert( pPage->pCache->pGroup->lru.isAnchor==1 );
46643 pPage->pCache->nRecyclable--;
46657 PCache1 *pCache = pPage->pCache;
46660 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
46661 h = pPage->iKey % pCache->nHash;
46662 for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
46665 pCache->nPage--;
46673 static void pcache1EnforceMaxPage(PCache1 *pCache){
46674 PGroup *pGroup = pCache->pGroup;
46680 assert( p->pCache->pGroup==pGroup );
46685 if( pCache->nPage==0 && pCache->pBulk ){
46686 sqlite3_free(pCache->pBulk);
46687 pCache->pBulk = pCache->pFree = 0;
46699 PCache1 *pCache, /* The cache to truncate */
46704 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
46705 assert( pCache->iMaxKey >= iLimit );
46706 assert( pCache->nHash > 0 );
46707 if( pCache->iMaxKey - iLimit < pCache->nHash ){
46712 h = iLimit % pCache->nHash;
46713 iStop = pCache->iMaxKey % pCache->nHash;
46718 h = pCache->nHash/2;
46724 assert( h<pCache->nHash );
46725 pp = &pCache->apHash[h];
46728 pCache->nPage--;
46738 h = (h+1) % pCache->nHash;
46740 assert( nPage<0 || pCache->nPage==(unsigned)nPage );
46817 PCache1 *pCache; /* The newly created page cache */
46825 pCache = (PCache1 *)sqlite3MallocZero(sz);
46826 if( pCache ){
46828 pGroup = (PGroup*)&pCache[1];
46837 pCache->pGroup = pGroup;
46838 pCache->szPage = szPage;
46839 pCache->szExtra = szExtra;
46840 pCache->szAlloc = szPage + szExtra + ROUND8(sizeof(PgHdr1));
46841 pCache->bPurgeable = (bPurgeable ? 1 : 0);
46843 pcache1ResizeHash(pCache);
46845 pCache->nMin = 10;
46846 pGroup->nMinPage += pCache->nMin;
46848 pCache->pnPurgeable = &pGroup->nPurgeable;
46851 pCache->pnPurgeable = &dummyCurrentPage;
46854 if( pCache->nHash==0 ){
46855 pcache1Destroy((sqlite3_pcache*)pCache);
46856 pCache = 0;
46859 return (sqlite3_pcache *)pCache;
46868 PCache1 *pCache = (PCache1 *)p;
46869 if( pCache->bPurgeable ){
46870 PGroup *pGroup = pCache->pGroup;
46872 pGroup->nMaxPage += (nMax - pCache->nMax);
46874 pCache->nMax = nMax;
46875 pCache->n90pct = pCache->nMax*9/10;
46876 pcache1EnforceMaxPage(pCache);
46887 PCache1 *pCache = (PCache1*)p;
46888 if( pCache->bPurgeable ){
46889 PGroup *pGroup = pCache->pGroup;
46894 pcache1EnforceMaxPage(pCache);
46905 PCache1 *pCache = (PCache1*)p;
46906 pcache1EnterMutex(pCache->pGroup);
46907 n = pCache->nPage;
46908 pcache1LeaveMutex(pCache->pGroup);
46922 PCache1 *pCache,
46927 PGroup *pGroup = pCache->pGroup;
46931 assert( pCache->nPage >= pCache->nRecyclable );
46932 nPinned = pCache->nPage - pCache->nRecyclable;
46934 assert( pCache->n90pct == pCache->nMax*9/10 );
46937 || nPinned>=pCache->n90pct
46938 || (pcache1UnderMemoryPressure(pCache) && pCache->nRecyclable<nPinned)
46943 if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
46944 assert( pCache->nHash>0 && pCache->apHash );
46947 if( pCache->bPurgeable
46949 && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
46956 pOther = pPage->pCache;
46957 if( pOther->szAlloc != pCache->szAlloc ){
46961 pGroup->nPurgeable -= (pOther->bPurgeable - pCache->bPurgeable);
46969 pPage = pcache1AllocPage(pCache, createFlag==1);
46973 unsigned int h = iKey % pCache->nHash;
46974 pCache->nPage++;
46976 pPage->pNext = pCache->apHash[h];
46977 pPage->pCache = pCache;
46981 pCache->apHash[h] = pPage;
46982 if( iKey>pCache->iMaxKey ){
46983 pCache->iMaxKey = iKey;
47053 PCache1 *pCache = (PCache1 *)p;
47057 pPage = pCache->apHash[iKey % pCache->nHash];
47072 return pcache1FetchStage2(pCache, iKey, createFlag);
47083 PCache1 *pCache = (PCache1 *)p;
47086 pcache1EnterMutex(pCache->pGroup);
47088 assert( pPage==0 || pCache->iMaxKey>=iKey );
47089 pcache1LeaveMutex(pCache->pGroup);
47099 PCache1 *pCache = (PCache1 *)p;
47103 assert( pCache->bPurgeable || createFlag!=1 );
47104 assert( pCache->bPurgeable || pCache->nMin==0 );
47105 assert( pCache->bPurgeable==0 || pCache->nMin==10 );
47106 assert( pCache->nMin==0 || pCache->bPurgeable );
47107 assert( pCache->nHash>0 );
47109 if( pCache->pGroup->mutex ){
47129 PCache1 *pCache = (PCache1 *)p;
47131 PGroup *pGroup = pCache->pGroup;
47133 assert( pPage->pCache==pCache );
47150 pCache->nRecyclable++;
47153 pcache1LeaveMutex(pCache->pGroup);
47165 PCache1 *pCache = (PCache1 *)p;
47170 assert( pPage->pCache==pCache );
47172 pcache1EnterMutex(pCache->pGroup);
47174 h = iOld%pCache->nHash;
47175 pp = &pCache->apHash[h];
47181 h = iNew%pCache->nHash;
47183 pPage->pNext = pCache->apHash[h];
47184 pCache->apHash[h] = pPage;
47185 if( iNew>pCache->iMaxKey ){
47186 pCache->iMaxKey = iNew;
47189 pcache1LeaveMutex(pCache->pGroup);
47200 PCache1 *pCache = (PCache1 *)p;
47201 pcache1EnterMutex(pCache->pGroup);
47202 if( iLimit<=pCache->iMaxKey ){
47203 pcache1TruncateUnsafe(pCache, iLimit);
47204 pCache->iMaxKey = iLimit-1;
47206 pcache1LeaveMutex(pCache->pGroup);
47215 PCache1 *pCache = (PCache1 *)p;
47216 PGroup *pGroup = pCache->pGroup;
47217 assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) );
47219 if( pCache->nPage ) pcache1TruncateUnsafe(pCache, 0);
47220 assert( pGroup->nMaxPage >= pCache->nMax );
47221 pGroup->nMaxPage -= pCache->nMax;
47222 assert( pGroup->nMinPage >= pCache->nMin );
47223 pGroup->nMinPage -= pCache->nMin;
47225 pcache1EnforceMaxPage(pCache);
47227 sqlite3_free(pCache->pBulk);
47228 sqlite3_free(pCache->apHash);
47229 sqlite3_free(pCache);