| OLD | NEW |
| 1 /* | 1 /* |
| 2 ** 2008 August 05 | 2 ** 2008 August 05 |
| 3 ** | 3 ** |
| 4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
| 5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
| 6 ** | 6 ** |
| 7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
| 8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
| 9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
| 10 ** | 10 ** |
| 11 ************************************************************************* | 11 ************************************************************************* |
| 12 ** This header file defines the interface that the sqlite page cache | 12 ** This header file defines the interface that the sqlite page cache |
| 13 ** subsystem. | 13 ** subsystem. |
| 14 */ | 14 */ |
| 15 | 15 |
| 16 #ifndef _PCACHE_H_ | 16 #ifndef _PCACHE_H_ |
| 17 | 17 |
| 18 typedef struct PgHdr PgHdr; | 18 typedef struct PgHdr PgHdr; |
| 19 typedef struct PCache PCache; | 19 typedef struct PCache PCache; |
| 20 | 20 |
| 21 /* | 21 /* |
| 22 ** Every page in the cache is controlled by an instance of the following | 22 ** Every page in the cache is controlled by an instance of the following |
| 23 ** structure. | 23 ** structure. |
| 24 */ | 24 */ |
| 25 struct PgHdr { | 25 struct PgHdr { |
| 26 void *pData; /* Content of this page */ | 26 sqlite3_pcache_page *pPage; /* Pcache object page handle */ |
| 27 void *pData; /* Page data */ |
| 27 void *pExtra; /* Extra content */ | 28 void *pExtra; /* Extra content */ |
| 28 PgHdr *pDirty; /* Transient list of dirty pages */ | 29 PgHdr *pDirty; /* Transient list of dirty pages */ |
| 30 Pager *pPager; /* The pager this page is part of */ |
| 29 Pgno pgno; /* Page number for this page */ | 31 Pgno pgno; /* Page number for this page */ |
| 30 Pager *pPager; /* The pager this page is part of */ | |
| 31 #ifdef SQLITE_CHECK_PAGES | 32 #ifdef SQLITE_CHECK_PAGES |
| 32 u32 pageHash; /* Hash of page content */ | 33 u32 pageHash; /* Hash of page content */ |
| 33 #endif | 34 #endif |
| 34 u16 flags; /* PGHDR flags defined below */ | 35 u16 flags; /* PGHDR flags defined below */ |
| 35 | 36 |
| 36 /********************************************************************** | 37 /********************************************************************** |
| 37 ** Elements above are public. All that follows is private to pcache.c | 38 ** Elements above are public. All that follows is private to pcache.c |
| 38 ** and should not be accessed by other modules. | 39 ** and should not be accessed by other modules. |
| 39 */ | 40 */ |
| 40 i16 nRef; /* Number of users of this page */ | 41 i16 nRef; /* Number of users of this page */ |
| 41 PCache *pCache; /* Cache that owns this page */ | 42 PCache *pCache; /* Cache that owns this page */ |
| 42 | 43 |
| 43 PgHdr *pDirtyNext; /* Next element in list of dirty pages */ | 44 PgHdr *pDirtyNext; /* Next element in list of dirty pages */ |
| 44 PgHdr *pDirtyPrev; /* Previous element in list of dirty pages */ | 45 PgHdr *pDirtyPrev; /* Previous element in list of dirty pages */ |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 /* Bit values for PgHdr.flags */ | 48 /* Bit values for PgHdr.flags */ |
| 48 #define PGHDR_DIRTY 0x002 /* Page has changed */ | 49 #define PGHDR_DIRTY 0x002 /* Page has changed */ |
| 49 #define PGHDR_NEED_SYNC 0x004 /* Fsync the rollback journal before | 50 #define PGHDR_NEED_SYNC 0x004 /* Fsync the rollback journal before |
| 50 ** writing this page to the database */ | 51 ** writing this page to the database */ |
| 51 #define PGHDR_NEED_READ 0x008 /* Content is unread */ | 52 #define PGHDR_NEED_READ 0x008 /* Content is unread */ |
| 52 #define PGHDR_REUSE_UNLIKELY 0x010 /* A hint that reuse is unlikely */ | 53 #define PGHDR_REUSE_UNLIKELY 0x010 /* A hint that reuse is unlikely */ |
| 53 #define PGHDR_DONT_WRITE 0x020 /* Do not write content to disk */ | 54 #define PGHDR_DONT_WRITE 0x020 /* Do not write content to disk */ |
| 54 | 55 |
| 56 #define PGHDR_MMAP 0x040 /* This is an mmap page object */ |
| 57 |
| 55 /* Initialize and shutdown the page cache subsystem */ | 58 /* Initialize and shutdown the page cache subsystem */ |
| 56 int sqlite3PcacheInitialize(void); | 59 int sqlite3PcacheInitialize(void); |
| 57 void sqlite3PcacheShutdown(void); | 60 void sqlite3PcacheShutdown(void); |
| 58 | 61 |
| 59 /* Page cache buffer management: | 62 /* Page cache buffer management: |
| 60 ** These routines implement SQLITE_CONFIG_PAGECACHE. | 63 ** These routines implement SQLITE_CONFIG_PAGECACHE. |
| 61 */ | 64 */ |
| 62 void sqlite3PCacheBufferSetup(void *, int sz, int n); | 65 void sqlite3PCacheBufferSetup(void *, int sz, int n); |
| 63 | 66 |
| 64 /* Create a new pager cache. | 67 /* Create a new pager cache. |
| 65 ** Under memory stress, invoke xStress to try to make pages clean. | 68 ** Under memory stress, invoke xStress to try to make pages clean. |
| 66 ** Only clean and unpinned pages can be reclaimed. | 69 ** Only clean and unpinned pages can be reclaimed. |
| 67 */ | 70 */ |
| 68 void sqlite3PcacheOpen( | 71 int sqlite3PcacheOpen( |
| 69 int szPage, /* Size of every page */ | 72 int szPage, /* Size of every page */ |
| 70 int szExtra, /* Extra space associated with each page */ | 73 int szExtra, /* Extra space associated with each page */ |
| 71 int bPurgeable, /* True if pages are on backing store */ | 74 int bPurgeable, /* True if pages are on backing store */ |
| 72 int (*xStress)(void*, PgHdr*), /* Call to try to make pages clean */ | 75 int (*xStress)(void*, PgHdr*), /* Call to try to make pages clean */ |
| 73 void *pStress, /* Argument to xStress */ | 76 void *pStress, /* Argument to xStress */ |
| 74 PCache *pToInit /* Preallocated space for the PCache */ | 77 PCache *pToInit /* Preallocated space for the PCache */ |
| 75 ); | 78 ); |
| 76 | 79 |
| 77 /* Modify the page-size after the cache has been created. */ | 80 /* Modify the page-size after the cache has been created. */ |
| 78 void sqlite3PcacheSetPageSize(PCache *, int); | 81 int sqlite3PcacheSetPageSize(PCache *, int); |
| 79 | 82 |
| 80 /* Return the size in bytes of a PCache object. Used to preallocate | 83 /* Return the size in bytes of a PCache object. Used to preallocate |
| 81 ** storage space. | 84 ** storage space. |
| 82 */ | 85 */ |
| 83 int sqlite3PcacheSize(void); | 86 int sqlite3PcacheSize(void); |
| 84 | 87 |
| 85 /* One release per successful fetch. Page is pinned until released. | 88 /* One release per successful fetch. Page is pinned until released. |
| 86 ** Reference counted. | 89 ** Reference counted. |
| 87 */ | 90 */ |
| 88 int sqlite3PcacheFetch(PCache*, Pgno, int createFlag, PgHdr**); | 91 sqlite3_pcache_page *sqlite3PcacheFetch(PCache*, Pgno, int createFlag); |
| 92 int sqlite3PcacheFetchStress(PCache*, Pgno, sqlite3_pcache_page**); |
| 93 PgHdr *sqlite3PcacheFetchFinish(PCache*, Pgno, sqlite3_pcache_page *pPage); |
| 89 void sqlite3PcacheRelease(PgHdr*); | 94 void sqlite3PcacheRelease(PgHdr*); |
| 90 | 95 |
| 91 void sqlite3PcacheDrop(PgHdr*); /* Remove page from cache */ | 96 void sqlite3PcacheDrop(PgHdr*); /* Remove page from cache */ |
| 92 void sqlite3PcacheMakeDirty(PgHdr*); /* Make sure page is marked dirty */ | 97 void sqlite3PcacheMakeDirty(PgHdr*); /* Make sure page is marked dirty */ |
| 93 void sqlite3PcacheMakeClean(PgHdr*); /* Mark a single page as clean */ | 98 void sqlite3PcacheMakeClean(PgHdr*); /* Mark a single page as clean */ |
| 94 void sqlite3PcacheCleanAll(PCache*); /* Mark all dirty list pages as clean */ | 99 void sqlite3PcacheCleanAll(PCache*); /* Mark all dirty list pages as clean */ |
| 95 | 100 |
| 96 /* Change a page number. Used by incr-vacuum. */ | 101 /* Change a page number. Used by incr-vacuum. */ |
| 97 void sqlite3PcacheMove(PgHdr*, Pgno); | 102 void sqlite3PcacheMove(PgHdr*, Pgno); |
| 98 | 103 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 ** | 139 ** |
| 135 ** If no global maximum is configured, then the system attempts to limit | 140 ** If no global maximum is configured, then the system attempts to limit |
| 136 ** the total number of pages cached by purgeable pager-caches to the sum | 141 ** the total number of pages cached by purgeable pager-caches to the sum |
| 137 ** of the suggested cache-sizes. | 142 ** of the suggested cache-sizes. |
| 138 */ | 143 */ |
| 139 void sqlite3PcacheSetCachesize(PCache *, int); | 144 void sqlite3PcacheSetCachesize(PCache *, int); |
| 140 #ifdef SQLITE_TEST | 145 #ifdef SQLITE_TEST |
| 141 int sqlite3PcacheGetCachesize(PCache *); | 146 int sqlite3PcacheGetCachesize(PCache *); |
| 142 #endif | 147 #endif |
| 143 | 148 |
| 149 /* Free up as much memory as possible from the page cache */ |
| 150 void sqlite3PcacheShrink(PCache*); |
| 151 |
| 144 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT | 152 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 145 /* Try to return memory used by the pcache module to the main memory heap */ | 153 /* Try to return memory used by the pcache module to the main memory heap */ |
| 146 int sqlite3PcacheReleaseMemory(int); | 154 int sqlite3PcacheReleaseMemory(int); |
| 147 #endif | 155 #endif |
| 148 | 156 |
| 149 #ifdef SQLITE_TEST | 157 #ifdef SQLITE_TEST |
| 150 void sqlite3PcacheStats(int*,int*,int*,int*); | 158 void sqlite3PcacheStats(int*,int*,int*,int*); |
| 151 #endif | 159 #endif |
| 152 | 160 |
| 153 void sqlite3PCacheSetDefault(void); | 161 void sqlite3PCacheSetDefault(void); |
| 154 | 162 |
| 155 #endif /* _PCACHE_H_ */ | 163 #endif /* _PCACHE_H_ */ |
| OLD | NEW |