Home | History | Annotate | Download | only in orig

Lines Matching defs:pCache

9038 /************** Include pcache.h in the middle of sqliteInt.h ****************/
9039 /************** Begin file pcache.h ******************************************/
9058 typedef struct PCache PCache;
9065 sqlite3_pcache_page *pPage; /* Pcache object page handle */
9077 ** Elements above are public. All that follows is private to pcache.c
9081 PCache *pCache; /* Cache that owns this page */
9114 PCache *pToInit /* Preallocated space for the PCache */
9118 SQLITE_PRIVATE void sqlite3PcacheSetPageSize(PCache *, int);
9120 /* Return the size in bytes of a PCache object. Used to preallocate
9128 SQLITE_PRIVATE int sqlite3PcacheFetch(PCache*, Pgno, int createFlag, PgHdr**);
9134 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache*); /* Mark all dirty list pages as clean */
9140 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache*, Pgno x);
9143 SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache*);
9146 SQLITE_PRIVATE void sqlite3PcacheClose(PCache*);
9149 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *);
9152 SQLITE_PRIVATE void sqlite3PcacheClear(PCache*);
9155 SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache*);
9163 SQLITE_PRIVATE int sqlite3PcachePagecount(PCache*);
9170 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
9179 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *, int);
9181 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *);
9185 SQLITE_PRIVATE void sqlite3PcacheShrink(PCache*);
9188 /* Try to return memory used by the pcache module to the main memory heap */
9200 /************** End of pcache.h **********************************************/
36223 /************** Begin file pcache.c ******************************************/
36241 struct PCache {
36251 sqlite3_pcache *pCache; /* Pluggable cache module */
36271 ** Check that the pCache->pSynced variable is set correctly. If it
36275 ** expensive_assert( pcacheCheckSynced(pCache) );
36277 static int pcacheCheckSynced(PCache *pCache){
36279 for(p=pCache->pDirtyTail; p!=pCache->pSynced; p=p->pDirtyPrev){
36290 PCache *p = pPage->pCache;
36327 PCache *p = pPage->pCache;
36351 PCache *pCache = p->pCache;
36352 if( pCache->bPurgeable ){
36354 pCache->pPage1 = 0;
36356 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, p->pPage, 0);
36382 ** Return the size in bytes of a PCache object.
36384 SQLITE_PRIVATE int sqlite3PcacheSize(void){ return sizeof(PCache); }
36387 ** Create a new PCache object. Storage space to hold the object
36398 PCache *p /* Preallocated space for the PCache */
36400 memset(p, 0, sizeof(PCache));
36410 ** Change the page size for PCache object. The caller must ensure that there
36413 SQLITE_PRIVATE void sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
36414 assert( pCache->nRef==0 && pCache->pDirty==0 );
36415 if( pCache->pCache ){
36416 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
36417 pCache->pCache = 0;
36418 pCache->pPage1 = 0;
36420 pCache->szPage = szPage;
36426 static int numberOfCachePages(PCache *p){
36438 PCache *pCache, /* Obtain the page from this cache */
36447 assert( pCache!=0 );
36454 if( !pCache->pCache && createFlag ){
36457 pCache->szPage, pCache->szExtra + sizeof(PgHdr), pCache->bPurgeable
36462 sqlite3GlobalConfig.pcache2.xCachesize(p, numberOfCachePages(pCache));
36463 pCache->pCache = p;
36466 eCreate = createFlag * (1 + (!pCache->bPurgeable || !pCache->pDirty));
36467 if( pCache->pCache ){
36468 pPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
36479 expensive_assert( pcacheCheckSynced(pCache) );
36480 for(pPg=pCache->pSynced;
36484 pCache->pSynced = pPg;
36486 for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
36494 sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache),
36495 numberOfCachePages(pCache));
36497 rc = pCache->xStress(pCache->pStress, pPg);
36503 pPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, 2);
36514 memset(pPgHdr->pExtra, 0, pCache->szExtra);
36515 pPgHdr->pCache = pCache;
36518 assert( pPgHdr->pCache==pCache );
36524 pCache->nRef++;
36528 pCache->pPage1 = pPgHdr;
36543 PCache *pCache = p->pCache;
36544 pCache->nRef--;
36569 PCache *pCache;
36574 pCache = p->pCache;
36575 pCache->nRef--;
36577 pCache->pPage1 = 0;
36579 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, p->pPage, 1);
36612 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
36614 while( (p = pCache->pDirty)!=0 ){
36622 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){
36624 for(p=pCache->pDirty; p; p=p->pDirtyNext){
36627 pCache->pSynced = pCache->pDirtyTail;
36634 PCache *pCache = p->pCache;
36637 sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
36654 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
36655 if( pCache->pCache ){
36658 for(p=pCache->pDirty; p; p=pNext){
36670 if( pgno==0 && pCache->pPage1 ){
36671 memset(pCache->pPage1->pData, 0, pCache->szPage);
36674 sqlite3GlobalConfig.pcache2.xTruncate(pCache->pCache, pgno+1);
36681 SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
36682 if( pCache->pCache ){
36683 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
36690 SQLITE_PRIVATE void sqlite3PcacheClear(PCache *pCache){
36691 sqlite3PcacheTruncate(pCache, 0);
36767 SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
36769 for(p=pCache->pDirty; p; p=p->pDirtyNext){
36772 return pcacheSortDirtyList(pCache->pDirty);
36778 SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *pCache){
36779 return pCache->nRef;
36792 SQLITE_PRIVATE int sqlite3PcachePagecount(PCache *pCache){
36794 if( pCache->pCache ){
36795 nPage = sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache);
36804 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *pCache){
36805 return numberOfCachePages(pCache);
36812 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){
36813 pCache->szCache = mxPage;
36814 if( pCache->pCache ){
36815 sqlite3GlobalConfig.pcache2.xCachesize(pCache->pCache,
36816 numberOfCachePages(pCache));
36823 SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){
36824 if( pCache->pCache ){
36825 sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache);
36835 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *)){
36837 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext){
36843 /************** End of pcache.c **********************************************/
36870 /* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
36877 ** (1) Every PCache is the sole member of its own PGroup. There is
36878 ** one PGroup per PCache.
36883 ** Mode 1 uses more memory (since PCache instances are not able to rob
36936 ** PgHdr1.pCache->szPage bytes is allocated directly before this structure
36943 PCache1 *pCache; /* Cache that currently owns this page */
36969 int nSlot; /* The number of pcache slots */
36975 int nFreeSlot; /* Number of unused pcache slots */
36991 ** Macros to enter and leave the PCache LRU mutex.
37100 ** Return the size of a pcache allocation
37117 ** Allocate a new page object initially associated with cache pCache.
37119 static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
37126 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
37127 pcache1LeaveMutex(pCache->pGroup);
37129 pPg = pcache1Alloc(pCache->szPage);
37130 p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
37137 pPg = pcache1Alloc(sizeof(PgHdr1) + pCache->szPage + pCache->szExtra);
37138 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
37140 pcache1EnterMutex(pCache->pGroup);
37145 if( pCache->bPurgeable ){
37146 pCache->pGroup->nCurrentPage++;
37162 PCache1 *pCache = p->pCache;
37163 assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
37168 if( pCache->bPurgeable ){
37169 pCache->pGroup->nCurrentPage--;
37207 static int pcache1UnderMemoryPressure(PCache1 *pCache){
37208 if( pcache1.nSlot && (pCache->szPage+pCache->szExtra)<=pcache1.szSlot ){
37222 ** The PCache mutex must be held when this function is called.
37271 PCache1 *pCache;
37275 pCache = pPage->pCache;
37276 pGroup = pCache->pGroup;
37293 pPage->pCache->nRecyclable--;
37306 PCache1 *pCache = pPage->pCache;
37309 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
37310 h = pPage->iKey % pCache->nHash;
37311 for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
37314 pCache->nPage--;
37325 assert( p->pCache->pGroup==pGroup );
37333 ** Discard all pages from cache pCache with a page number (key value)
37337 ** The PCache mutex must be held when this function is called.
37340 PCache1 *pCache, /* The cache to truncate */
37343 TESTONLY( unsigned int nPage = 0; ) /* To assert pCache->nPage is correct */
37345 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
37346 for(h=0; h<pCache->nHash; h++){
37347 PgHdr1 **pp = &pCache->apHash[h];
37351 pCache->nPage--;
37361 assert( pCache->nPage==nPage );
37400 PCache1 *pCache; /* The newly created page cache */
37405 ** The seperateCache variable is true if each PCache has its own private
37426 pCache = (PCache1 *)sqlite3_malloc(sz);
37427 if( pCache ){
37428 memset(pCache, 0, sz);
37430 pGroup = (PGroup*)&pCache[1];
37435 pCache->pGroup = pGroup;
37436 pCache->szPage = szPage;
37437 pCache->szExtra = szExtra;
37438 pCache->bPurgeable = (bPurgeable ? 1 : 0);
37440 pCache->nMin = 10;
37442 pGroup->nMinPage += pCache->nMin;
37447 return (sqlite3_pcache *)pCache;
37456 PCache1 *pCache = (PCache1 *)p;
37457 if( pCache->bPurgeable ){
37458 PGroup *pGroup = pCache->pGroup;
37460 pGroup->nMaxPage += (nMax - pCache->nMax);
37462 pCache->nMax = nMax;
37463 pCache->n90pct = pCache->nMax*9/10;
37475 PCache1 *pCache = (PCache1*)p;
37476 if( pCache->bPurgeable ){
37477 PGroup *pGroup = pCache->pGroup;
37493 PCache1 *pCache = (PCache1*)p;
37494 pcache1EnterMutex(pCache->pGroup);
37495 n = pCache->nPage;
37496 pcache1LeaveMutex(pCache->pGroup);
37512 ** the calling function (pcache.c) will never have a createFlag of 1 on
37560 PCache1 *pCache = (PCache1 *)p;
37564 assert( pCache->bPurgeable || createFlag!=1 );
37565 assert( pCache->bPurgeable || pCache->nMin==0 );
37566 assert( pCache->bPurgeable==0 || pCache->nMin==10 );
37567 assert( pCache->nMin==0 || pCache->bPurgeable );
37568 pcache1EnterMutex(pGroup = pCache->pGroup);
37571 if( pCache->nHash>0 ){
37572 unsigned int h = iKey % pCache->nHash;
37573 for(pPage=pCache->apHash[h]; pPage&&pPage->iKey!=iKey; pPage=pPage->pNext);
37590 pGroup = pCache->pGroup;
37594 assert( pCache->nPage >= pCache->nRecyclable );
37595 nPinned = pCache->nPage - pCache->nRecyclable;
37597 assert( pCache->n90pct == pCache->nMax*9/10 );
37600 || nPinned>=pCache->n90pct
37601 || pcache1UnderMemoryPressure(pCache)
37606 if( pCache->nPage>=pCache->nHash && pcache1ResizeHash(pCache) ){
37611 if( pCache->bPurgeable && pGroup->pLruTail && (
37612 (pCache->nPage+1>=pCache->nMax)
37614 || pcache1UnderMemoryPressure(pCache)
37620 pOther = pPage->pCache;
37623 ** and pCache. Assert that we can verify this by comparing sums. */
37624 assert( (pCache->szPage & (pCache->szPage-1))==0 && pCache->szPage>=512 );
37625 assert( pCache->szExtra<512 );
37629 if( pOther->szPage+pOther->szExtra != pCache->szPage+pCache->szExtra ){
37633 pGroup->nCurrentPage -= (pOther->bPurgeable - pCache->bPurgeable);
37642 pPage = pcache1AllocPage(pCache);
37647 unsigned int h = iKey % pCache->nHash;
37648 pCache->nPage++;
37650 pPage->pNext = pCache->apHash[h];
37651 pPage->pCache = pCache;
37655 pCache->apHash[h] = pPage;
37659 if( pPage && iKey>pCache->iMaxKey ){
37660 pCache->iMaxKey = iKey;
37677 PCache1 *pCache = (PCache1 *)p;
37679 PGroup *pGroup = pCache->pGroup;
37681 assert( pPage->pCache==pCache );
37703 pCache->nRecyclable++;
37706 pcache1LeaveMutex(pCache->pGroup);
37718 PCache1 *pCache = (PCache1 *)p;
37723 assert( pPage->pCache==pCache );
37725 pcache1EnterMutex(pCache->pGroup);
37727 h = iOld%pCache->nHash;
37728 pp = &pCache->apHash[h];
37734 h = iNew%pCache->nHash;
37736 pPage->pNext = pCache->apHash[h];
37737 pCache->apHash[h] = pPage;
37738 if( iNew>pCache->iMaxKey ){
37739 pCache->iMaxKey = iNew;
37742 pcache1LeaveMutex(pCache->pGroup);
37753 PCache1 *pCache = (PCache1 *)p;
37754 pcache1EnterMutex(pCache->pGroup);
37755 if( iLimit<=pCache->iMaxKey ){
37756 pcache1TruncateUnsafe(pCache, iLimit);
37757 pCache->iMaxKey = iLimit-1;
37759 pcache1LeaveMutex(pCache->pGroup);
37768 PCache1 *pCache = (PCache1 *)p;
37769 PGroup *pGroup = pCache->pGroup;
37770 assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) );
37772 pcache1TruncateUnsafe(pCache, 0);
37773 assert( pGroup->nMaxPage >= pCache->nMax );
37774 pGroup->nMaxPage -= pCache->nMax;
37775 assert( pGroup->nMinPage >= pCache->nMin );
37776 pGroup->nMinPage -= pCache->nMin;
37780 sqlite3_free(pCache->apHash);
37781 sqlite3_free(pCache);
38951 ** (calls made by the pcache module to the pagerStress() routine to
38956 ** comes up during savepoint rollback that requires the pcache module
39111 PCache *pPCache; /* Pointer to page cache object */
42583 ** This function is called by the pcache layer when it has reached some
42746 int pcacheSize = sqlite3PcacheSize(); /* Bytes to allocate for PCache */
42811 /* Allocate memory for the Pager structure, PCache object, the
42816 ** PCache object (sqlite3PcacheSize() bytes)
42825 ROUND8(pcacheSize) + /* PCache object */
42840 pPager->pPCache = (PCache*)(pPtr += ROUND8(sizeof(*pPager)));
42942 /* Initialize the PCache object. */
43377 ** read from the database file. In some cases, the pcache module may
43437 ** Otherwise, request the page from the PCache layer. */
43455 /* In this case the pcache already contains an initialized copy of
112616 ** The following mutex is what serializes access to the appdef pcache xInit