Home | History | Annotate | Download | only in dist

Lines Matching defs:pCache

7658 /************** Include pcache.h in the middle of sqliteInt.h ****************/
7659 /************** Begin file pcache.h ******************************************/
7678 typedef struct PCache PCache;
7696 ** Elements above are public. All that follows is private to pcache.c
7700 PCache *pCache; /* Cache that owns this page */
7733 PCache *pToInit /* Preallocated space for the PCache */
7737 SQLITE_PRIVATE void sqlite3PcacheSetPageSize(PCache *, int);
7739 /* Return the size in bytes of a PCache object. Used to preallocate
7747 SQLITE_PRIVATE int sqlite3PcacheFetch(PCache*, Pgno, int createFlag, PgHdr**);
7753 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache*); /* Mark all dirty list pages as clean */
7759 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache*, Pgno x);
7762 SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache*);
7765 SQLITE_PRIVATE void sqlite3PcacheClose(PCache*);
7768 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *);
7771 SQLITE_PRIVATE void sqlite3PcacheClear(PCache*);
7774 SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache*);
7782 SQLITE_PRIVATE int sqlite3PcachePagecount(PCache*);
7789 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
7798 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *, int);
7800 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *);
7804 /* Try to return memory used by the pcache module to the main memory heap */
7816 /************** End of pcache.h **********************************************/
9884 sqlite3_pcache_methods pcache; /* Low-level page-cache interface */
10762 {0,0,0,0,0,0,0,0,0,0,0}, /* pcache */
29654 /************** Begin file pcache.c ******************************************/
29672 struct PCache {
29682 sqlite3_pcache *pCache; /* Pluggable cache module */
29702 ** Check that the pCache->pSynced variable is set correctly. If it
29706 ** expensive_assert( pcacheCheckSynced(pCache) );
29708 static int pcacheCheckSynced(PCache *pCache){
29710 for(p=pCache->pDirtyTail; p!=pCache->pSynced; p=p->pDirtyPrev){
29721 PCache *p = pPage->pCache;
29758 PCache *p = pPage->pCache;
29782 PCache *pCache = p->pCache;
29783 if( pCache->bPurgeable ){
29785 pCache->pPage1 = 0;
29787 sqlite3GlobalConfig.pcache.xUnpin(pCache->pCache, p, 0);
29797 if( sqlite3GlobalConfig.pcache.xInit==0 ){
29800 return sqlite3GlobalConfig.pcache.xInit(sqlite3GlobalConfig.pcache.pArg);
29803 if( sqlite3GlobalConfig.pcache.xShutdown ){
29804 sqlite3GlobalConfig.pcache.xShutdown(sqlite3GlobalConfig.pcache.pArg);
29809 ** Return the size in bytes of a PCache object.
29811 SQLITE_PRIVATE int sqlite3PcacheSize(void){ return sizeof(PCache); }
29814 ** Create a new PCache object. Storage space to hold the object
29825 PCache *p /* Preallocated space for the PCache */
29827 memset(p, 0, sizeof(PCache));
29837 ** Change the page size for PCache object. The caller must ensure that there
29840 SQLITE_PRIVATE void sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
29841 assert( pCache->nRef==0 && pCache->pDirty==0 );
29842 if( pCache->pCache ){
29843 sqlite3GlobalConfig.pcache.xDestroy(pCache->pCache);
29844 pCache->pCache = 0;
29845 pCache->pPage1 = 0;
29847 pCache->szPage = szPage;
29854 PCache *pCache, /* Obtain the page from this cache */
29862 assert( pCache!=0 );
29869 if( !pCache->pCache && createFlag ){
29872 nByte = pCache->szPage + pCache->szExtra + sizeof(PgHdr);
29873 p = sqlite3GlobalConfig.pcache.xCreate(nByte, pCache->bPurgeable);
29877 sqlite3GlobalConfig.pcache.xCachesize(p, pCache->nMax);
29878 pCache->pCache = p;
29881 eCreate = createFlag * (1 + (!pCache->bPurgeable || !pCache->pDirty));
29882 if( pCache->pCache ){
29883 pPage = sqlite3GlobalConfig.pcache.xFetch(pCache->pCache, pgno, eCreate);
29894 expensive_assert( pcacheCheckSynced(pCache) );
29895 for(pPg=pCache->pSynced;
29899 pCache->pSynced = pPg;
29901 for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
29905 rc = pCache->xStress(pCache->pStress, pPg);
29911 pPage = sqlite3GlobalConfig.pcache.xFetch(pCache->pCache, pgno, 2);
29916 memset(pPage, 0, sizeof(PgHdr) + pCache->szExtra);
29918 pPage->pData = (void *)&((char *)pPage)[sizeof(PgHdr) + pCache->szExtra];
29919 pPage->pCache = pCache;
29922 assert( pPage->pCache==pCache );
29927 pCache->nRef++;
29931 pCache->pPage1 = pPage;
29946 PCache *pCache = p->pCache;
29947 pCache->nRef--;
29972 PCache *pCache;
29977 pCache = p->pCache;
29978 pCache->nRef--;
29980 pCache->pPage1 = 0;
29982 sqlite3GlobalConfig.pcache.xUnpin(pCache->pCache, p, 1);
30015 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
30017 while( (p = pCache->pDirty)!=0 ){
30025 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){
30027 for(p=pCache->pDirty; p; p=p->pDirtyNext){
30030 pCache->pSynced = pCache->pDirtyTail;
30037 PCache *pCache = p->pCache;
30040 sqlite3GlobalConfig.pcache.xRekey(pCache->pCache, p, p->pgno, newPgno);
30057 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
30058 if( pCache->pCache ){
30061 for(p=pCache->pDirty; p; p=pNext){
30068 if( pgno==0 && pCache->pPage1 ){
30069 memset(pCache->pPage1->pData, 0, pCache->szPage);
30072 sqlite3GlobalConfig.pcache.xTruncate(pCache->pCache, pgno+1);
30079 SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
30080 if( pCache->pCache ){
30081 sqlite3GlobalConfig.pcache.xDestroy(pCache->pCache);
30088 SQLITE_PRIVATE void sqlite3PcacheClear(PCache *pCache){
30089 sqlite3PcacheTruncate(pCache, 0);
30165 SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
30167 for(p=pCache->pDirty; p; p=p->pDirtyNext){
30170 return pcacheSortDirtyList(pCache->pDirty);
30176 SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *pCache){
30177 return pCache->nRef;
30190 SQLITE_PRIVATE int sqlite3PcachePagecount(PCache *pCache){
30192 if( pCache->pCache ){
30193 nPage = sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache);
30202 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *pCache){
30203 return pCache->nMax;
30210 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){
30211 pCache->nMax = mxPage;
30212 if( pCache->pCache ){
30213 sqlite3GlobalConfig.pcache.xCachesize(pCache->pCache, mxPage);
30223 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *)){
30225 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext){
30231 /************** End of pcache.c **********************************************/
30285 ** structure. A buffer of PgHdr1.pCache->szPage bytes is allocated
30292 PCache1 *pCache; /* Cache that currently owns this page */
30340 ** assert( PGHDR1_TO_PAGE(PAGE_TO_PGHDR1(pCache, X))==X );
30342 #define PGHDR1_TO_PAGE(p) (void*)(((char*)p) - p->pCache->szPage)
30395 ** global pcache mutex and unlock the pager-cache object pCache. This is
30431 ** Allocate a new page object initially associated with cache pCache.
30433 static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
30434 int nByte = sizeof(PgHdr1) + pCache->szPage;
30438 p = PAGE_TO_PGHDR1(pCache, pPg);
30439 if( pCache->bPurgeable ){
30457 if( p->pCache->bPurgeable ){
30556 pPage->pCache->nRecyclable--;
30569 PCache1 *pCache = pPage->pCache;
30572 h = pPage->iKey % pCache->nHash;
30573 for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
30576 pCache->nPage--;
30580 ** If there are currently more than pcache.nMaxPage pages allocated, try
30581 ** to recycle pages to reduce the number allocated to pcache.nMaxPage.
30594 ** Discard all pages from cache pCache with a page number (key value)
30601 PCache1 *pCache,
30604 TESTONLY( unsigned int nPage = 0; ) /* Used to assert pCache->nPage is correct */
30607 for(h=0; h<pCache->nHash; h++){
30608 PgHdr1 **pp = &pCache->apHash[h];
30612 pCache->nPage--;
30622 assert( pCache->nPage==nPage );
30659 PCache1 *pCache;
30661 pCache = (PCache1 *)sqlite3_malloc(sizeof(PCache1));
30662 if( pCache ){
30663 memset(pCache, 0, sizeof(PCache1));
30664 pCache->szPage = szPage;
30665 pCache->bPurgeable = (bPurgeable ? 1 : 0);
30667 pCache->nMin = 10;
30669 pcache1.nMinPage += pCache->nMin;
30673 return (sqlite3_pcache *)pCache;
30682 PCache1 *pCache = (PCache1 *)p;
30683 if( pCache->bPurgeable ){
30685 pcache1.nMaxPage += (nMax - pCache->nMax);
30686 pCache->nMax = nMax;
30715 ** the calling function (pcache.c) will never have a createFlag of 1 on
30754 PCache1 *pCache = (PCache1 *)p;
30757 assert( pCache->bPurgeable || createFlag!=1 );
30762 if( pCache->nHash>0 ){
30763 unsigned int h = iKey % pCache->nHash;
30764 for(pPage=pCache->apHash[h]; pPage&&pPage->iKey!=iKey; pPage=pPage->pNext);
30773 nPinned = pCache->nPage - pCache->nRecyclable;
30775 nPinned>=(pcache1.nMaxPage+pCache->nMin-pcache1.nMinPage)
30776 || nPinned>=(pCache->nMax * 9 / 10)
30781 if( pCache->nPage>=pCache->nHash && pcache1ResizeHash(pCache) ){
30786 if( pCache->bPurgeable && pcache1.pLruTail && (
30787 (pCache->nPage+1>=pCache->nMax) || pcache1.nCurrentPage>=pcache1.nMaxPage
30792 if( pPage->pCache->szPage!=pCache->szPage ){
30796 pcache1.nCurrentPage -= (pPage->pCache->bPurgeable - pCache->bPurgeable);
30804 pPage = pcache1AllocPage(pCache);
30808 unsigned int h = iKey % pCache->nHash;
30809 pCache->nPage++;
30811 pPage->pNext = pCache->apHash[h];
30812 pPage->pCache = pCache;
30816 pCache->apHash[h] = pPage;
30820 if( pPage && iKey>pCache->iMaxKey ){
30821 pCache->iMaxKey = iKey;
30835 PCache1 *pCache = (PCache1 *)p;
30836 PgHdr1 *pPage = PAGE_TO_PGHDR1(pCache, pPg);
30838 assert( pPage->pCache==pCache );
30864 pCache->nRecyclable++;
30879 PCache1 *pCache = (PCache1 *)p;
30880 PgHdr1 *pPage = PAGE_TO_PGHDR1(pCache, pPg);
30884 assert( pPage->pCache==pCache );
30888 h = iOld%pCache->nHash;
30889 pp = &pCache->apHash[h];
30895 h = iNew%pCache->nHash;
30897 pPage->pNext = pCache->apHash[h];
30898 pCache->apHash[h] = pPage;
30899 if( iNew>pCache->iMaxKey ){
30900 pCache->iMaxKey = iNew;
30914 PCache1 *pCache = (PCache1 *)p;
30916 if( iLimit<=pCache->iMaxKey ){
30917 pcache1TruncateUnsafe(pCache, iLimit);
30918 pCache->iMaxKey = iLimit-1;
30929 PCache1 *pCache = (PCache1 *)p;
30931 pcache1TruncateUnsafe(pCache, 0);
30932 pcache1.nMaxPage -= pCache->nMax;
30933 pcache1.nMinPage -= pCache->nMin;
30936 sqlite3_free(pCache->apHash);
30937 sqlite3_free(pCache);
31749 PCache *pPCache; /* Pointer to page cache object */
34402 ** This function is called by the pcache layer when it has reached some
34433 ** flag is set, return without doing anything. The pcache layer will
34557 int pcacheSize = sqlite3PcacheSize(); /* Bytes to allocate for PCache */
34614 /* Allocate memory for the Pager structure, PCache object, the
34619 ** PCache object (sqlite3PcacheSize() bytes)
34628 ROUND8(pcacheSize) + /* PCache object */
34640 pPager->pPCache = (PCache*)(pPtr += ROUND8(sizeof(*pPager)));
34732 /* Initialize the PCache object. */
35179 ** read from the database file. In some cases, the pcache module may
35239 ** Otherwise, request the page from the PCache layer. */
35257 /* In this case the pcache already contains an initialized copy of
95790 sqlite3GlobalConfig.pcache = *va_arg(ap, sqlite3_pcache_methods*);
95795 if( sqlite3GlobalConfig.pcache.xInit==0 ){
95798 *va_arg(ap, sqlite3_pcache_methods*) = sqlite3GlobalConfig.pcache;