Lines Matching refs:pCache
16020 PCache *pCache; /* PRIVATE: Cache that owns this page */ member
16130 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
16178 SQLITE_PRIVATE int sqlite3PCacheIsDirty(PCache *pCache);
48832 sqlite3_pcache *pCache; /* Pluggable cache module */
48848 void pcacheDump(PCache *pCache){
48856 if( pCache->pCache==0 ) return;
48857 N = sqlite3PcachePagecount(pCache);
48860 pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
48868 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
48888 PCache *pCache;
48891 pCache = pPg->pCache;
48892 assert( pCache!=0 ); /* Every page has an associated PCache */
48895 assert( pCache->pDirty!=pPg ); /* CLEAN pages not on dirty list */
48896 assert( pCache->pDirtyTail!=pPg );
48938 PCache *p = pPage->pCache;
49008 if( p->pCache->bPurgeable ){
49009 pcacheTrace(("%p.UNPIN %d\n", p->pCache, p->pgno));
49010 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
49011 pcacheDump(p->pCache);
49098 SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
49099 assert( pCache->nRefSum==0 && pCache->pDirty==0 );
49100 if( pCache->szPage ){
49103 szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
49104 pCache->bPurgeable
49107 sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache));
49108 if( pCache->pCache ){
49109 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
49111 pCache->pCache = pNew;
49112 pCache->szPage = szPage;
49113 pcacheTrace(("%p.PAGESIZE %d\n",pCache,szPage));
49143 PCache *pCache, /* Obtain the page from this cache */
49150 assert( pCache!=0 );
49151 assert( pCache->pCache!=0 );
49153 assert( pCache->eCreate==((pCache->bPurgeable && pCache->pDirty) ? 1 : 2) );
49162 eCreate = createFlag & pCache->eCreate;
49164 assert( createFlag==0 || pCache->eCreate==eCreate );
49165 assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
49166 pRes = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
49167 pcacheTrace(("%p.FETCH %d%s (result: %p)\n",pCache,pgno,
49184 PCache *pCache, /* Obtain the page from this cache */
49189 if( pCache->eCreate==2 ) return 0;
49191 if( sqlite3PcachePagecount(pCache)>pCache->szSpill ){
49201 for(pPg=pCache->pSynced;
49205 pCache->pSynced = pPg;
49207 for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
49215 sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache),
49216 numberOfCachePages(pCache));
49218 pcacheTrace(("%p.SPILL %d\n",pCache,pPg->pgno));
49219 rc = pCache->xStress(pCache->pStress, pPg);
49220 pcacheDump(pCache);
49226 *ppPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, 2);
49240 PCache *pCache, /* Obtain the page from this cache */
49253 pPgHdr->pCache = pCache;
49256 return sqlite3PcacheFetchFinish(pCache,pgno,pPage);
49266 PCache *pCache, /* Obtain the page from this cache */
49276 return pcacheFetchFinishWithInit(pCache, pgno, pPage);
49278 pCache->nRefSum++;
49290 p->pCache->nRefSum--;
49307 p->pCache->nRefSum++;
49321 p->pCache->nRefSum--;
49322 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
49336 pcacheTrace(("%p.DIRTY %d\n",p->pCache,p->pgno));
49355 pcacheTrace(("%p.CLEAN %d\n",p->pCache,p->pgno));
49365 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
49367 pcacheTrace(("%p.CLEAN-ALL\n",pCache));
49368 while( (p = pCache->pDirty)!=0 ){
49376 SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache *pCache){
49378 pcacheTrace(("%p.CLEAR-WRITEABLE\n",pCache));
49379 for(p=pCache->pDirty; p; p=p->pDirtyNext){
49382 pCache->pSynced = pCache->pDirtyTail;
49388 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){
49390 for(p=pCache->pDirty; p; p=p->pDirtyNext){
49393 pCache->pSynced = pCache->pDirtyTail;
49400 PCache *pCache = p->pCache;
49404 pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno));
49405 sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
49421 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
49422 if( pCache->pCache ){
49425 pcacheTrace(("%p.TRUNCATE %d\n",pCache,pgno));
49426 for(p=pCache->pDirty; p; p=pNext){
49438 if( pgno==0 && pCache->nRefSum ){
49440 pPage1 = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache,1,0);
49443 memset(pPage1->pBuf, 0, pCache->szPage);
49447 sqlite3GlobalConfig.pcache2.xTruncate(pCache->pCache, pgno+1);
49454 SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
49455 assert( pCache->pCache!=0 );
49456 pcacheTrace(("%p.CLOSE\n",pCache));
49457 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
49463 SQLITE_PRIVATE void sqlite3PcacheClear(PCache *pCache){
49464 sqlite3PcacheTruncate(pCache, 0);
49543 SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
49545 for(p=pCache->pDirty; p; p=p->pDirtyNext){
49548 return pcacheSortDirtyList(pCache->pDirty);
49557 SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *pCache){
49558 return pCache->nRefSum;
49571 SQLITE_PRIVATE int sqlite3PcachePagecount(PCache *pCache){
49572 assert( pCache->pCache!=0 );
49573 return sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache);
49580 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *pCache){
49581 return numberOfCachePages(pCache);
49588 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){
49589 assert( pCache->pCache!=0 );
49590 pCache->szCache = mxPage;
49591 sqlite3GlobalConfig.pcache2.xCachesize(pCache->pCache,
49592 numberOfCachePages(pCache));
49602 assert( p->pCache!=0 );
49617 SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){
49618 assert( pCache->pCache!=0 );
49619 sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache);
49632 SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache *pCache){
49635 int nCache = numberOfCachePages(pCache);
49636 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext) nDirty++;
49644 SQLITE_PRIVATE int sqlite3PCacheIsDirty(PCache *pCache){
49645 return (pCache->pDirty!=0);
49655 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *)){
49657 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext){
49776 PCache1 *pCache; /* Cache that currently owns this page */
49954 static int pcache1InitBulk(PCache1 *pCache){
49959 if( pCache->nMax<3 ) return 0;
49962 szBulk = pCache->szAlloc * (i64)pcache1.nInitPage;
49966 if( szBulk > pCache->szAlloc*(i64)pCache->nMax ){
49967 szBulk = pCache->szAlloc*(i64)pCache->nMax;
49969 zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
49972 int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
49974 PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
49979 pX->pNext = pCache->pFree;
49981 pCache->pFree = pX;
49982 zBulk += pCache->szAlloc;
49985 return pCache->pFree!=0;
50085 static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc){
50089 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
50090 if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){
50091 assert( pCache->pFree!=0 );
50092 p = pCache->pFree;
50093 pCache->pFree = p->pNext;
50101 assert( pCache->pGroup==&pcache1.grp );
50102 pcache1LeaveMutex(pCache->pGroup);
50106 pPg = pcache1Alloc(pCache->szPage);
50107 p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
50114 pPg = pcache1Alloc(pCache->szAlloc);
50118 pcache1EnterMutex(pCache->pGroup);
50122 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
50129 (*pCache->pnPurgeable)++;
50137 PCache1 *pCache;
50139 pCache = p->pCache;
50140 assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
50142 p->pNext = pCache->pFree;
50143 pCache->pFree = p;
50150 (*pCache->pnPurgeable)--;
50187 static int pcache1UnderMemoryPressure(PCache1 *pCache){
50188 if( pcache1.nSlot && (pCache->szPage+pCache->szExtra)<=pcache1.szSlot ){
50250 assert( sqlite3_mutex_held(pPage->pCache->pGroup->mutex) );
50257 assert( pPage->pCache->pGroup->lru.isAnchor==1 );
50258 pPage->pCache->nRecyclable--;
50272 PCache1 *pCache = pPage->pCache;
50275 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
50276 h = pPage->iKey % pCache->nHash;
50277 for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
50280 pCache->nPage--;
50288 static void pcache1EnforceMaxPage(PCache1 *pCache){
50289 PGroup *pGroup = pCache->pGroup;
50295 assert( p->pCache->pGroup==pGroup );
50300 if( pCache->nPage==0 && pCache->pBulk ){
50301 sqlite3_free(pCache->pBulk);
50302 pCache->pBulk = pCache->pFree = 0;
50314 PCache1 *pCache, /* The cache to truncate */
50319 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
50320 assert( pCache->iMaxKey >= iLimit );
50321 assert( pCache->nHash > 0 );
50322 if( pCache->iMaxKey - iLimit < pCache->nHash ){
50327 h = iLimit % pCache->nHash;
50328 iStop = pCache->iMaxKey % pCache->nHash;
50333 h = pCache->nHash/2;
50339 assert( h<pCache->nHash );
50340 pp = &pCache->apHash[h];
50343 pCache->nPage--;
50353 h = (h+1) % pCache->nHash;
50355 assert( nPage<0 || pCache->nPage==(unsigned)nPage );
50432 PCache1 *pCache; /* The newly created page cache */
50440 pCache = (PCache1 *)sqlite3MallocZero(sz);
50441 if( pCache ){
50443 pGroup = (PGroup*)&pCache[1];
50453 pCache->pGroup = pGroup;
50454 pCache->szPage = szPage;
50455 pCache->szExtra = szExtra;
50456 pCache->szAlloc = szPage + szExtra + ROUND8(sizeof(PgHdr1));
50457 pCache->bPurgeable = (bPurgeable ? 1 : 0);
50458 pcache1ResizeHash(pCache);
50460 pCache->nMin = 10;
50461 pGroup->nMinPage += pCache->nMin;
50463 pCache->pnPurgeable = &pGroup->nPurgeable;
50465 pCache->pnPurgeable = &pCache->nPurgeableDummy;
50468 if( pCache->nHash==0 ){
50469 pcache1Destroy((sqlite3_pcache*)pCache);
50470 pCache = 0;
50473 return (sqlite3_pcache *)pCache;
50482 PCache1 *pCache = (PCache1 *)p;
50483 if( pCache->bPurgeable ){
50484 PGroup *pGroup = pCache->pGroup;
50486 pGroup->nMaxPage += (nMax - pCache->nMax);
50488 pCache->nMax = nMax;
50489 pCache->n90pct = pCache->nMax*9/10;
50490 pcache1EnforceMaxPage(pCache);
50501 PCache1 *pCache = (PCache1*)p;
50502 if( pCache->bPurgeable ){
50503 PGroup *pGroup = pCache->pGroup;
50508 pcache1EnforceMaxPage(pCache);
50519 PCache1 *pCache = (PCache1*)p;
50520 pcache1EnterMutex(pCache->pGroup);
50521 n = pCache->nPage;
50522 pcache1LeaveMutex(pCache->pGroup);
50536 PCache1 *pCache,
50541 PGroup *pGroup = pCache->pGroup;
50545 assert( pCache->nPage >= pCache->nRecyclable );
50546 nPinned = pCache->nPage - pCache->nRecyclable;
50548 assert( pCache->n90pct == pCache->nMax*9/10 );
50551 || nPinned>=pCache->n90pct
50552 || (pcache1UnderMemoryPressure(pCache) && pCache->nRecyclable<nPinned)
50557 if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
50558 assert( pCache->nHash>0 && pCache->apHash );
50561 if( pCache->bPurgeable
50563 && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
50570 pOther = pPage->pCache;
50571 if( pOther->szAlloc != pCache->szAlloc ){
50575 pGroup->nPurgeable -= (pOther->bPurgeable - pCache->bPurgeable);
50583 pPage = pcache1AllocPage(pCache, createFlag==1);
50587 unsigned int h = iKey % pCache->nHash;
50588 pCache->nPage++;
50590 pPage->pNext = pCache->apHash[h];
50591 pPage->pCache = pCache;
50596 pCache->apHash[h] = pPage;
50597 if( iKey>pCache->iMaxKey ){
50598 pCache->iMaxKey = iKey;
50668 PCache1 *pCache = (PCache1 *)p;
50672 pPage = pCache->apHash[iKey % pCache->nHash];
50687 return pcache1FetchStage2(pCache, iKey, createFlag);
50698 PCache1 *pCache = (PCache1 *)p;
50701 pcache1EnterMutex(pCache->pGroup);
50703 assert( pPage==0 || pCache->iMaxKey>=iKey );
50704 pcache1LeaveMutex(pCache->pGroup);
50714 PCache1 *pCache = (PCache1 *)p;
50718 assert( pCache->bPurgeable || createFlag!=1 );
50719 assert( pCache->bPurgeable || pCache->nMin==0 );
50720 assert( pCache->bPurgeable==0 || pCache->nMin==10 );
50721 assert( pCache->nMin==0 || pCache->bPurgeable );
50722 assert( pCache->nHash>0 );
50724 if( pCache->pGroup->mutex ){
50744 PCache1 *pCache = (PCache1 *)p;
50746 PGroup *pGroup = pCache->pGroup;
50748 assert( pPage->pCache==pCache );
50765 pCache->nRecyclable++;
50768 pcache1LeaveMutex(pCache->pGroup);
50780 PCache1 *pCache = (PCache1 *)p;
50785 assert( pPage->pCache==pCache );
50787 pcache1EnterMutex(pCache->pGroup);
50789 h = iOld%pCache->nHash;
50790 pp = &pCache->apHash[h];
50796 h = iNew%pCache->nHash;
50798 pPage->pNext = pCache->apHash[h];
50799 pCache->apHash[h] = pPage;
50800 if( iNew>pCache->iMaxKey ){
50801 pCache->iMaxKey = iNew;
50804 pcache1LeaveMutex(pCache->pGroup);
50815 PCache1 *pCache = (PCache1 *)p;
50816 pcache1EnterMutex(pCache->pGroup);
50817 if( iLimit<=pCache->iMaxKey ){
50818 pcache1TruncateUnsafe(pCache, iLimit);
50819 pCache->iMaxKey = iLimit-1;
50821 pcache1LeaveMutex(pCache->pGroup);
50830 PCache1 *pCache = (PCache1 *)p;
50831 PGroup *pGroup = pCache->pGroup;
50832 assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) );
50834 if( pCache->nPage ) pcache1TruncateUnsafe(pCache, 0);
50835 assert( pGroup->nMaxPage >= pCache->nMax );
50836 pGroup->nMaxPage -= pCache->nMax;
50837 assert( pGroup->nMinPage >= pCache->nMin );
50838 pGroup->nMinPage -= pCache->nMin;
50840 pcache1EnforceMaxPage(pCache);
50842 sqlite3_free(pCache->pBulk);
50843 sqlite3_free(pCache->apHash);
50844 sqlite3_free(pCache);