Lines Matching refs:pCache
13375 PCache *pCache; /* Cache that owns this page */ member
13470 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
44131 sqlite3_pcache *pCache; /* Pluggable cache module */
44147 void pcacheDump(PCache *pCache){
44155 if( pCache->pCache==0 ) return;
44156 N = sqlite3PcachePagecount(pCache);
44159 pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
44167 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
44187 PCache *pCache;
44190 pCache = pPg->pCache;
44191 assert( pCache!=0 ); /* Every page has an associated PCache */
44194 assert( pCache->pDirty!=pPg ); /* CLEAN pages not on dirty list */
44195 assert( pCache->pDirtyTail!=pPg );
44237 PCache *p = pPage->pCache;
44310 if( p->pCache->bPurgeable ){
44311 pcacheTrace(("%p.UNPIN %d\n", p->pCache, p->pgno));
44312 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
44313 pcacheDump(p->pCache);
44398 SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
44399 assert( pCache->nRefSum==0 && pCache->pDirty==0 );
44400 if( pCache->szPage ){
44403 szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
44404 pCache->bPurgeable
44407 sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache));
44408 if( pCache->pCache ){
44409 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
44411 pCache->pCache = pNew;
44412 pCache->szPage = szPage;
44413 pcacheTrace(("%p.PAGESIZE %d\n",pCache,szPage));
44443 PCache *pCache, /* Obtain the page from this cache */
44450 assert( pCache!=0 );
44451 assert( pCache->pCache!=0 );
44453 assert( pCache->eCreate==((pCache->bPurgeable && pCache->pDirty) ? 1 : 2) );
44462 eCreate = createFlag & pCache->eCreate;
44464 assert( createFlag==0 || pCache->eCreate==eCreate );
44465 assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
44466 pRes = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
44467 pcacheTrace(("%p.FETCH %d%s (result: %p)\n",pCache,pgno,
44484 PCache *pCache, /* Obtain the page from this cache */
44489 if( pCache->eCreate==2 ) return 0;
44491 if( sqlite3PcachePagecount(pCache)>pCache->szSpill ){
44501 for(pPg=pCache->pSynced;
44505 pCache->pSynced = pPg;
44507 for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
44515 sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache),
44516 numberOfCachePages(pCache));
44518 pcacheTrace(("%p.SPILL %d\n",pCache,pPg->pgno));
44519 rc = pCache->xStress(pCache->pStress, pPg);
44520 pcacheDump(pCache);
44526 *ppPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, 2);
44540 PCache *pCache, /* Obtain the page from this cache */
44553 pPgHdr->pCache = pCache;
44556 return sqlite3PcacheFetchFinish(pCache,pgno,pPage);
44566 PCache *pCache, /* Obtain the page from this cache */
44576 return pcacheFetchFinishWithInit(pCache, pgno, pPage);
44578 pCache->nRefSum++;
44590 p->pCache->nRefSum--;
44611 p->pCache->nRefSum++;
44625 p->pCache->nRefSum--;
44626 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
44640 pcacheTrace(("%p.DIRTY %d\n",p->pCache,p->pgno));
44659 pcacheTrace(("%p.CLEAN %d\n",p->pCache,p->pgno));
44670 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
44672 pcacheTrace(("%p.CLEAN-ALL\n",pCache));
44673 while( (p = pCache->pDirty)!=0 ){
44681 SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache *pCache){
44683 pcacheTrace(("%p.CLEAR-WRITEABLE\n",pCache));
44684 for(p=pCache->pDirty; p; p=p->pDirtyNext){
44687 pCache->pSynced = pCache->pDirtyTail;
44693 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){
44695 for(p=pCache->pDirty; p; p=p->pDirtyNext){
44698 pCache->pSynced = pCache->pDirtyTail;
44705 PCache *pCache = p->pCache;
44709 pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno));
44710 sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
44726 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
44727 if( pCache->pCache ){
44730 pcacheTrace(("%p.TRUNCATE %d\n",pCache,pgno));
44731 for(p=pCache->pDirty; p; p=pNext){
44743 if( pgno==0 && pCache->nRefSum ){
44745 pPage1 = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache,1,0);
44748 memset(pPage1->pBuf, 0, pCache->szPage);
44752 sqlite3GlobalConfig.pcache2.xTruncate(pCache->pCache, pgno+1);
44759 SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
44760 assert( pCache->pCache!=0 );
44761 pcacheTrace(("%p.CLOSE\n",pCache));
44762 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
44768 SQLITE_PRIVATE void sqlite3PcacheClear(PCache *pCache){
44769 sqlite3PcacheTruncate(pCache, 0);
44848 SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
44850 for(p=pCache->pDirty; p; p=p->pDirtyNext){
44853 return pcacheSortDirtyList(pCache->pDirty);
44862 SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *pCache){
44863 return pCache->nRefSum;
44876 SQLITE_PRIVATE int sqlite3PcachePagecount(PCache *pCache){
44877 assert( pCache->pCache!=0 );
44878 return sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache);
44885 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *pCache){
44886 return numberOfCachePages(pCache);
44893 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){
44894 assert( pCache->pCache!=0 );
44895 pCache->szCache = mxPage;
44896 sqlite3GlobalConfig.pcache2.xCachesize(pCache->pCache,
44897 numberOfCachePages(pCache));
44907 assert( p->pCache!=0 );
44922 SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){
44923 assert( pCache->pCache!=0 );
44924 sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache);
44937 SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache *pCache){
44940 int nCache = numberOfCachePages(pCache);
44941 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext) nDirty++;
44951 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *)){
44953 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext){
45063 PCache1 *pCache; /* Cache that currently owns this page */
45229 static int pcache1InitBulk(PCache1 *pCache){
45234 if( pCache->nMax<3 ) return 0;
45237 szBulk = pCache->szAlloc * (i64)pcache1.nInitPage;
45241 if( szBulk > pCache->szAlloc*(i64)pCache->nMax ){
45242 szBulk = pCache->szAlloc*(i64)pCache->nMax;
45244 zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
45247 int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
45250 PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
45255 pX->pNext = pCache->pFree;
45256 pCache->pFree = pX;
45257 zBulk += pCache->szAlloc;
45260 return pCache->pFree!=0;
45360 static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc){
45364 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
45365 if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){
45366 p = pCache->pFree;
45367 pCache->pFree = p->pNext;
45375 assert( pCache->pGroup==&pcache1.grp );
45376 pcache1LeaveMutex(pCache->pGroup);
45380 pPg = pcache1Alloc(pCache->szPage);
45381 p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
45388 pPg = pcache1Alloc(pCache->szAlloc);
45389 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
45393 pcache1EnterMutex(pCache->pGroup);
45401 if( pCache->bPurgeable ){
45402 pCache->pGroup->nCurrentPage++;
45411 PCache1 *pCache;
45413 pCache = p->pCache;
45414 assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
45416 p->pNext = pCache->pFree;
45417 pCache->pFree = p;
45424 if( pCache->bPurgeable ){
45425 pCache->pGroup->nCurrentPage--;
45462 static int pcache1UnderMemoryPressure(PCache1 *pCache){
45463 if( pcache1.nSlot && (pCache->szPage+pCache->szExtra)<=pcache1.szSlot ){
45521 PCache1 *pCache;
45525 pCache = pPage->pCache;
45528 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
45535 assert( pCache->pGroup->lru.isAnchor==1 );
45536 pCache->nRecyclable--;
45550 PCache1 *pCache = pPage->pCache;
45553 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
45554 h = pPage->iKey % pCache->nHash;
45555 for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
45558 pCache->nPage--;
45566 static void pcache1EnforceMaxPage(PCache1 *pCache){
45567 PGroup *pGroup = pCache->pGroup;
45573 assert( p->pCache->pGroup==pGroup );
45578 if( pCache->nPage==0 && pCache->pBulk ){
45579 sqlite3_free(pCache->pBulk);
45580 pCache->pBulk = pCache->pFree = 0;
45592 PCache1 *pCache, /* The cache to truncate */
45597 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
45598 assert( pCache->iMaxKey >= iLimit );
45599 assert( pCache->nHash > 0 );
45600 if( pCache->iMaxKey - iLimit < pCache->nHash ){
45605 h = iLimit % pCache->nHash;
45606 iStop = pCache->iMaxKey % pCache->nHash;
45611 h = pCache->nHash/2;
45617 assert( h<pCache->nHash );
45618 pp = &pCache->apHash[h];
45621 pCache->nPage--;
45631 h = (h+1) % pCache->nHash;
45633 assert( nPage<0 || pCache->nPage==(unsigned)nPage );
45710 PCache1 *pCache; /* The newly created page cache */
45718 pCache = (PCache1 *)sqlite3MallocZero(sz);
45719 if( pCache ){
45721 pGroup = (PGroup*)&pCache[1];
45730 pCache->pGroup = pGroup;
45731 pCache->szPage = szPage;
45732 pCache->szExtra = szExtra;
45733 pCache->szAlloc = szPage + szExtra + ROUND8(sizeof(PgHdr1));
45734 pCache->bPurgeable = (bPurgeable ? 1 : 0);
45736 pcache1ResizeHash(pCache);
45738 pCache->nMin = 10;
45739 pGroup->nMinPage += pCache->nMin;
45743 if( pCache->nHash==0 ){
45744 pcache1Destroy((sqlite3_pcache*)pCache);
45745 pCache = 0;
45748 return (sqlite3_pcache *)pCache;
45757 PCache1 *pCache = (PCache1 *)p;
45758 if( pCache->bPurgeable ){
45759 PGroup *pGroup = pCache->pGroup;
45761 pGroup->nMaxPage += (nMax - pCache->nMax);
45763 pCache->nMax = nMax;
45764 pCache->n90pct = pCache->nMax*9/10;
45765 pcache1EnforceMaxPage(pCache);
45776 PCache1 *pCache = (PCache1*)p;
45777 if( pCache->bPurgeable ){
45778 PGroup *pGroup = pCache->pGroup;
45783 pcache1EnforceMaxPage(pCache);
45794 PCache1 *pCache = (PCache1*)p;
45795 pcache1EnterMutex(pCache->pGroup);
45796 n = pCache->nPage;
45797 pcache1LeaveMutex(pCache->pGroup);
45811 PCache1 *pCache,
45816 PGroup *pGroup = pCache->pGroup;
45820 assert( pCache->nPage >= pCache->nRecyclable );
45821 nPinned = pCache->nPage - pCache->nRecyclable;
45823 assert( pCache->n90pct == pCache->nMax*9/10 );
45826 || nPinned>=pCache->n90pct
45827 || (pcache1UnderMemoryPressure(pCache) && pCache->nRecyclable<nPinned)
45832 if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
45833 assert( pCache->nHash>0 && pCache->apHash );
45836 if( pCache->bPurgeable
45838 && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
45845 pOther = pPage->pCache;
45846 if( pOther->szAlloc != pCache->szAlloc ){
45850 pGroup->nCurrentPage -= (pOther->bPurgeable - pCache->bPurgeable);
45858 pPage = pcache1AllocPage(pCache, createFlag==1);
45862 unsigned int h = iKey % pCache->nHash;
45863 pCache->nPage++;
45865 pPage->pNext = pCache->apHash[h];
45866 pPage->pCache = pCache;
45871 pCache->apHash[h] = pPage;
45872 if( iKey>pCache->iMaxKey ){
45873 pCache->iMaxKey = iKey;
45943 PCache1 *pCache = (PCache1 *)p;
45947 pPage = pCache->apHash[iKey % pCache->nHash];
45962 return pcache1FetchStage2(pCache, iKey, createFlag);
45973 PCache1 *pCache = (PCache1 *)p;
45976 pcache1EnterMutex(pCache->pGroup);
45978 assert( pPage==0 || pCache->iMaxKey>=iKey );
45979 pcache1LeaveMutex(pCache->pGroup);
45989 PCache1 *pCache = (PCache1 *)p;
45993 assert( pCache->bPurgeable || createFlag!=1 );
45994 assert( pCache->bPurgeable || pCache->nMin==0 );
45995 assert( pCache->bPurgeable==0 || pCache->nMin==10 );
45996 assert( pCache->nMin==0 || pCache->bPurgeable );
45997 assert( pCache->nHash>0 );
45999 if( pCache->pGroup->mutex ){
46019 PCache1 *pCache = (PCache1 *)p;
46021 PGroup *pGroup = pCache->pGroup;
46023 assert( pPage->pCache==pCache );
46040 pCache->nRecyclable++;
46044 pcache1LeaveMutex(pCache->pGroup);
46056 PCache1 *pCache = (PCache1 *)p;
46061 assert( pPage->pCache==pCache );
46063 pcache1EnterMutex(pCache->pGroup);
46065 h = iOld%pCache->nHash;
46066 pp = &pCache->apHash[h];
46072 h = iNew%pCache->nHash;
46074 pPage->pNext = pCache->apHash[h];
46075 pCache->apHash[h] = pPage;
46076 if( iNew>pCache->iMaxKey ){
46077 pCache->iMaxKey = iNew;
46080 pcache1LeaveMutex(pCache->pGroup);
46091 PCache1 *pCache = (PCache1 *)p;
46092 pcache1EnterMutex(pCache->pGroup);
46093 if( iLimit<=pCache->iMaxKey ){
46094 pcache1TruncateUnsafe(pCache, iLimit);
46095 pCache->iMaxKey = iLimit-1;
46097 pcache1LeaveMutex(pCache->pGroup);
46106 PCache1 *pCache = (PCache1 *)p;
46107 PGroup *pGroup = pCache->pGroup;
46108 assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) );
46110 if( pCache->nPage ) pcache1TruncateUnsafe(pCache, 0);
46111 assert( pGroup->nMaxPage >= pCache->nMax );
46112 pGroup->nMaxPage -= pCache->nMax;
46113 assert( pGroup->nMinPage >= pCache->nMin );
46114 pGroup->nMinPage -= pCache->nMin;
46116 pcache1EnforceMaxPage(pCache);
46118 sqlite3_free(pCache->pBulk);
46119 sqlite3_free(pCache->apHash);
46120 sqlite3_free(pCache);