00001 /* 00002 ** 2008 August 05 00003 ** 00004 ** The author disclaims copyright to this source code. In place of 00005 ** a legal notice, here is a blessing: 00006 ** 00007 ** May you do good and not evil. 00008 ** May you find forgiveness for yourself and forgive others. 00009 ** May you share freely, never taking more than you give. 00010 ** 00011 ************************************************************************* 00012 ** This header file defines the interface that the sqlite page cache 00013 ** subsystem. 00014 ** 00015 ** @(#) $Id: pcache.h,v 1.14 2008/10/17 18:51:53 danielk1977 Exp $ 00016 */ 00017 00018 #ifndef _PCACHE_H_ 00019 00020 typedef struct PgHdr PgHdr; 00021 typedef struct PCache PCache; 00022 00023 /* 00024 ** Every page in the cache is controlled by an instance of the following 00025 ** structure. 00026 */ 00027 struct PgHdr { 00028 void *pData; /* Content of this page */ 00029 void *pExtra; /* Extra content */ 00030 PgHdr *pDirty; /* Transient list of dirty pages */ 00031 Pgno pgno; /* Page number for this page */ 00032 Pager *pPager; /* The pager this page is part of */ 00033 #ifdef SQLITE_CHECK_PAGES 00034 u32 pageHash; /* Hash of page content */ 00035 #endif 00036 u16 flags; /* PGHDR flags defined below */ 00037 /********************************************************************** 00038 ** Elements above are public. All that follows is private to pcache.c 00039 ** and should not be accessed by other modules. 00040 */ 00041 i16 nRef; /* Number of users of this page */ 00042 PCache *pCache; /* Cache that owns this page */ 00043 00044 /********************************************************************** 00045 ** Elements above are accessible at any time by the owner of the cache 00046 ** without the need for a mutex. The elements that follow can only be 00047 ** accessed while holding the SQLITE_MUTEX_STATIC_LRU mutex. 00048 */ 00049 PgHdr *pNextHash, *pPrevHash; /* Hash collision chain for PgHdr.pgno */ 00050 PgHdr *pNext, *pPrev; /* List of clean or dirty pages */ 00051 PgHdr *pNextLru, *pPrevLru; /* Part of global LRU list */ 00052 }; 00053 00054 /* Bit values for PgHdr.flags */ 00055 #define PGHDR_IN_JOURNAL 0x001 /* Page is in rollback journal */ 00056 #define PGHDR_DIRTY 0x002 /* Page has changed */ 00057 #define PGHDR_NEED_SYNC 0x004 /* Fsync the rollback journal before 00058 ** writing this page to the database */ 00059 #define PGHDR_NEED_READ 0x008 /* Content is unread */ 00060 #define PGHDR_REUSE_UNLIKELY 0x010 /* A hint that reuse is unlikely */ 00061 #define PGHDR_DONT_WRITE 0x020 /* Do not write content to disk */ 00062 00063 /* Initialize and shutdown the page cache subsystem */ 00064 int sqlite3PcacheInitialize(void); 00065 void sqlite3PcacheShutdown(void); 00066 00067 /* Page cache buffer management: 00068 ** These routines implement SQLITE_CONFIG_PAGECACHE. 00069 */ 00070 void sqlite3PCacheBufferSetup(void *, int sz, int n); 00071 void *sqlite3PCacheMalloc(int sz); 00072 void sqlite3PCacheFree(void*); 00073 00074 /* Create a new pager cache. 00075 ** Under memory stress, invoke xStress to try to make pages clean. 00076 ** Only clean and unpinned pages can be reclaimed. 00077 */ 00078 void sqlite3PcacheOpen( 00079 int szPage, /* Size of every page */ 00080 int szExtra, /* Extra space associated with each page */ 00081 int bPurgeable, /* True if pages are on backing store */ 00082 int (*xStress)(void*, PgHdr*), /* Call to try to make pages clean */ 00083 void *pStress, /* Argument to xStress */ 00084 PCache *pToInit /* Preallocated space for the PCache */ 00085 ); 00086 00087 /* Modify the page-size after the cache has been created. */ 00088 void sqlite3PcacheSetPageSize(PCache *, int); 00089 00090 /* Return the size in bytes of a PCache object. Used to preallocate 00091 ** storage space. 00092 */ 00093 int sqlite3PcacheSize(void); 00094 00095 /* One release per successful fetch. Page is pinned until released. 00096 ** Reference counted. 00097 */ 00098 int sqlite3PcacheFetch(PCache*, Pgno, int createFlag, PgHdr**); 00099 void sqlite3PcacheRelease(PgHdr*); 00100 00101 void sqlite3PcacheDrop(PgHdr*); /* Remove page from cache */ 00102 void sqlite3PcacheMakeDirty(PgHdr*); /* Make sure page is marked dirty */ 00103 void sqlite3PcacheMakeClean(PgHdr*); /* Mark a single page as clean */ 00104 void sqlite3PcacheCleanAll(PCache*); /* Mark all dirty list pages as clean */ 00105 00106 /* Change a page number. Used by incr-vacuum. */ 00107 void sqlite3PcacheMove(PgHdr*, Pgno); 00108 00109 /* Remove all pages with pgno>x. Reset the cache if x==0 */ 00110 void sqlite3PcacheTruncate(PCache*, Pgno x); 00111 00112 /* Get a list of all dirty pages in the cache, sorted by page number */ 00113 PgHdr *sqlite3PcacheDirtyList(PCache*); 00114 00115 /* Reset and close the cache object */ 00116 void sqlite3PcacheClose(PCache*); 00117 00118 /* Clear flags from pages of the page cache */ 00119 void sqlite3PcacheClearFlags(PCache*, int mask); 00120 00121 /* Assert flags settings on all pages. Debugging only */ 00122 #ifndef NDEBUG 00123 void sqlite3PcacheAssertFlags(PCache*, int trueMask, int falseMask); 00124 #else 00125 # define sqlite3PcacheAssertFlags(A,B,C) 00126 #endif 00127 00128 /* Return true if the number of dirty pages is 0 or 1 */ 00129 int sqlite3PcacheZeroOrOneDirtyPages(PCache*); 00130 00131 /* Discard the contents of the cache */ 00132 int sqlite3PcacheClear(PCache*); 00133 00134 /* Return the total number of outstanding page references */ 00135 int sqlite3PcacheRefCount(PCache*); 00136 00137 /* Increment the reference count of an existing page */ 00138 void sqlite3PcacheRef(PgHdr*); 00139 00140 int sqlite3PcachePageRefcount(PgHdr*); 00141 00142 /* Return the total number of pages stored in the cache */ 00143 int sqlite3PcachePagecount(PCache*); 00144 00145 #ifdef SQLITE_CHECK_PAGES 00146 /* Iterate through all pages currently stored in the cache. This interface 00147 ** is only available if SQLITE_CHECK_PAGES is defined when the library is 00148 ** built. 00149 */ 00150 void sqlite3PcacheIterate(PCache *pCache, void (*xIter)(PgHdr *)); 00151 #endif 00152 00153 /* Set and get the suggested cache-size for the specified pager-cache. 00154 ** 00155 ** If no global maximum is configured, then the system attempts to limit 00156 ** the total number of pages cached by purgeable pager-caches to the sum 00157 ** of the suggested cache-sizes. 00158 */ 00159 int sqlite3PcacheGetCachesize(PCache *); 00160 void sqlite3PcacheSetCachesize(PCache *, int); 00161 00162 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT 00163 /* Try to return memory used by the pcache module to the main memory heap */ 00164 int sqlite3PcacheReleaseMemory(int); 00165 #endif 00166 00167 #ifdef SQLITE_TEST 00168 void sqlite3PcacheStats(int*,int*,int*,int*); 00169 #endif 00170 00171 #endif /* _PCACHE_H_ */
ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:55 2011 by Doxygen 1.6.1