Home | History | Annotate | Download | only in dist

Lines Matching refs:PCache

8278 /************** Include pcache.h in the middle of sqliteInt.h ****************/
8279 /************** Begin file pcache.h ******************************************/
8298 typedef struct PCache PCache;
8316 ** Elements above are public. All that follows is private to pcache.c
8320 PCache *pCache; /* Cache that owns this page */
8353 PCache *pToInit /* Preallocated space for the PCache */
8357 SQLITE_PRIVATE void sqlite3PcacheSetPageSize(PCache *, int);
8359 /* Return the size in bytes of a PCache object. Used to preallocate
8367 SQLITE_PRIVATE int sqlite3PcacheFetch(PCache*, Pgno, int createFlag, PgHdr**);
8373 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache*); /* Mark all dirty list pages as clean */
8379 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache*, Pgno x);
8382 SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache*);
8385 SQLITE_PRIVATE void sqlite3PcacheClose(PCache*);
8388 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *);
8391 SQLITE_PRIVATE void sqlite3PcacheClear(PCache*);
8394 SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache*);
8402 SQLITE_PRIVATE int sqlite3PcachePagecount(PCache*);
8409 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
8418 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *, int);
8420 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *);
8424 /* Try to return memory used by the pcache module to the main memory heap */
8436 /************** End of pcache.h **********************************************/
10547 sqlite3_pcache_methods pcache; /* Low-level page-cache interface */
11489 {0,0,0,0,0,0,0,0,0,0,0}, /* pcache */
32830 /************** Begin file pcache.c ******************************************/
32848 struct PCache {
32858 sqlite3_pcache *pCache; /* Pluggable cache module */
32878 ** Check that the pCache->pSynced variable is set correctly. If it
32882 ** expensive_assert( pcacheCheckSynced(pCache) );
32884 static int pcacheCheckSynced(PCache *pCache){
32886 for(p=pCache->pDirtyTail; p!=pCache->pSynced; p=p->pDirtyPrev){
32897 PCache *p = pPage->pCache;
32934 PCache *p = pPage->pCache;
32958 PCache *pCache = p->pCache;
32959 if( pCache->bPurgeable ){
32961 pCache->pPage1 = 0;
32963 sqlite3GlobalConfig.pcache.xUnpin(pCache->pCache, p, 0);
32973 if( sqlite3GlobalConfig.pcache.xInit==0 ){
32979 return sqlite3GlobalConfig.pcache.xInit(sqlite3GlobalConfig.pcache.pArg);
32982 if( sqlite3GlobalConfig.pcache.xShutdown ){
32984 sqlite3GlobalConfig.pcache.xShutdown(sqlite3GlobalConfig.pcache.pArg);
32989 ** Return the size in bytes of a PCache object.
32991 SQLITE_PRIVATE int sqlite3PcacheSize(void){ return sizeof(PCache); }
32994 ** Create a new PCache object. Storage space to hold the object
33005 PCache *p /* Preallocated space for the PCache */
33007 memset(p, 0, sizeof(PCache));
33017 ** Change the page size for PCache object. The caller must ensure that there
33020 SQLITE_PRIVATE void sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
33021 assert( pCache->nRef==0 && pCache->pDirty==0 );
33022 if( pCache->pCache ){
33023 sqlite3GlobalConfig.pcache.xDestroy(pCache->pCache);
33024 pCache->pCache = 0;
33025 pCache->pPage1 = 0;
33027 pCache->szPage = szPage;
33034 PCache *pCache, /* Obtain the page from this cache */
33042 assert( pCache!=0 );
33049 if( !pCache->pCache && createFlag ){
33052 nByte = pCache->szPage + pCache->szExtra + sizeof(PgHdr);
33053 p = sqlite3GlobalConfig.pcache.xCreate(nByte, pCache->bPurgeable);
33057 sqlite3GlobalConfig.pcache.xCachesize(p, pCache->nMax);
33058 pCache->pCache = p;
33061 eCreate = createFlag * (1 + (!pCache->bPurgeable || !pCache->pDirty));
33062 if( pCache->pCache ){
33063 pPage = sqlite3GlobalConfig.pcache.xFetch(pCache->pCache, pgno, eCreate);
33074 expensive_assert( pcacheCheckSynced(pCache) );
33075 for(pPg=pCache->pSynced;
33079 pCache->pSynced = pPg;
33081 for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
33085 rc = pCache->xStress(pCache->pStress, pPg);
33091 pPage = sqlite3GlobalConfig.pcache.xFetch(pCache->pCache, pgno, 2);
33098 pPage->pExtra = (void*)&((char *)pPage->pData)[pCache->szPage];
33099 memset(pPage->pExtra, 0, pCache->szExtra);
33100 pPage->pCache = pCache;
33103 assert( pPage->pCache==pCache );
33106 assert( pPage->pExtra==(void *)&((char *)&pPage[1])[pCache->szPage] );
33109 pCache->nRef++;
33113 pCache->pPage1 = pPage;
33128 PCache *pCache = p->pCache;
33129 pCache->nRef--;
33154 PCache *pCache;
33159 pCache = p->pCache;
33160 pCache->nRef--;
33162 pCache->pPage1 = 0;
33164 sqlite3GlobalConfig.pcache.xUnpin(pCache->pCache, p, 1);
33197 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
33199 while( (p = pCache->pDirty)!=0 ){
33207 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){
33209 for(p=pCache->pDirty; p; p=p->pDirtyNext){
33212 pCache->pSynced = pCache->pDirtyTail;
33219 PCache *pCache = p->pCache;
33222 sqlite3GlobalConfig.pcache.xRekey(pCache->pCache, p, p->pgno, newPgno);
33239 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
33240 if( pCache->pCache ){
33243 for(p=pCache->pDirty; p; p=pNext){
33255 if( pgno==0 && pCache->pPage1 ){
33256 memset(pCache->pPage1->pData, 0, pCache->szPage);
33259 sqlite3GlobalConfig.pcache.xTruncate(pCache->pCache, pgno+1);
33266 SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
33267 if( pCache->pCache ){
33268 sqlite3GlobalConfig.pcache.xDestroy(pCache->pCache);
33275 SQLITE_PRIVATE void sqlite3PcacheClear(PCache *pCache){
33276 sqlite3PcacheTruncate(pCache, 0);
33352 SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
33354 for(p=pCache->pDirty; p; p=p->pDirtyNext){
33357 return pcacheSortDirtyList(pCache->pDirty);
33363 SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *pCache){
33364 return pCache->nRef;
33377 SQLITE_PRIVATE int sqlite3PcachePagecount(PCache *pCache){
33379 if( pCache->pCache ){
33380 nPage = sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache);
33389 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *pCache){
33390 return pCache->nMax;
33397 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){
33398 pCache->nMax = mxPage;
33399 if( pCache->pCache ){
33400 sqlite3GlobalConfig.pcache.xCachesize(pCache->pCache, mxPage);
33410 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *)){
33412 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext){
33418 /************** End of pcache.c **********************************************/
33477 ** structure. A buffer of PgHdr1.pCache->szPage bytes is allocated
33484 PCache1 *pCache; /* Cache that currently owns this page */
33510 int nSlot; /* The number of pcache slots */
33511 int nFreeSlot; /* Number of unused pcache slots */
33535 ** assert( PGHDR1_TO_PAGE(PAGE_TO_PGHDR1(pCache, X))==X );
33537 #define PGHDR1_TO_PAGE(p) (void*)(((char*)p) - p->pCache->szPage)
33594 ** global pcache mutex and unlock the pager-cache object pCache. This is
33637 ** Return the size of a pcache allocation
33655 ** Allocate a new page object initially associated with cache pCache.
33657 static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
33658 int nByte = sizeof(PgHdr1) + pCache->szPage;
33662 p = PAGE_TO_PGHDR1(pCache, pPg);
33663 if( pCache->bPurgeable ){
33681 if( p->pCache->bPurgeable ){
33727 static int pcache1UnderMemoryPressure(PCache1 *pCache){
33729 if( pcache1.nSlot && pCache->szPage<=pcache1.szSlot ){
33806 pPage->pCache->nRecyclable--;
33819 PCache1 *pCache = pPage->pCache;
33822 h = pPage->iKey % pCache->nHash;
33823 for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
33826 pCache->nPage--;
33830 ** If there are currently more than pcache.nMaxPage pages allocated, try
33831 ** to recycle pages to reduce the number allocated to pcache.nMaxPage.
33844 ** Discard all pages from cache pCache with a page number (key value)
33851 PCache1 *pCache,
33854 TESTONLY( unsigned int nPage = 0; ) /* Used to assert pCache->nPage is correct */
33857 for(h=0; h<pCache->nHash; h++){
33858 PgHdr1 **pp = &pCache->apHash[h];
33862 pCache->nPage--;
33872 assert( pCache->nPage==nPage );
33909 PCache1 *pCache;
33911 pCache = (PCache1 *)sqlite3_malloc(sizeof(PCache1));
33912 if( pCache ){
33913 memset(pCache, 0, sizeof(PCache1));
33914 pCache->szPage = szPage;
33915 pCache->bPurgeable = (bPurgeable ? 1 : 0);
33917 pCache->nMin = 10;
33919 pcache1.nMinPage += pCache->nMin;
33923 return (sqlite3_pcache *)pCache;
33932 PCache1 *pCache = (PCache1 *)p;
33933 if( pCache->bPurgeable ){
33935 pcache1.nMaxPage += (nMax - pCache->nMax);
33936 pCache->nMax = nMax;
33965 ** the calling function (pcache.c) will never have a createFlag of 1 on
34009 PCache1 *pCache = (PCache1 *)p;
34012 assert( pCache->bPurgeable || createFlag!=1 );
34017 if( pCache->nHash>0 ){
34018 unsigned int h = iKey % pCache->nHash;
34019 for(pPage=pCache->apHash[h]; pPage&&pPage->iKey!=iKey; pPage=pPage->pNext);
34028 nPinned = pCache->nPage - pCache->nRecyclable;
34030 nPinned>=(pcache1.nMaxPage+pCache->nMin-pcache1.nMinPage)
34031 || nPinned>=(pCache->nMax * 9 / 10)
34032 || pcache1UnderMemoryPressure(pCache)
34037 if( pCache->nPage>=pCache->nHash && pcache1ResizeHash(pCache) ){
34042 if( pCache->bPurgeable && pcache1.pLruTail && (
34043 (pCache->nPage+1>=pCache->nMax)
34045 || pcache1UnderMemoryPressure(pCache)
34050 if( pPage->pCache->szPage!=pCache->szPage ){
34054 pcache1.nCurrentPage -= (pPage->pCache->bPurgeable - pCache->bPurgeable);
34062 pPage = pcache1AllocPage(pCache);
34066 unsigned int h = iKey % pCache->nHash;
34067 pCache->nPage++;
34069 pPage->pNext = pCache->apHash[h];
34070 pPage->pCache = pCache;
34074 pCache->apHash[h] = pPage;
34078 if( pPage && iKey>pCache->iMaxKey ){
34079 pCache->iMaxKey = iKey;
34093 PCache1 *pCache = (PCache1 *)p;
34094 PgHdr1 *pPage = PAGE_TO_PGHDR1(pCache, pPg);
34096 assert( pPage->pCache==pCache );
34122 pCache->nRecyclable++;
34137 PCache1 *pCache = (PCache1 *)p;
34138 PgHdr1 *pPage = PAGE_TO_PGHDR1(pCache, pPg);
34142 assert( pPage->pCache==pCache );
34146 h = iOld%pCache->nHash;
34147 pp = &pCache->apHash[h];
34153 h = iNew%pCache->nHash;
34155 pPage->pNext = pCache->apHash[h];
34156 pCache->apHash[h] = pPage;
34157 if( iNew>pCache->iMaxKey ){
34158 pCache->iMaxKey = iNew;
34172 PCache1 *pCache = (PCache1 *)p;
34174 if( iLimit<=pCache->iMaxKey ){
34175 pcache1TruncateUnsafe(pCache, iLimit);
34176 pCache->iMaxKey = iLimit-1;
34187 PCache1 *pCache = (PCache1 *)p;
34188 assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) );
34190 pcache1TruncateUnsafe(pCache, 0);
34191 pcache1.nMaxPage -= pCache->nMax;
34192 pcache1.nMinPage -= pCache->nMin;
34195 sqlite3_free(pCache->apHash);
34196 sqlite3_free(pCache);
35336 ** (calls made by the pcache module to the pagerStress() routine to
35341 ** comes up during savepoint rollback that requires the pcache module
35496 PCache *pPCache; /* Pointer to page cache object */
38928 ** This function is called by the pcache layer when it has reached some
39092 int pcacheSize = sqlite3PcacheSize(); /* Bytes to allocate for PCache */
39147 /* Allocate memory for the Pager structure, PCache object, the
39152 ** PCache object (sqlite3PcacheSize() bytes)
39161 ROUND8(pcacheSize) + /* PCache object */
39176 pPager->pPCache = (PCache*)(pPtr += ROUND8(sizeof(*pPager)));
39275 /* Initialize the PCache object. */
39706 ** read from the database file. In some cases, the pcache module may
39766 ** Otherwise, request the page from the PCache layer. */
39784 /* In this case the pcache already contains an initialized copy of
104994 ** The following mutex is what serializes access to the appdef pcache xInit
105173 sqlite3GlobalConfig.pcache = *va_arg(ap, sqlite3_pcache_methods*);
105178 if( sqlite3GlobalConfig.pcache.xInit==0 ){
105181 *va_arg(ap, sqlite3_pcache_methods*) = sqlite3GlobalConfig.pcache;
107401 ** Return the size of a pcache header in bytes.