Home | History | Annotate | Download | only in dist

Lines Matching refs: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 **********************************************/
36251 /************** Begin file pcache.c ******************************************/
36269 struct PCache {
36279 sqlite3_pcache *pCache; /* Pluggable cache module */
36299 ** Check that the pCache->pSynced variable is set correctly. If it
36303 ** expensive_assert( pcacheCheckSynced(pCache) );
36305 static int pcacheCheckSynced(PCache *pCache){
36307 for(p=pCache->pDirtyTail; p!=pCache->pSynced; p=p->pDirtyPrev){
36318 PCache *p = pPage->pCache;
36355 PCache *p = pPage->pCache;
36379 PCache *pCache = p->pCache;
36380 if( pCache->bPurgeable ){
36382 pCache->pPage1 = 0;
36384 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, p->pPage, 0);
36410 ** Return the size in bytes of a PCache object.
36412 SQLITE_PRIVATE int sqlite3PcacheSize(void){ return sizeof(PCache); }
36415 ** Create a new PCache object. Storage space to hold the object
36426 PCache *p /* Preallocated space for the PCache */
36428 memset(p, 0, sizeof(PCache));
36438 ** Change the page size for PCache object. The caller must ensure that there
36441 SQLITE_PRIVATE void sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
36442 assert( pCache->nRef==0 && pCache->pDirty==0 );
36443 if( pCache->pCache ){
36444 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
36445 pCache->pCache = 0;
36446 pCache->pPage1 = 0;
36448 pCache->szPage = szPage;
36454 static int numberOfCachePages(PCache *p){
36466 PCache *pCache, /* Obtain the page from this cache */
36475 assert( pCache!=0 );
36482 if( !pCache->pCache && createFlag ){
36485 pCache->szPage, pCache->szExtra + sizeof(PgHdr), pCache->bPurgeable
36490 sqlite3GlobalConfig.pcache2.xCachesize(p, numberOfCachePages(pCache));
36491 pCache->pCache = p;
36494 eCreate = createFlag * (1 + (!pCache->bPurgeable || !pCache->pDirty));
36495 if( pCache->pCache ){
36496 pPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
36507 expensive_assert( pcacheCheckSynced(pCache) );
36508 for(pPg=pCache->pSynced;
36512 pCache->pSynced = pPg;
36514 for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
36522 sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache),
36523 numberOfCachePages(pCache));
36525 rc = pCache->xStress(pCache->pStress, pPg);
36531 pPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, 2);
36542 memset(pPgHdr->pExtra, 0, pCache->szExtra);
36543 pPgHdr->pCache = pCache;
36546 assert( pPgHdr->pCache==pCache );
36552 pCache->nRef++;
36556 pCache->pPage1 = pPgHdr;
36571 PCache *pCache = p->pCache;
36572 pCache->nRef--;
36597 PCache *pCache;
36602 pCache = p->pCache;
36603 pCache->nRef--;
36605 pCache->pPage1 = 0;
36607 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, p->pPage, 1);
36640 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
36642 while( (p = pCache->pDirty)!=0 ){
36650 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){
36652 for(p=pCache->pDirty; p; p=p->pDirtyNext){
36655 pCache->pSynced = pCache->pDirtyTail;
36662 PCache *pCache = p->pCache;
36665 sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
36682 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
36683 if( pCache->pCache ){
36686 for(p=pCache->pDirty; p; p=pNext){
36698 if( pgno==0 && pCache->pPage1 ){
36699 memset(pCache->pPage1->pData, 0, pCache->szPage);
36702 sqlite3GlobalConfig.pcache2.xTruncate(pCache->pCache, pgno+1);
36709 SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
36710 if( pCache->pCache ){
36711 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
36718 SQLITE_PRIVATE void sqlite3PcacheClear(PCache *pCache){
36719 sqlite3PcacheTruncate(pCache, 0);
36795 SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
36797 for(p=pCache->pDirty; p; p=p->pDirtyNext){
36800 return pcacheSortDirtyList(pCache->pDirty);
36806 SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *pCache){
36807 return pCache->nRef;
36820 SQLITE_PRIVATE int sqlite3PcachePagecount(PCache *pCache){
36822 if( pCache->pCache ){
36823 nPage = sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache);
36832 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *pCache){
36833 return numberOfCachePages(pCache);
36840 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){
36841 pCache->szCache = mxPage;
36842 if( pCache->pCache ){
36843 sqlite3GlobalConfig.pcache2.xCachesize(pCache->pCache,
36844 numberOfCachePages(pCache));
36851 SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){
36852 if( pCache->pCache ){
36853 sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache);
36863 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *)){
36865 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext){
36871 /************** End of pcache.c **********************************************/
36898 /* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
36905 ** (1) Every PCache is the sole member of its own PGroup. There is
36906 ** one PGroup per PCache.
36911 ** Mode 1 uses more memory (since PCache instances are not able to rob
36964 ** PgHdr1.pCache->szPage bytes is allocated directly before this structure
36971 PCache1 *pCache; /* Cache that currently owns this page */
36997 int nSlot; /* The number of pcache slots */
37003 int nFreeSlot; /* Number of unused pcache slots */
37019 ** Macros to enter and leave the PCache LRU mutex.
37128 ** Return the size of a pcache allocation
37145 ** Allocate a new page object initially associated with cache pCache.
37147 static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
37154 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
37155 pcache1LeaveMutex(pCache->pGroup);
37157 pPg = pcache1Alloc(pCache->szPage);
37158 p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
37165 pPg = pcache1Alloc(sizeof(PgHdr1) + pCache->szPage + pCache->szExtra);
37166 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
37168 pcache1EnterMutex(pCache->pGroup);
37173 if( pCache->bPurgeable ){
37174 pCache->pGroup->nCurrentPage++;
37190 PCache1 *pCache = p->pCache;
37191 assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
37196 if( pCache->bPurgeable ){
37197 pCache->pGroup->nCurrentPage--;
37235 pCache){
37236 if( pcache1.nSlot && (pCache->szPage+pCache->szExtra)<=pcache1.szSlot ){
37250 ** The PCache mutex must be held when this function is called.
37299 PCache1 *pCache;
37303 pCache = pPage->pCache;
37304 pGroup = pCache->pGroup;
37321 pPage->pCache->nRecyclable--;
37334 PCache1 *pCache = pPage->pCache;
37337 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
37338 h = pPage->iKey % pCache->nHash;
37339 for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
37342 pCache->nPage--;
37353 assert( p->pCache->pGroup==pGroup );
37361 ** Discard all pages from cache pCache with a page number (key value)
37365 ** The PCache mutex must be held when this function is called.
37368 PCache1 *pCache, /* The cache to truncate */
37371 TESTONLY( unsigned int nPage = 0; ) /* To assert pCache->nPage is correct */
37373 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
37374 for(h=0; h<pCache->nHash; h++){
37375 PgHdr1 **pp = &pCache->apHash[h];
37379 pCache->nPage--;
37389 assert( pCache->nPage==nPage );
37428 PCache1 *pCache; /* The newly created page cache */
37433 ** The seperateCache variable is true if each PCache has its own private
37454 pCache = (PCache1 *)sqlite3_malloc(sz);
37455 if( pCache ){
37456 memset(pCache, 0, sz);
37458 pGroup = (PGroup*)&pCache[1];
37463 pCache->pGroup = pGroup;
37464 pCache->szPage = szPage;
37465 pCache->szExtra = szExtra;
37466 pCache->bPurgeable = (bPurgeable ? 1 : 0);
37468 pCache->nMin = 10;
37470 pGroup->nMinPage += pCache->nMin;
37475 return (sqlite3_pcache *)pCache;
37484 PCache1 *pCache = (PCache1 *)p;
37485 if( pCache->bPurgeable ){
37486 PGroup *pGroup = pCache->pGroup;
37488 pGroup->nMaxPage += (nMax - pCache->nMax);
37490 pCache->nMax = nMax;
37491 pCache->n90pct = pCache->nMax*9/10;
37503 PCache1 *pCache = (PCache1*)p;
37504 if( pCache->bPurgeable ){
37505 PGroup *pGroup = pCache->pGroup;
37521 PCache1 *pCache = (PCache1*)p;
37522 pcache1EnterMutex(pCache->pGroup);
37523 n = pCache->nPage;
37524 pcache1LeaveMutex(pCache->pGroup);
37540 ** the calling function (pcache.c) will never have a createFlag of 1 on
37588 PCache1 *pCache = (PCache1 *)p;
37592 assert( pCache->bPurgeable || createFlag!=1 );
37593 assert( pCache->bPurgeable || pCache->nMin==0 );
37594 assert( pCache->bPurgeable==0 || pCache->nMin==10 );
37595 assert( pCache->nMin==0 || pCache->bPurgeable );
37596 pcache1EnterMutex(pGroup = pCache->pGroup);
37599 if( pCache->nHash>0 ){
37600 unsigned int h = iKey % pCache->nHash;
37601 for(pPage=pCache->apHash[h]; pPage&&pPage->iKey!=iKey; pPage=pPage->pNext);
37618 pGroup = pCache->pGroup;
37622 assert( pCache->nPage >= pCache->nRecyclable );
37623 nPinned = pCache->nPage - pCache->nRecyclable;
37625 assert( pCache->n90pct == pCache->nMax*9/10 );
37628 || nPinned>=pCache->n90pct
37629 || pcache1UnderMemoryPressure(pCache)
37634 if( pCache->nPage>=pCache->nHash && pcache1ResizeHash(pCache) ){
37639 if( pCache->bPurgeable && pGroup->pLruTail && (
37640 (pCache->nPage+1>=pCache->nMax)
37642 || pcache1UnderMemoryPressure(pCache)
37648 pOther = pPage->pCache;
37651 ** and pCache. Assert that we can verify this by comparing sums. */
37652 assert( (pCache->szPage & (pCache->szPage-1))==0 && pCache->szPage>=512 );
37653 assert( pCache->szExtra<512 );
37657 if( pOther->szPage+pOther->szExtra != pCache->szPage+pCache->szExtra ){
37661 pGroup->nCurrentPage -= (pOther->bPurgeable - pCache->bPurgeable);
37670 pPage = pcache1AllocPage(pCache);
37675 unsigned int h = iKey % pCache->nHash;
37676 pCache->nPage++;
37678 pPage->pNext = pCache->apHash[h];
37679 pPage->pCache = pCache;
37683 pCache->apHash[h] = pPage;
37687 if( pPage && iKey>pCache->iMaxKey ){
37688 pCache->iMaxKey = iKey;
37705 PCache1 *pCache = (PCache1 *)p;
37707 PGroup *pGroup = pCache->pGroup;
37709 assert( pPage->pCache==pCache );
37731 pCache->nRecyclable++;
37734 pcache1LeaveMutex(pCache->pGroup);
37746 PCache1 *pCache = (PCache1 *)p;
37751 assert( pPage->pCache==pCache );
37753 pcache1EnterMutex(pCache->pGroup);
37755 h = iOld%pCache->nHash;
37756 pp = &pCache->apHash[h];
37762 h = iNew%pCache->nHash;
37764 pPage->pNext = pCache->apHash[h];
37765 pCache->apHash[h] = pPage;
37766 if( iNew>pCache->iMaxKey ){
37767 pCache->iMaxKey = iNew;
37770 pcache1LeaveMutex(pCache->pGroup);
37781 PCache1 *pCache = (PCache1 *)p;
37782 pcache1EnterMutex(pCache->pGroup);
37783 pCache->iMaxKey ){
37784 pcache1TruncateUnsafe(pCache, iLimit);
37785 pCache->iMaxKey = iLimit-1;
37787 pcache1LeaveMutex(pCache->pGroup);
37796 PCache1 *pCache = (PCache1 *)p;
37797 PGroup *pGroup = pCache->pGroup;
37798 assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) );
37800 pcache1TruncateUnsafe(pCache, 0);
37801 assert( pGroup->nMaxPage >= pCache->nMax );
37802 pGroup->nMaxPage -= pCache->nMax;
37803 assert( pGroup->nMinPage >= pCache->nMin );
37804 pGroup->nMinPage -= pCache->nMin;
37808 sqlite3_free(pCache->apHash);
37809 sqlite3_free(pCache);
38979 ** (calls made by the pcache module to the pagerStress() routine to
38984 ** comes up during savepoint rollback that requires the pcache module
39139 PCache *pPCache; /* Pointer to page cache object */
42611 ** This function is called by the pcache layer when it has reached some
42774 int pcacheSize = sqlite3PcacheSize(); /* Bytes to allocate for PCache */
42839 /* Allocate memory for the Pager structure, PCache object, the
42844 ** PCache object (sqlite3PcacheSize() bytes)
42853 ROUND8(pcacheSize) + /* PCache object */
42868 pPager->pPCache = (PCache*)(pPtr += ROUND8(sizeof(*pPager)));
42970 /* Initialize the PCache object. */
43405 ** read from the database file. In some cases, the pcache module may
43465 ** Otherwise, request the page from the PCache layer. */
43483 /* In this case the pcache already contains an initialized copy of
112652 ** The following mutex is what serializes access to the appdef pcache xInit