Lines Matching refs:pCache
13445 PCache *pCache; /* Cache that owns this page */ member
13540 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
44290 sqlite3_pcache *pCache; /* Pluggable cache module */
44306 void pcacheDump(PCache *pCache){
44314 if( pCache->pCache==0 ) return;
44315 N = sqlite3PcachePagecount(pCache);
44318 pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
44326 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
44346 PCache *pCache;
44349 pCache = pPg->pCache;
44350 assert( pCache!=0 ); /* Every page has an associated PCache */
44353 assert( pCache->pDirty!=pPg ); /* CLEAN pages not on dirty list */
44354 assert( pCache->pDirtyTail!=pPg );
44396 PCache *p = pPage->pCache;
44469 if( p->pCache->bPurgeable ){
44470 pcacheTrace(("%p.UNPIN %d\n", p->pCache, p->pgno));
44471 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
44472 pcacheDump(p->pCache);
44557 SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
44558 assert( pCache->nRefSum==0 && pCache->pDirty==0 );
44559 if( pCache->szPage ){
44562 szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
44563 pCache->bPurgeable
44566 sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache));
44567 if( pCache->pCache ){
44568 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
44570 pCache->pCache = pNew;
44571 pCache->szPage = szPage;
44572 pcacheTrace(("%p.PAGESIZE %d\n",pCache,szPage));
44602 PCache *pCache, /* Obtain the page from this cache */
44609 assert( pCache!=0 );
44610 assert( pCache->pCache!=0 );
44612 assert( pCache->eCreate==((pCache->bPurgeable && pCache->pDirty) ? 1 : 2) );
44621 eCreate = createFlag & pCache->eCreate;
44623 assert( createFlag==0 || pCache->eCreate==eCreate );
44624 assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
44625 pRes = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
44626 pcacheTrace(("%p.FETCH %d%s (result: %p)\n",pCache,pgno,
44643 PCache *pCache, /* Obtain the page from this cache */
44648 if( pCache->eCreate==2 ) return 0;
44650 if( sqlite3PcachePagecount(pCache)>pCache->szSpill ){
44660 for(pPg=pCache->pSynced;
44664 pCache->pSynced = pPg;
44666 for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
44674 sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache),
44675 numberOfCachePages(pCache));
44677 pcacheTrace(("%p.SPILL %d\n",pCache,pPg->pgno));
44678 rc = pCache->xStress(pCache->pStress, pPg);
44679 pcacheDump(pCache);
44685 *ppPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, 2);
44699 PCache *pCache, /* Obtain the page from this cache */
44712 pPgHdr->pCache = pCache;
44715 return sqlite3PcacheFetchFinish(pCache,pgno,pPage);
44725 PCache *pCache, /* Obtain the page from this cache */
44735 return pcacheFetchFinishWithInit(pCache, pgno, pPage);
44737 pCache->nRefSum++;
44749 p->pCache->nRefSum--;
44770 p->pCache->nRefSum++;
44784 p->pCache->nRefSum--;
44785 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
44799 pcacheTrace(("%p.DIRTY %d\n",p->pCache,p->pgno));
44818 pcacheTrace(("%p.CLEAN %d\n",p->pCache,p->pgno));
44829 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
44831 pcacheTrace(("%p.CLEAN-ALL\n",pCache));
44832 while( (p = pCache->pDirty)!=0 ){
44840 SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache *pCache){
44842 pcacheTrace(("%p.CLEAR-WRITEABLE\n",pCache));
44843 for(p=pCache->pDirty; p; p=p->pDirtyNext){
44846 pCache->pSynced = pCache->pDirtyTail;
44852 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){
44854 for(p=pCache->pDirty; p; p=p->pDirtyNext){
44857 pCache->pSynced = pCache->pDirtyTail;
44864 PCache *pCache = p->pCache;
44868 pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno));
44869 sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
44885 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
44886 if( pCache->pCache ){
44889 pcacheTrace(("%p.TRUNCATE %d\n",pCache,pgno));
44890 for(p=pCache->pDirty; p; p=pNext){
44902 if( pgno==0 && pCache->nRefSum ){
44904 pPage1 = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache,1,0);
44907 memset(pPage1->pBuf, 0, pCache->szPage);
44911 sqlite3GlobalConfig.pcache2.xTruncate(pCache->pCache, pgno+1);
44918 SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
44919 assert( pCache->pCache!=0 );
44920 pcacheTrace(("%p.CLOSE\n",pCache));
44921 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
44927 SQLITE_PRIVATE void sqlite3PcacheClear(PCache *pCache){
44928 sqlite3PcacheTruncate(pCache, 0);
45007 SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
45009 for(p=pCache->pDirty; p; p=p->pDirtyNext){
45012 return pcacheSortDirtyList(pCache->pDirty);
45021 SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *pCache){
45022 return pCache->nRefSum;
45035 SQLITE_PRIVATE int sqlite3PcachePagecount(PCache *pCache){
45036 assert( pCache->pCache!=0 );
45037 return sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache);
45044 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *pCache){
45045 return numberOfCachePages(pCache);
45052 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){
45053 assert( pCache->pCache!=0 );
45054 pCache->szCache = mxPage;
45055 sqlite3GlobalConfig.pcache2.xCachesize(pCache->pCache,
45056 numberOfCachePages(pCache));
45066 assert( p->pCache!=0 );
45081 SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){
45082 assert( pCache->pCache!=0 );
45083 sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache);
45096 SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache *pCache){
45099 int nCache = numberOfCachePages(pCache);
45100 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext) nDirty++;
45110 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *)){
45112 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext){
45222 PCache1 *pCache; /* Cache that currently owns this page */
45388 static int pcache1InitBulk(PCache1 *pCache){
45393 if( pCache->nMax<3 ) return 0;
45396 szBulk = pCache->szAlloc * (i64)pcache1.nInitPage;
45400 if( szBulk > pCache->szAlloc*(i64)pCache->nMax ){
45401 szBulk = pCache->szAlloc*(i64)pCache->nMax;
45403 zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
45406 int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
45408 PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
45413 pX->pNext = pCache->pFree;
45414 pCache->pFree = pX;
45415 zBulk += pCache->szAlloc;
45418 return pCache->pFree!=0;
45518 static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc){
45522 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
45523 if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){
45524 p = pCache->pFree;
45525 pCache->pFree = p->pNext;
45533 assert( pCache->pGroup==&pcache1.grp );
45534 pcache1LeaveMutex(pCache->pGroup);
45538 pPg = pcache1Alloc(pCache->szPage);
45539 p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
45546 pPg = pcache1Alloc(pCache->szAlloc);
45547 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
45551 pcache1EnterMutex(pCache->pGroup);
45559 if( pCache->bPurgeable ){
45560 pCache->pGroup->nCurrentPage++;
45569 PCache1 *pCache;
45571 pCache = p->pCache;
45572 assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
45574 p->pNext = pCache->pFree;
45575 pCache->pFree = p;
45582 if( pCache->bPurgeable ){
45583 pCache->pGroup->nCurrentPage--;
45620 static int pcache1UnderMemoryPressure(PCache1 *pCache){
45621 if( pcache1.nSlot && (pCache->szPage+pCache->szExtra)<=pcache1.szSlot ){
45679 PCache1 *pCache;
45683 pCache = pPage->pCache;
45686 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
45693 assert( pCache->pGroup->lru.isAnchor==1 );
45694 pCache->nRecyclable--;
45708 PCache1 *pCache = pPage->pCache;
45711 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
45712 h = pPage->iKey % pCache->nHash;
45713 for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
45716 pCache->nPage--;
45724 static void pcache1EnforceMaxPage(PCache1 *pCache){
45725 PGroup *pGroup = pCache->pGroup;
45731 assert( p->pCache->pGroup==pGroup );
45736 if( pCache->nPage==0 && pCache->pBulk ){
45737 sqlite3_free(pCache->pBulk);
45738 pCache->pBulk = pCache->pFree = 0;
45750 PCache1 *pCache, /* The cache to truncate */
45755 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
45756 assert( pCache->iMaxKey >= iLimit );
45757 assert( pCache->nHash > 0 );
45758 if( pCache->iMaxKey - iLimit < pCache->nHash ){
45763 h = iLimit % pCache->nHash;
45764 iStop = pCache->iMaxKey % pCache->nHash;
45769 h = pCache->nHash/2;
45775 assert( h<pCache->nHash );
45776 pp = &pCache->apHash[h];
45779 pCache->nPage--;
45789 h = (h+1) % pCache->nHash;
45791 assert( nPage<0 || pCache->nPage==(unsigned)nPage );
45868 PCache1 *pCache; /* The newly created page cache */
45876 pCache = (PCache1 *)sqlite3MallocZero(sz);
45877 if( pCache ){
45879 pGroup = (PGroup*)&pCache[1];
45888 pCache->pGroup = pGroup;
45889 pCache->szPage = szPage;
45890 pCache->szExtra = szExtra;
45891 pCache->szAlloc = szPage + szExtra + ROUND8(sizeof(PgHdr1));
45892 pCache->bPurgeable = (bPurgeable ? 1 : 0);
45894 pcache1ResizeHash(pCache);
45896 pCache->nMin = 10;
45897 pGroup->nMinPage += pCache->nMin;
45901 if( pCache->nHash==0 ){
45902 pcache1Destroy((sqlite3_pcache*)pCache);
45903 pCache = 0;
45906 return (sqlite3_pcache *)pCache;
45915 PCache1 *pCache = (PCache1 *)p;
45916 if( pCache->bPurgeable ){
45917 PGroup *pGroup = pCache->pGroup;
45919 pGroup->nMaxPage += (nMax - pCache->nMax);
45921 pCache->nMax = nMax;
45922 pCache->n90pct = pCache->nMax*9/10;
45923 pcache1EnforceMaxPage(pCache);
45934 PCache1 *pCache = (PCache1*)p;
45935 if( pCache->bPurgeable ){
45936 PGroup *pGroup = pCache->pGroup;
45941 pcache1EnforceMaxPage(pCache);
45952 PCache1 *pCache = (PCache1*)p;
45953 pcache1EnterMutex(pCache->pGroup);
45954 n = pCache->nPage;
45955 pcache1LeaveMutex(pCache->pGroup);
45969 PCache1 *pCache,
45974 PGroup *pGroup = pCache->pGroup;
45978 assert( pCache->nPage >= pCache->nRecyclable );
45979 nPinned = pCache->nPage - pCache->nRecyclable;
45981 assert( pCache->n90pct == pCache->nMax*9/10 );
45984 || nPinned>=pCache->n90pct
45985 || (pcache1UnderMemoryPressure(pCache) && pCache->nRecyclable<nPinned)
45990 if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
45991 assert( pCache->nHash>0 && pCache->apHash );
45994 if( pCache->bPurgeable
45996 && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
46003 pOther = pPage->pCache;
46004 if( pOther->szAlloc != pCache->szAlloc ){
46008 pGroup->nCurrentPage -= (pOther->bPurgeable - pCache->bPurgeable);
46016 pPage = pcache1AllocPage(pCache, createFlag==1);
46020 unsigned int h = iKey % pCache->nHash;
46021 pCache->nPage++;
46023 pPage->pNext = pCache->apHash[h];
46024 pPage->pCache = pCache;
46029 pCache->apHash[h] = pPage;
46030 if( iKey>pCache->iMaxKey ){
46031 pCache->iMaxKey = iKey;
46101 PCache1 *pCache = (PCache1 *)p;
46105 pPage = pCache->apHash[iKey % pCache->nHash];
46120 return pcache1FetchStage2(pCache, iKey, createFlag);
46131 PCache1 *pCache = (PCache1 *)p;
46134 pcache1EnterMutex(pCache->pGroup);
46136 assert( pPage==0 || pCache->iMaxKey>=iKey );
46137 pcache1LeaveMutex(pCache->pGroup);
46147 PCache1 *pCache = (PCache1 *)p;
46151 assert( pCache->bPurgeable || createFlag!=1 );
46152 assert( pCache->bPurgeable || pCache->nMin==0 );
46153 assert( pCache->bPurgeable==0 || pCache->nMin==10 );
46154 assert( pCache->nMin==0 || pCache->bPurgeable );
46155 assert( pCache->nHash>0 );
46157 if( pCache->pGroup->mutex ){
46177 PCache1 *pCache = (PCache1 *)p;
46179 PGroup *pGroup = pCache->pGroup;
46181 assert( pPage->pCache==pCache );
46198 pCache->nRecyclable++;
46202 pcache1LeaveMutex(pCache->pGroup);
46214 PCache1 *pCache = (PCache1 *)p;
46219 assert( pPage->pCache==pCache );
46221 pcache1EnterMutex(pCache->pGroup);
46223 h = iOld%pCache->nHash;
46224 pp = &pCache->apHash[h];
46230 h = iNew%pCache->nHash;
46232 pPage->pNext = pCache->apHash[h];
46233 pCache->apHash[h] = pPage;
46234 if( iNew>pCache->iMaxKey ){
46235 pCache->iMaxKey = iNew;
46238 pcache1LeaveMutex(pCache->pGroup);
46249 PCache1 *pCache = (PCache1 *)p;
46250 pcache1EnterMutex(pCache->pGroup);
46251 if( iLimit<=pCache->iMaxKey ){
46252 pcache1TruncateUnsafe(pCache, iLimit);
46253 pCache->iMaxKey = iLimit-1;
46255 pcache1LeaveMutex(pCache->pGroup);
46264 PCache1 *pCache = (PCache1 *)p;
46265 PGroup *pGroup = pCache->pGroup;
46266 assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) );
46268 if( pCache->nPage ) pcache1TruncateUnsafe(pCache, 0);
46269 assert( pGroup->nMaxPage >= pCache->nMax );
46270 pGroup->nMaxPage -= pCache->nMax;
46271 assert( pGroup->nMinPage >= pCache->nMin );
46272 pGroup->nMinPage -= pCache->nMin;
46274 pcache1EnforceMaxPage(pCache);
46276 sqlite3_free(pCache->pBulk);
46277 sqlite3_free(pCache->apHash);
46278 sqlite3_free(pCache);