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 **********************************************/
36234 /************** Begin file pcache.c ******************************************/
36252 struct PCache {
36262 sqlite3_pcache *pCache; /* Pluggable cache module */
36282 ** Check that the pCache->pSynced variable is set correctly. If it
36286 ** expensive_assert( pcacheCheckSynced(pCache) );
36288 static int pcacheCheckSynced(PCache *pCache){
36290 for(p=pCache->pDirtyTail; p!=pCache->pSynced; p=p->pDirtyPrev){
36301 PCache *p = pPage->pCache;
36338 PCache *p = pPage->pCache;
36362 PCache *pCache = p->pCache;
36363 if( pCache->bPurgeable ){
36365 pCache->pPage1 = 0;
36367 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, p->pPage, 0);
36393 ** Return the size in bytes of a PCache object.
36395 SQLITE_PRIVATE int sqlite3PcacheSize(void){ return sizeof(PCache); }
36398 ** Create a new PCache object. Storage space to hold the object
36409 PCache *p /* Preallocated space for the PCache */
36411 memset(p, 0, sizeof(PCache));
36421 ** Change the page size for PCache object. The caller must ensure that there
36424 SQLITE_PRIVATE void sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
36425 assert( pCache->nRef==0 && pCache->pDirty==0 );
36426 if( pCache->pCache ){
36427 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
36428 pCache->pCache = 0;
36429 pCache->pPage1 = 0;
36431 pCache->szPage = szPage;
36437 static int numberOfCachePages(PCache *p){
36449 PCache *pCache, /* Obtain the page from this cache */
36458 assert( pCache!=0 );
36465 if( !pCache->pCache && createFlag ){
36468 pCache->szPage, pCache->szExtra + sizeof(PgHdr), pCache->bPurgeable
36473 sqlite3GlobalConfig.pcache2.xCachesize(p, numberOfCachePages(pCache));
36474 pCache->pCache = p;
36477 eCreate = createFlag * (1 + (!pCache->bPurgeable || !pCache->pDirty));
36478 if( pCache->pCache ){
36479 pPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
36490 expensive_assert( pcacheCheckSynced(pCache) );
36491 for(pPg=pCache->pSynced;
36495 pCache->pSynced = pPg;
36497 for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
36505 sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache),
36506 numberOfCachePages(pCache));
36508 rc = pCache->xStress(pCache->pStress, pPg);
36514 pPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, 2);
36525 memset(pPgHdr->pExtra, 0, pCache->szExtra);
36526 pPgHdr->pCache = pCache;
36529 assert( pPgHdr->pCache==pCache );
36535 pCache->nRef++;
36539 pCache->pPage1 = pPgHdr;
36554 PCache *pCache = p->pCache;
36555 pCache->nRef--;
36580 PCache *pCache;
36585 pCache = p->pCache;
36586 pCache->nRef--;
36588 pCache->pPage1 = 0;
36590 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, p->pPage, 1);
36623 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
36625 while( (p = pCache->pDirty)!=0 ){
36633 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){
36635 for(p=pCache->pDirty; p; p=p->pDirtyNext){
36638 pCache->pSynced = pCache->pDirtyTail;
36645 PCache *pCache = p->pCache;
36648 sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
36665 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
36666 if( pCache->pCache ){
36669 for(p=pCache->pDirty; p; p=pNext){
36681 if( pgno==0 && pCache->pPage1 ){
36682 memset(pCache->pPage1->pData, 0, pCache->szPage);
36685 sqlite3GlobalConfig.pcache2.xTruncate(pCache->pCache, pgno+1);
36692 SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
36693 if( pCache->pCache ){
36694 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
36701 SQLITE_PRIVATE void sqlite3PcacheClear(PCache *pCache){
36702 sqlite3PcacheTruncate(pCache, 0);
36778 SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
36780 for(p=pCache->pDirty; p; p=p->pDirtyNext){
36783 return pcacheSortDirtyList(pCache->pDirty);
36789 SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *pCache){
36790 return pCache->nRef;
36803 SQLITE_PRIVATE int sqlite3PcachePagecount(PCache *pCache){
36805 if( pCache->pCache ){
36806 nPage = sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache);
36815 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *pCache){
36816 return numberOfCachePages(pCache);
36823 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){
36824 pCache->szCache = mxPage;
36825 if( pCache->pCache ){
36826 sqlite3GlobalConfig.pcache2.xCachesize(pCache->pCache,
36827 numberOfCachePages(pCache));
36834 SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){
36835 if( pCache->pCache ){
36836 sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache);
36846 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *)){
36848 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext){
36854 /************** End of pcache.c **********************************************/
36881 /* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
36888 ** (1) Every PCache is the sole member of its own PGroup. There is
36889 ** one PGroup per PCache.
36894 ** Mode 1 uses more memory (since PCache instances are not able to rob
36947 ** PgHdr1.pCache->szPage bytes is allocated directly before this structure
36954 PCache1 *pCache; /* Cache that currently owns this page */
36980 int nSlot; /* The number of pcache slots */
36986 int nFreeSlot; /* Number of unused pcache slots */
37002 ** Macros to enter and leave the PCache LRU mutex.
37111 ** Return the size of a pcache allocation
37128 ** Allocate a new page object initially associated with cache pCache.
37130 static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
37137 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
37138 pcache1LeaveMutex(pCache->pGroup);
37140 pPg = pcache1Alloc(pCache->szPage);
37141 p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
37148 pPg = pcache1Alloc(sizeof(PgHdr1) + pCache->szPage + pCache->szExtra);
37149 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
37151 pcache1EnterMutex(pCache->pGroup);
37156 if( pCache->bPurgeable ){
37157 pCache->pGroup->nCurrentPage++;
37173 PCache1 *pCache = p->pCache;
37174 assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
37179 if( pCache->bPurgeable ){
37180 pCache->pGroup->nCurrentPage--;
37218 static int pcache1UnderMemoryPressure(PCache1 *pCache){
37219 if( pcache1.nSlot && (pCache->szPage+pCache->szExtra)<=pcache1.szSlot ){
37233 ** The PCache mutex must be held when this function is called.
37282 PCache1 *pCache;
37286 pCache = pPage->pCache;
37287 pGroup = pCache->pGroup;
37304 pPage->pCache->nRecyclable--;
37317 PCache1 *pCache = pPage->pCache;
37320 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
37321 h = pPage->iKey % pCache->nHash;
37322 for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
37325 pCache->nPage--;
37336 assert( p->pCache->pGroup==pGroup );
37344 ** Discard all pages from cache pCache with a page number (key value)
37348 ** The PCache mutex must be held when this function is called.
37351 PCache1 *pCache, /* The cache to truncate */
37354 TESTONLY( unsigned int nPage = 0; ) /* To assert pCache->nPage is correct */
37356 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
37357 for(h=0; h<pCache->nHash; h++){
37358 PgHdr1 **pp = &pCache->apHash[h];
37362 pCache->nPage--;
37372 assert( pCache->nPage==nPage );
37411 PCache1 *pCache; /* The newly created page cache */
37416 ** The seperateCache variable is true if each PCache has its own private
37437 pCache = (PCache1 *)sqlite3_malloc(sz);
37438 if( pCache ){
37439 memset(pCache, 0, sz);
37441 pGroup = (PGroup*)&pCache[1];
37446 pCache->pGroup = pGroup;
37447 pCache->szPage = szPage;
37448 pCache->szExtra = szExtra;
37449 pCache->bPurgeable = (bPurgeable ? 1 : 0);
37451 pCache->nMin = 10;
37453 pGroup->nMinPage += pCache->nMin;
37458 return (sqlite3_pcache *)pCache;
37467 PCache1 *pCache = (PCache1 *)p;
37468 if( pCache->bPurgeable ){
37469 PGroup *pGroup = pCache->pGroup;
37471 pGroup->nMaxPage += (nMax - pCache->nMax);
37473 pCache->nMax = nMax;
37474 pCache->n90pct = pCache->nMax*9/10;
37486 PCache1 *pCache = (PCache1*)p;
37487 if( pCache->bPurgeable ){
37488 PGroup *pGroup = pCache->pGroup;
37504 PCache1 *pCache = (PCache1*)p;
37505 pcache1EnterMutex(pCache->pGroup);
37506 n = pCache->nPage;
37507 pcache1LeaveMutex(pCache->pGroup);
37523 ** the calling function (pcache.c) will never have a createFlag of 1 on
37571 PCache1 *pCache = (PCache1 *)p;
37575 assert( pCache->bPurgeable || createFlag!=1 );
37576 assert( pCache->bPurgeable || pCache->nMin==0 );
37577 assert( pCache->bPurgeable==0 || pCache->nMin==10 );
37578 assert( pCache->nMin==0 || pCache->bPurgeable );
37579 pcache1EnterMutex(pGroup = pCache->pGroup);
37582 if( pCache->nHash>0 ){
37583 unsigned int h = iKey % pCache->nHash;
37584 for(pPage=pCache->apHash[h]; pPage&&pPage->iKey!=iKey; pPage=pPage->pNext);
37601 pGroup = pCache->pGroup;
37605 assert( pCache->nPage >= pCache->nRecyclable );
37606 nPinned = pCache->nPage - pCache->nRecyclable;
37608 assert( pCache->n90pct == pCache->nMax*9/10 );
37611 || nPinned>=pCache->n90pct
37612 || pcache1UnderMemoryPressure(pCache)
37617 if( pCache->nPage>=pCache->nHash && pcache1ResizeHash(pCache) ){
37622 if( pCache->bPurgeable && pGroup->pLruTail && (
37623 (pCache->nPage+1>=pCache->nMax)
37625 || pcache1UnderMemoryPressure(pCache)
37631 pOther = pPage->pCache;
37634 ** and pCache. Assert that we can verify this by comparing sums. */
37635 assert( (pCache->szPage & (pCache->szPage-1))==0 && pCache->szPage>=512 );
37636 assert( pCache->szExtra<512 );
37640 if( pOther->szPage+pOther->szExtra != pCache->szPage+pCache->szExtra ){
37644 pGroup->nCurrentPage -= (pOther->bPurgeable - pCache->bPurgeable);
37653 pPage = pcache1AllocPage(pCache);
37658 unsigned int h = iKey % pCache->nHash;
37659 pCache->nPage++;
37661 pPage->pNext = pCache->apHash[h];
37662 pPage->pCache = pCache;
37666 pCache->apHash[h] = pPage;
37670 if( pPage && iKey>pCache->iMaxKey ){
37671 pCache->iMaxKey = iKey;
37688 PCache1 *pCache = (PCache1 *)p;
37690 PGroup *pGroup = pCache->pGroup;
37692 assert( pPage->pCache==pCache );
37714 pCache->nRecyclable++;
37717 pcache1LeaveMutex(pCache->pGroup);
37729 PCache1 *pCache = (PCache1 *)p;
37734 assert( pPage->pCache==pCache );
37736 pcache1EnterMutex(pCache->pGroup);
37738 h = iOld%pCache->nHash;
37739 pp = &pCache->apHash[h];
37745 h = iNew%pCache->nHash;
37747 pPage->pNext = pCache->apHash[h];
37748 pCache->apHash[h] = pPage;
37749 if( iNew>pCache->iMaxKey ){
37750 pCache->iMaxKey = iNew;
37753 pcache1LeaveMutex(pCache->pGroup);
37764 PCache1 *pCache = (PCache1 *)p;
37765 pcache1EnterMutex(pCache->pGroup);
37766 if( iLimit<=pCache->iMaxKey ){
37767 pcache1TruncateUnsafe(pCache, iLimit);
37768 pCache->iMaxKey = iLimit-1;
37770 pcache1LeaveMutex(pCache->pGroup);
37779 PCache1 *pCache = (PCache1 *)p;
37780 PGroup *pGroup = pCache->pGroup;
37781 assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) );
37783 pcache1TruncateUnsafe(pCache, 0);
37784 assert( pGroup->nMaxPage >= pCache->nMax );
37785 pGroup->nMaxPage -= pCache->nMax;
37786 pCache->nMin );
37787 pGroup->nMinPage -= pCache->nMin;
37791 sqlite3_free(pCache->apHash);
37792 sqlite3_free(pCache);
38962 ** (calls made by the pcache module to the pagerStress() routine to
38967 ** comes up during savepoint rollback that requires the pcache module
39122 PCache *pPCache; /* Pointer to page cache object */
42594 ** This function is called by the pcache layer when it has reached some
42757 int pcacheSize = sqlite3PcacheSize(); /* Bytes to allocate for PCache */
42822 /* Allocate memory for the Pager structure, PCache object, the
42827 ** PCache object (sqlite3PcacheSize() bytes)
42836 ROUND8(pcacheSize) + /* PCache object */
42851 pPager->pPCache = (PCache*)(pPtr += ROUND8(sizeof(*pPager)));
42953 /* Initialize the PCache object. */
43388 ** read from the database file. In some cases, the pcache module may
43448 ** Otherwise, request the page from the PCache layer. */
43466 /* In this case the pcache already contains an initialized copy of
112627 ** The following mutex is what serializes access to the appdef pcache xInit