Home | History | Annotate | Download | only in dist

Lines Matching refs:PCache

8271 /************** Include pcache.h in the middle of sqliteInt.h ****************/
8272 /************** Begin file pcache.h ******************************************/
8291 typedef struct PCache PCache;
8309 ** Elements above are public. All that follows is private to pcache.c
8313 PCache *pCache; /* Cache that owns this page */
8346 PCache *pToInit /* Preallocated space for the PCache */
8350 SQLITE_PRIVATE void sqlite3PcacheSetPageSize(PCache *, int);
8352 /* Return the size in bytes of a PCache object. Used to preallocate
8360 SQLITE_PRIVATE int sqlite3PcacheFetch(PCache*, Pgno, int createFlag, PgHdr**);
8366 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache*); /* Mark all dirty list pages as clean */
8372 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache*, Pgno x);
8375 SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache*);
8378 SQLITE_PRIVATE void sqlite3PcacheClose(PCache*);
8381 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *);
8384 SQLITE_PRIVATE void sqlite3PcacheClear(PCache*);
8387 SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache*);
8395 SQLITE_PRIVATE int sqlite3PcachePagecount(PCache*);
8402 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
8411 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *, int);
8413 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *);
8417 /* Try to return memory used by the pcache module to the main memory heap */
8429 /************** End of pcache.h **********************************************/
10540 sqlite3_pcache_methods pcache; /* Low-level page-cache interface */
11482 {0,0,0,0,0,0,0,0,0,0,0}, /* pcache */
32823 /************** Begin file pcache.c ******************************************/
32841 struct PCache {
32851 sqlite3_pcache *pCache; /* Pluggable cache module */
32871 ** Check that the pCache->pSynced variable is set correctly. If it
32875 ** expensive_assert( pcacheCheckSynced(pCache) );
32877 static int pcacheCheckSynced(PCache *pCache){
32879 for(p=pCache->pDirtyTail; p!=pCache->pSynced; p=p->pDirtyPrev){
32890 PCache *p = pPage->pCache;
32927 PCache *p = pPage->pCache;
32951 PCache *pCache = p->pCache;
32952 if( pCache->bPurgeable ){
32954 pCache->pPage1 = 0;
32956 sqlite3GlobalConfig.pcache.xUnpin(pCache->pCache, p, 0);
32966 if( sqlite3GlobalConfig.pcache.xInit==0 ){
32972 return sqlite3GlobalConfig.pcache.xInit(sqlite3GlobalConfig.pcache.pArg);
32975 if( sqlite3GlobalConfig.pcache.xShutdown ){
32977 sqlite3GlobalConfig.pcache.xShutdown(sqlite3GlobalConfig.pcache.pArg);
32982 ** Return the size in bytes of a PCache object.
32984 SQLITE_PRIVATE int sqlite3PcacheSize(void){ return sizeof(PCache); }
32987 ** Create a new PCache object. Storage space to hold the object
32998 PCache *p /* Preallocated space for the PCache */
33000 memset(p, 0, sizeof(PCache));
33010 ** Change the page size for PCache object. The caller must ensure that there
33013 SQLITE_PRIVATE void sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
33014 assert( pCache->nRef==0 && pCache->pDirty==0 );
33015 if( pCache->pCache ){
33016 sqlite3GlobalConfig.pcache.xDestroy(pCache->pCache);
33017 pCache->pCache = 0;
33018 pCache->pPage1 = 0;
33020 pCache->szPage = szPage;
33027 PCache *pCache, /* Obtain the page from this cache */
33035 assert( pCache!=0 );
33042 if( !pCache->pCache && createFlag ){
33045 nByte = pCache->szPage + pCache->szExtra + sizeof(PgHdr);
33046 p = sqlite3GlobalConfig.pcache.xCreate(nByte, pCache->bPurgeable);
33050 sqlite3GlobalConfig.pcache.xCachesize(p, pCache->nMax);
33051 pCache->pCache = p;
33054 eCreate = createFlag * (1 + (!pCache->bPurgeable || !pCache->pDirty));
33055 if( pCache->pCache ){
33056 pPage = sqlite3GlobalConfig.pcache.xFetch(pCache->pCache, pgno, eCreate);
33067 expensive_assert( pcacheCheckSynced(pCache) );
33068 for(pPg=pCache->pSynced;
33072 pCache->pSynced = pPg;
33074 for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
33078 rc = pCache->xStress(pCache->pStress, pPg);
33084 pPage = sqlite3GlobalConfig.pcache.xFetch(pCache->pCache, pgno, 2);
33091 pPage->pExtra = (void*)&((char *)pPage->pData)[pCache->szPage];
33092 memset(pPage->pExtra, 0, pCache->szExtra);
33093 pPage->pCache = pCache;
33096 assert( pPage->pCache==pCache );
33099 assert( pPage->pExtra==(void *)&((char *)&pPage[1])[pCache->szPage] );
33102 pCache->nRef++;
33106 pCache->pPage1 = pPage;
33121 PCache *pCache = p->pCache;
33122 pCache->nRef--;
33147 PCache *pCache;
33152 pCache = p->pCache;
33153 pCache->nRef--;
33155 pCache->pPage1 = 0;
33157 sqlite3GlobalConfig.pcache.xUnpin(pCache->pCache, p, 1);
33190 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
33192 while( (p = pCache->pDirty)!=0 ){
33200 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){
33202 for(p=pCache->pDirty; p; p=p->pDirtyNext){
33205 pCache->pSynced = pCache->pDirtyTail;
33212 PCache *pCache = p->pCache;
33215 sqlite3GlobalConfig.pcache.xRekey(pCache->pCache, p, p->pgno, newPgno);
33232 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
33233 if( pCache->pCache ){
33236 for(p=pCache->pDirty; p; p=pNext){
33248 if( pgno==0 && pCache->pPage1 ){
33249 memset(pCache->pPage1->pData, 0, pCache->szPage);
33252 sqlite3GlobalConfig.pcache.xTruncate(pCache->pCache, pgno+1);
33259 SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
33260 if( pCache->pCache ){
33261 sqlite3GlobalConfig.pcache.xDestroy(pCache->pCache);
33268 SQLITE_PRIVATE void sqlite3PcacheClear(PCache *pCache){
33269 sqlite3PcacheTruncate(pCache, 0);
33345 SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
33347 for(p=pCache->pDirty; p; p=p->pDirtyNext){
33350 return pcacheSortDirtyList(pCache->pDirty);
33356 SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *pCache){
33357 return pCache->nRef;
33370 SQLITE_PRIVATE int sqlite3PcachePagecount(PCache *pCache){
33372 if( pCache->pCache ){
33373 nPage = sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache);
33382 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *pCache){
33383 return pCache->nMax;
33390 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){
33391 pCache->nMax = mxPage;
33392 if( pCache->pCache ){
33393 sqlite3GlobalConfig.pcache.xCachesize(pCache->pCache, mxPage);
33403 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *)){
33405 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext){
33411 /************** End of pcache.c **********************************************/
33470 ** structure. A buffer of PgHdr1.pCache->szPage bytes is allocated
33477 PCache1 *pCache; /* Cache that currently owns this page */
33503 int nSlot; /* The number of pcache slots */
33504 int nFreeSlot; /* Number of unused pcache slots */
33528 ** assert( PGHDR1_TO_PAGE(PAGE_TO_PGHDR1(pCache, X))==X );
33530 #define PGHDR1_TO_PAGE(p) (void*)(((char*)p) - p->pCache->szPage)
33587 ** global pcache mutex and unlock the pager-cache object pCache. This is
33630 ** Return the size of a pcache allocation
33648 ** Allocate a new page object initially associated with cache pCache.
33650 static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
33651 int nByte = sizeof(PgHdr1) + pCache->szPage;
33655 p = PAGE_TO_PGHDR1(pCache, pPg);
33656 if( pCache->bPurgeable ){
33674 if( p->pCache->bPurgeable ){
33720 static int pcache1UnderMemoryPressure(PCache1 *pCache){
33722 if( pcache1.nSlot && pCache->szPage<=pcache1.szSlot ){
33799 pPage->pCache->nRecyclable--;
33812 PCache1 *pCache = pPage->pCache;
33815 h = pPage->iKey % pCache->nHash;
33816 for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
33819 pCache->nPage--;
33823 ** If there are currently more than pcache.nMaxPage pages allocated, try
33824 ** to recycle pages to reduce the number allocated to pcache.nMaxPage.
33837 ** Discard all pages from cache pCache with a page number (key value)
33844 PCache1 *pCache,
33847 pCache->nPage is correct */
33850 for(h=0; h<pCache->nHash; h++){
33851 PgHdr1 **pp = &pCache->apHash[h];
33855 pCache->nPage--;
33865 assert( pCache->nPage==nPage );
33902 PCache1 *pCache;
33904 pCache = (PCache1 *)sqlite3_malloc(sizeof(PCache1));
33905 if( pCache ){
33906 memset(pCache, 0, sizeof(PCache1));
33907 pCache->szPage = szPage;
33908 pCache->bPurgeable = (bPurgeable ? 1 : 0);
33910 pCache->nMin = 10;
33912 pcache1.nMinPage += pCache->nMin;
33916 return (sqlite3_pcache *)pCache;
33925 PCache1 *pCache = (PCache1 *)p;
33926 if( pCache->bPurgeable ){
33928 pcache1.nMaxPage += (nMax - pCache->nMax);
33929 pCache->nMax = nMax;
33958 ** the calling function (pcache.c) will never have a createFlag of 1 on
34002 PCache1 *pCache = (PCache1 *)p;
34005 assert( pCache->bPurgeable || createFlag!=1 );
34010 if( pCache->nHash>0 ){
34011 unsigned int h = iKey % pCache->nHash;
34012 for(pPage=pCache->apHash[h]; pPage&&pPage->iKey!=iKey; pPage=pPage->pNext);
34021 nPinned = pCache->nPage - pCache->nRecyclable;
34023 nPinned>=(pcache1.nMaxPage+pCache->nMin-pcache1.nMinPage)
34024 || nPinned>=(pCache->nMax * 9 / 10)
34025 || pcache1UnderMemoryPressure(pCache)
34030 if( pCache->nPage>=pCache->nHash && pcache1ResizeHash(pCache) ){
34035 if( pCache->bPurgeable && pcache1.pLruTail && (
34036 (pCache->nPage+1>=pCache->nMax)
34038 || pcache1UnderMemoryPressure(pCache)
34043 if( pPage->pCache->szPage!=pCache->szPage ){
34047 pcache1.nCurrentPage -= (pPage->pCache->bPurgeable - pCache->bPurgeable);
34055 pPage = pcache1AllocPage(pCache);
34059 unsigned int h = iKey % pCache->nHash;
34060 pCache->nPage++;
34062 pPage->pNext = pCache->apHash[h];
34063 pPage->pCache = pCache;
34067 pCache->apHash[h] = pPage;
34071 if( pPage && iKey>pCache->iMaxKey ){
34072 pCache->iMaxKey = iKey;
34086 PCache1 *pCache = (PCache1 *)p;
34087 PgHdr1 *pPage = PAGE_TO_PGHDR1(pCache, pPg);
34089 assert( pPage->pCache==pCache );
34115 pCache->nRecyclable++;
34130 PCache1 *pCache = (PCache1 *)p;
34131 PgHdr1 *pPage = PAGE_TO_PGHDR1(pCache, pPg);
34135 assert( pPage->pCache==pCache );
34139 h = iOld%pCache->nHash;
34140 pp = &pCache->apHash[h];
34146 h = iNew%pCache->nHash;
34148 pPage->pNext = pCache->apHash[h];
34149 pCache->apHash[h] = pPage;
34150 if( iNew>pCache->iMaxKey ){
34151 pCache->iMaxKey = iNew;
34165 PCache1 *pCache = (PCache1 *)p;
34167 if( iLimit<=pCache->iMaxKey ){
34168 pcache1TruncateUnsafe(pCache, iLimit);
34169 pCache->iMaxKey = iLimit-1;
34180 PCache1 *pCache = (PCache1 *)p;
34181 assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) );
34183 pcache1TruncateUnsafe(pCache, 0);
34184 pcache1.nMaxPage -= pCache->nMax;
34185 pcache1.nMinPage -= pCache->nMin;
34188 sqlite3_free(pCache->apHash);
34189 sqlite3_free(pCache);
35329 ** (calls made by the pcache module to the pagerStress() routine to
35334 ** comes up during savepoint rollback that requires the pcache module
35489 PCache *pPCache; /* Pointer to page cache object */
38921 ** This function is called by the pcache layer when it has reached some
39085 int pcacheSize = sqlite3PcacheSize(); /* Bytes to allocate for PCache */
39140 /* Allocate memory for the Pager structure, PCache object, the
39145 ** PCache object (sqlite3PcacheSize() bytes)
39154 ROUND8(pcacheSize) + /* PCache object */
39169 pPager->pPCache = (PCache*)(pPtr += ROUND8(sizeof(*pPager)));
39268 /* Initialize the PCache object. */
39699 ** read from the database file. In some cases, the pcache module may
39759 ** Otherwise, request the page from the PCache layer. */
39777 /* In this case the pcache already contains an initialized copy of
104987 ** The following mutex is what serializes access to the appdef pcache xInit
105166 sqlite3GlobalConfig.pcache = *va_arg(ap, sqlite3_pcache_methods*);
105171 if( sqlite3GlobalConfig.pcache.xInit==0 ){
105174 *va_arg(ap, sqlite3_pcache_methods*) = sqlite3GlobalConfig.pcache;
107373 ** Return the size of a pcache header in bytes.