From ee70a84ea7d709979dc09fa42bf4aa9afae21667 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 6 Jul 2015 18:54:52 +0000 Subject: [PATCH 1/8] Enhance separate pcache1 to allocate a block of pages from heap on startup, if possible, for a 5.2% performance improvement. FossilOrigin-Name: aa7341c8736732a0a59f6688cc34e78be02a7bfc --- manifest | 19 +++--- manifest.uuid | 2 +- src/global.c | 2 +- src/pcache1.c | 148 ++++++++++++++++++++++++++++++++-------------- test/speedtest1.c | 12 ++-- 5 files changed, 126 insertions(+), 57 deletions(-) diff --git a/manifest b/manifest index 1954e6998c..c2e77a579b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\sallow\srecursive\sCTEs\sthat\suse\saggregate\squeries\sin\sthe\srecursive\spart. -D 2015-07-05T22:15:10.026 +C Enhance\sseparate\spcache1\sto\sallocate\sa\sblock\sof\spages\sfrom\sheap\son\sstartup,\nif\spossible,\sfor\sa\s5.2%\sperformance\simprovement. +D 2015-07-06T18:54:52.424 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 017bf0511d1b2dd1db5e16488fbf75a17b526cbc F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -283,7 +283,7 @@ F src/expr.c c5c58e4d01c7ceb2266791d8d877f1b23a88e316 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c c9b63a217d86582c22121699a47f22f524608869 F src/func.c a98ea5880dc50e9ca6dd6f57079a37b9cfcdecf1 -F src/global.c 4f77cadbc5427d00139ba43d0f3979804cbb700e +F src/global.c 32c0ebfdca59db55c761f1405abf7bdfd24ecae0 F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 @@ -319,7 +319,7 @@ F src/pager.h 6d435f563b3f7fcae4b84433b76a6ac2730036e2 F src/parse.y 6d60dda8f8d418b6dc034f1fbccd816c459983a8 F src/pcache.c cde06aa50962595e412d497e22fd2e07878ba1f0 F src/pcache.h 9968603796240cdf83da7e7bef76edf90619cea9 -F src/pcache1.c b800e90896640bb0d1b0f6baa34fb059ca3b8b2e +F src/pcache1.c 28f3434788cac24bc95f8c1af4a61cbde179ef18 F src/pragma.c c1f4d012ea9f6b1ce52d341b2cd0ad72d560afd7 F src/pragma.h b8632d7cdda7b25323fa580e3e558a4f0d4502cc F src/prepare.c 82e5db1013846a819f198336fed72c44c974e7b1 @@ -1005,7 +1005,7 @@ F test/speed3.test d32043614c08c53eafdc80f33191d5bd9b920523 F test/speed4.test abc0ad3399dcf9703abed2fff8705e4f8e416715 F test/speed4p.explain 6b5f104ebeb34a038b2f714150f51d01143e59aa F test/speed4p.test 0e51908951677de5a969b723e03a27a1c45db38b -F test/speedtest1.c 2e8f367c5fe5e0c3df24a157e17cb2f75c1b88c7 +F test/speedtest1.c 54f211994e2fb5b3f7c5c82137378f46ca89aae8 F test/spellfix.test 0597065ff57042df1f138e6a2611ae19c2698135 F test/sqldiff1.test 8f6bc7c6a5b3585d350d779c6078869ba402f8f5 F test/sqllimits1.test e05786eaed7950ff6a2d00031d001d8a26131e68 @@ -1364,7 +1364,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 8cf02090ce53ec150492d77d9e5e5f27665bd34f -R 2ced95f329e3743e78bec1f4f82122ca +P 6d2999afbc25b9c238e4028f637c10eaaf0ec75e +R 773f110b2d424984f83126d1917fdcbb +T *branch * pcache-bulk-local +T *sym-pcache-bulk-local * +T -sym-trunk * U drh -Z 74748fde014fce363e747a5eecd57396 +Z a5a615d5b6a74570375077a92838726e diff --git a/manifest.uuid b/manifest.uuid index 0975b167fb..29a53816d9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6d2999afbc25b9c238e4028f637c10eaaf0ec75e \ No newline at end of file +aa7341c8736732a0a59f6688cc34e78be02a7bfc \ No newline at end of file diff --git a/src/global.c b/src/global.c index 61450b3d35..3b1e804bb8 100644 --- a/src/global.c +++ b/src/global.c @@ -186,7 +186,7 @@ SQLITE_WSD struct Sqlite3Config sqlite3Config = { 0, /* nScratch */ (void*)0, /* pPage */ 0, /* szPage */ - 0, /* nPage */ + 100, /* nPage */ 0, /* mxParserStack */ 0, /* sharedCacheEnabled */ SQLITE_SORTER_PMASZ, /* szPma */ diff --git a/src/pcache1.c b/src/pcache1.c index 797354bd75..30ea7d0d8b 100644 --- a/src/pcache1.c +++ b/src/pcache1.c @@ -50,8 +50,35 @@ ** ** The pcache.c and pager.c modules deal pointers to PgHdr objects. ** The btree.c module deals with pointers to MemPage objects. +** +** SOURCE OF PAGE CACHE MEMORY: +** +** Memory for a page might come from any of three sources: +** +** (1) The general-purpose memory allocator - sqlite3Malloc() +** (2) Global page-cache memory provided using sqlite3_config() with +** SQLITE_CONFIG_PAGECACHE. +** (3) PCache-local bulk allocation. +** +** The third case is a chunk of heap memory (defaulting to 100 pages worth) +** that is allocated when the page cache is created. The size of the local +** bulk allocation can be adjusted using +** +** sqlite3_config(SQLITE_CONFIG_PCACHE, 0, 0, N). +** +** If N is positive, then N pages worth of memory are allocated using a single +** sqlite3Malloc() call and that memory is used for the first N pages allocated. +** Or if N is negative, then -1024*N bytes of memory are allocated and used +** for as many pages as can be accomodated. +** +** Only one of (2) or (3) can be used. Once the memory available to (2) or +** (3) is exhausted, subsequent allocations fail over to the general-purpose +** memory allocator (1). +** +** Earlier versions of SQLite used only methods (1) and (2). But experiments +** show that method (3) with N==100 provides about a 5% performance boost for +** common workloads. */ - #include "sqliteInt.h" typedef struct PCache1 PCache1; @@ -105,8 +132,9 @@ struct PCache1 { ** The PGroup mutex must be held when accessing nMax. */ PGroup *pGroup; /* PGroup this cache belongs to */ - int szPage; /* Size of allocated pages in bytes */ - int szExtra; /* Size of extra space in bytes */ + int szPage; /* Size of database content section */ + int szExtra; /* sizeof(MemPage)+sizeof(PgHdr) */ + int szAlloc; /* Total size of one pcache line */ int bPurgeable; /* True if cache is purgeable */ unsigned int nMin; /* Minimum number of pages reserved */ unsigned int nMax; /* Configured "cache_size" value */ @@ -120,6 +148,8 @@ struct PCache1 { unsigned int nPage; /* Total number of pages in apHash */ unsigned int nHash; /* Number of slots in apHash[] */ PgHdr1 **apHash; /* Hash table for fast lookup by key */ + PgHdr1 *pFree; /* List of unused pcache-local pages */ + void *pBulk; /* Bulk memory used by pcache-local */ }; /* @@ -132,6 +162,7 @@ struct PgHdr1 { sqlite3_pcache_page page; unsigned int iKey; /* Key value (page number) */ u8 isPinned; /* Page in use, not on the LRU list */ + u8 isBulkLocal; /* This page from bulk local storage */ PgHdr1 *pNext; /* Next in hash table chain */ PCache1 *pCache; /* Cache that currently owns this page */ PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */ @@ -139,8 +170,8 @@ struct PgHdr1 { }; /* -** Free slots in the allocator used to divide up the buffer provided using -** the SQLITE_CONFIG_PAGECACHE mechanism. +** Free slots in the allocator used to divide up the global page cache +** buffer provided using the SQLITE_CONFIG_PAGECACHE mechanism. */ struct PgFreeslot { PgFreeslot *pNext; /* Next free slot */ @@ -161,7 +192,7 @@ static SQLITE_WSD struct PCacheGlobal { int szSlot; /* Size of each free slot */ int nSlot; /* The number of pcache slots */ int nReserve; /* Try to keep nFreeSlot above this */ - void *pStart, *pEnd; /* Bounds of pagecache malloc range */ + void *pStart, *pEnd; /* Bounds of global page cache memory */ /* Above requires no mutex. Use mutex below for variable that follow. */ sqlite3_mutex *mutex; /* Mutex for accessing the following: */ PgFreeslot *pFree; /* Free page blocks */ @@ -208,6 +239,7 @@ static SQLITE_WSD struct PCacheGlobal { void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){ if( pcache1.isInit ){ PgFreeslot *p; + if( pBuf==0 ) sz = n = 0; sz = ROUNDDOWN8(sz); pcache1.szSlot = sz; pcache1.nSlot = pcache1.nFreeSlot = n; @@ -272,9 +304,9 @@ static void *pcache1Alloc(int nByte){ /* ** Free an allocated buffer obtained from pcache1Alloc(). */ -static int pcache1Free(void *p){ +static void pcache1Free(void *p){ int nFreed = 0; - if( p==0 ) return 0; + if( p==0 ) return; if( p>=pcache1.pStart && ppGroup->mutex) ); - pcache1LeaveMutex(pCache->pGroup); + if( pCache->pFree ){ + p = pCache->pFree; + pCache->pFree = p->pNext; + p->pNext = 0; + }else{ + /* The group mutex must be released before pcache1Alloc() is called. This + ** is because it may call sqlite3_release_memory(), which assumes that + ** this mutex is not held. */ + pcache1LeaveMutex(pCache->pGroup); #ifdef SQLITE_PCACHE_SEPARATE_HEADER - pPg = pcache1Alloc(pCache->szPage); - p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra); - if( !pPg || !p ){ - pcache1Free(pPg); - sqlite3_free(p); - pPg = 0; - } + pPg = pcache1Alloc(pCache->szPage); + p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra); + if( !pPg || !p ){ + pcache1Free(pPg); + sqlite3_free(p); + pPg = 0; + } #else - pPg = pcache1Alloc(ROUND8(sizeof(PgHdr1)) + pCache->szPage + pCache->szExtra); - p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage]; + pPg = pcache1Alloc(pCache->szAlloc); + p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage]; #endif - pcache1EnterMutex(pCache->pGroup); - - if( pPg ){ + pcache1EnterMutex(pCache->pGroup); + if( pPg==0 ) return 0; p->page.pBuf = pPg; p->page.pExtra = &p[1]; - if( pCache->bPurgeable ){ - pCache->pGroup->nCurrentPage++; - } - return p; + p->isBulkLocal = 0; } - return 0; + if( pCache->bPurgeable ){ + pCache->pGroup->nCurrentPage++; + } + return p; } /* @@ -366,10 +401,15 @@ static void pcache1FreePage(PgHdr1 *p){ if( ALWAYS(p) ){ PCache1 *pCache = p->pCache; assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) ); - pcache1Free(p->page.pBuf); + if( p->isBulkLocal ){ + p->pNext = pCache->pFree; + pCache->pFree = p; + }else{ + pcache1Free(p->page.pBuf); #ifdef SQLITE_PCACHE_SEPARATE_HEADER - sqlite3_free(p); + sqlite3_free(p); #endif + } if( pCache->bPurgeable ){ pCache->pGroup->nCurrentPage--; } @@ -640,6 +680,7 @@ static sqlite3_pcache *pcache1Create(int szPage, int szExtra, int bPurgeable){ pCache->pGroup = pGroup; pCache->szPage = szPage; pCache->szExtra = szExtra; + pCache->szAlloc = szPage + szExtra + ROUND8(sizeof(PgHdr1)); pCache->bPurgeable = (bPurgeable ? 1 : 0); pcache1EnterMutex(pGroup); pcache1ResizeHash(pCache); @@ -649,6 +690,34 @@ static sqlite3_pcache *pcache1Create(int szPage, int szExtra, int bPurgeable){ pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage; } pcache1LeaveMutex(pGroup); + if( separateCache + && sqlite3GlobalConfig.szPage==0 + && sqlite3GlobalConfig.nPage!=0 + ){ + int szBulk; + char *zBulk; + sqlite3BeginBenignMalloc(); + if( sqlite3GlobalConfig.nPage>0 ){ + szBulk = pCache->szAlloc * sqlite3GlobalConfig.nPage; + }else{ + szBulk = -1024*sqlite3GlobalConfig.nPage; + } + zBulk = pCache->pBulk = sqlite3Malloc( szBulk ); + sqlite3EndBenignMalloc(); + if( zBulk ){ + int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc; + int i; + for(i=0; ipage.pBuf = zBulk; + pX->page.pExtra = &pX[1]; + pX->isBulkLocal = 1; + pX->pNext = pCache->pFree; + pCache->pFree = pX; + zBulk += pCache->szAlloc; + } + } + } if( pCache->nHash==0 ){ pcache1Destroy((sqlite3_pcache*)pCache); pCache = 0; @@ -753,15 +822,7 @@ static SQLITE_NOINLINE PgHdr1 *pcache1FetchStage2( pcache1RemoveFromHash(pPage, 0); pcache1PinPage(pPage); pOther = pPage->pCache; - - /* We want to verify that szPage and szExtra are the same for pOther - ** and pCache. Assert that we can verify this by comparing sums. */ - assert( (pCache->szPage & (pCache->szPage-1))==0 && pCache->szPage>=512 ); - assert( pCache->szExtra<512 ); - assert( (pOther->szPage & (pOther->szPage-1))==0 && pOther->szPage>=512 ); - assert( pOther->szExtra<512 ); - - if( pOther->szPage+pOther->szExtra != pCache->szPage+pCache->szExtra ){ + if( pOther->szAlloc != pCache->szAlloc ){ pcache1FreePage(pPage); pPage = 0; }else{ @@ -1037,6 +1098,7 @@ static void pcache1Destroy(sqlite3_pcache *p){ pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage; pcache1EnforceMaxPage(pGroup); pcache1LeaveMutex(pGroup); + sqlite3_free(pCache->pBulk); sqlite3_free(pCache->apHash); sqlite3_free(pCache); } @@ -1092,7 +1154,7 @@ int sqlite3PcacheReleaseMemory(int nReq){ int nFree = 0; assert( sqlite3_mutex_notheld(pcache1.grp.mutex) ); assert( sqlite3_mutex_notheld(pcache1.mutex) ); - if( pcache1.pStart==0 ){ + if( sqlite3GlobalConfig.nPage==0 ){ PgHdr1 *p; pcache1EnterMutex(&pcache1.grp); while( (nReq<0 || nFree=argc-2 ) fatal_error("missing arguments on %s\n", argv[i]); nPCache = integerValue(argv[i+1]); szPCache = integerValue(argv[i+2]); + doPCache = 1; i += 2; }else if( strcmp(z,"primarykey")==0 ){ g.zPK = "PRIMARY KEY"; @@ -1317,10 +1319,12 @@ int main(int argc, char **argv){ rc = sqlite3_config(SQLITE_CONFIG_HEAP, pHeap, nHeap, mnHeap); if( rc ) fatal_error("heap configuration failed: %d\n", rc); } - if( nPCache>0 && szPCache>0 ){ - pPCache = malloc( nPCache*(sqlite3_int64)szPCache ); - if( pPCache==0 ) fatal_error("cannot allocate %lld-byte pcache\n", - nPCache*(sqlite3_int64)szPCache); + if( doPCache ){ + if( nPCache>0 && szPCache>0 ){ + pPCache = malloc( nPCache*(sqlite3_int64)szPCache ); + if( pPCache==0 ) fatal_error("cannot allocate %lld-byte pcache\n", + nPCache*(sqlite3_int64)szPCache); + } rc = sqlite3_config(SQLITE_CONFIG_PAGECACHE, pPCache, szPCache, nPCache); if( rc ) fatal_error("pcache configuration failed: %d\n", rc); } From db7ae89d5ba3a97cf23a8600d21e6d181eef8210 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 6 Jul 2015 20:57:22 +0000 Subject: [PATCH 2/8] A unified cache is now only used for SQLITE_ENABLE_MEMORY_MANAGEMENT, or if SQLITE_CONFIG_PAGECACHE defines a shared start-time page cache buffer and the application is single-threaded. FossilOrigin-Name: d5ff1d69054d51a55eff6e1979971822db7f8f30 --- manifest | 15 ++++----- manifest.uuid | 2 +- src/pcache1.c | 91 +++++++++++++++++++++++++++------------------------ 3 files changed, 56 insertions(+), 52 deletions(-) diff --git a/manifest b/manifest index c2e77a579b..4622da25d7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhance\sseparate\spcache1\sto\sallocate\sa\sblock\sof\spages\sfrom\sheap\son\sstartup,\nif\spossible,\sfor\sa\s5.2%\sperformance\simprovement. -D 2015-07-06T18:54:52.424 +C A\sunified\scache\sis\snow\sonly\sused\sfor\sSQLITE_ENABLE_MEMORY_MANAGEMENT,\sor\sif\nSQLITE_CONFIG_PAGECACHE\sdefines\sa\sshared\sstart-time\spage\scache\sbuffer\sand\sthe\napplication\sis\ssingle-threaded. +D 2015-07-06T20:57:22.615 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 017bf0511d1b2dd1db5e16488fbf75a17b526cbc F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -319,7 +319,7 @@ F src/pager.h 6d435f563b3f7fcae4b84433b76a6ac2730036e2 F src/parse.y 6d60dda8f8d418b6dc034f1fbccd816c459983a8 F src/pcache.c cde06aa50962595e412d497e22fd2e07878ba1f0 F src/pcache.h 9968603796240cdf83da7e7bef76edf90619cea9 -F src/pcache1.c 28f3434788cac24bc95f8c1af4a61cbde179ef18 +F src/pcache1.c 17c392b4208ea6e1e5d220be18bcfebac07110b1 F src/pragma.c c1f4d012ea9f6b1ce52d341b2cd0ad72d560afd7 F src/pragma.h b8632d7cdda7b25323fa580e3e558a4f0d4502cc F src/prepare.c 82e5db1013846a819f198336fed72c44c974e7b1 @@ -1364,10 +1364,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 6d2999afbc25b9c238e4028f637c10eaaf0ec75e -R 773f110b2d424984f83126d1917fdcbb -T *branch * pcache-bulk-local -T *sym-pcache-bulk-local * -T -sym-trunk * +P aa7341c8736732a0a59f6688cc34e78be02a7bfc +R ab876e072a5f820e07c8ea2cb7e263ca U drh -Z a5a615d5b6a74570375077a92838726e +Z d6cf6ae811ec210c263fdd6a92d21a0f diff --git a/manifest.uuid b/manifest.uuid index 29a53816d9..d027464ae1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -aa7341c8736732a0a59f6688cc34e78be02a7bfc \ No newline at end of file +d5ff1d69054d51a55eff6e1979971822db7f8f30 \ No newline at end of file diff --git a/src/pcache1.c b/src/pcache1.c index 30ea7d0d8b..c34d0bba1c 100644 --- a/src/pcache1.c +++ b/src/pcache1.c @@ -189,6 +189,7 @@ static SQLITE_WSD struct PCacheGlobal { ** The nFreeSlot and pFree values do require mutex protection. */ int isInit; /* True if initialized */ + int separateCache; /* Use a new PGroup for each PCache */ int szSlot; /* Size of each free slot */ int nSlot; /* The number of pcache slots */ int nReserve; /* Try to keep nFreeSlot above this */ @@ -362,10 +363,14 @@ static PgHdr1 *pcache1AllocPage(PCache1 *pCache){ pCache->pFree = p->pNext; p->pNext = 0; }else{ +#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT /* The group mutex must be released before pcache1Alloc() is called. This - ** is because it may call sqlite3_release_memory(), which assumes that + ** is because it might call sqlite3_release_memory(), which assumes that ** this mutex is not held. */ + assert( pcache1.separateCache==0 ); + assert( pCache->pGroup==&pcache1.grp ); pcache1LeaveMutex(pCache->pGroup); +#endif #ifdef SQLITE_PCACHE_SEPARATE_HEADER pPg = pcache1Alloc(pCache->szPage); p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra); @@ -378,7 +383,9 @@ static PgHdr1 *pcache1AllocPage(PCache1 *pCache){ pPg = pcache1Alloc(pCache->szAlloc); p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage]; #endif +#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT pcache1EnterMutex(pCache->pGroup); +#endif if( pPg==0 ) return 0; p->page.pBuf = pPg; p->page.pExtra = &p[1]; @@ -392,27 +399,23 @@ static PgHdr1 *pcache1AllocPage(PCache1 *pCache){ /* ** Free a page object allocated by pcache1AllocPage(). -** -** The pointer is allowed to be NULL, which is prudent. But it turns out -** that the current implementation happens to never call this routine -** with a NULL pointer, so we mark the NULL test with ALWAYS(). */ static void pcache1FreePage(PgHdr1 *p){ - if( ALWAYS(p) ){ - PCache1 *pCache = p->pCache; - assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) ); - if( p->isBulkLocal ){ - p->pNext = pCache->pFree; - pCache->pFree = p; - }else{ - pcache1Free(p->page.pBuf); + PCache1 *pCache; + assert( p!=0 ); + pCache = p->pCache; + assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) ); + if( p->isBulkLocal ){ + p->pNext = pCache->pFree; + pCache->pFree = p; + }else{ + pcache1Free(p->page.pBuf); #ifdef SQLITE_PCACHE_SEPARATE_HEADER - sqlite3_free(p); + sqlite3_free(p); #endif - } - if( pCache->bPurgeable ){ - pCache->pGroup->nCurrentPage--; - } + } + if( pCache->bPurgeable ){ + pCache->pGroup->nCurrentPage--; } } @@ -612,6 +615,29 @@ static int pcache1Init(void *NotUsed){ UNUSED_PARAMETER(NotUsed); assert( pcache1.isInit==0 ); memset(&pcache1, 0, sizeof(pcache1)); + + + /* + ** The pcache1.separateCache variable is true if each PCache has its own + ** private PGroup (mode-1). pcache1.separateCache is false if the single + ** PGroup in pcache1.grp is used for all page caches (mode-2). + ** + ** * Always use a unified cache (mode-2) if ENABLE_MEMORY_MANAGEMENT + ** + ** * Use a unified cache in single-threaded applications that have + ** configured a start-time buffer for use as page-cache memory using + ** sqlite3_config(SQLITE_CONFIG_PAGECACHE, pBuf, sz, N) with non-NULL + ** pBuf argument. + ** + ** * Otherwise use separate caches (mode-1) + */ +#if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) + pcache1.separateCache = 0; +#else + pcache1.separateCache = sqlite3GlobalConfig.pPage==0 + || sqlite3GlobalConfig.bCoreMutex>0; +#endif + #if SQLITE_THREADSAFE if( sqlite3GlobalConfig.bCoreMutex ){ pcache1.grp.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU); @@ -647,31 +673,13 @@ static sqlite3_pcache *pcache1Create(int szPage, int szExtra, int bPurgeable){ PGroup *pGroup; /* The group the new page cache will belong to */ int sz; /* Bytes of memory required to allocate the new cache */ - /* - ** The separateCache variable is true if each PCache has its own private - ** PGroup. In other words, separateCache is true for mode (1) where no - ** mutexing is required. - ** - ** * Always use a unified cache (mode-2) if ENABLE_MEMORY_MANAGEMENT - ** - ** * Always use a unified cache in single-threaded applications - ** - ** * Otherwise (if multi-threaded and ENABLE_MEMORY_MANAGEMENT is off) - ** use separate caches (mode-1) - */ -#if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) || SQLITE_THREADSAFE==0 - const int separateCache = 0; -#else - int separateCache = sqlite3GlobalConfig.bCoreMutex>0; -#endif - assert( (szPage & (szPage-1))==0 && szPage>=512 && szPage<=65536 ); assert( szExtra < 300 ); - sz = sizeof(PCache1) + sizeof(PGroup)*separateCache; + sz = sizeof(PCache1) + sizeof(PGroup)*pcache1.separateCache; pCache = (PCache1 *)sqlite3MallocZero(sz); if( pCache ){ - if( separateCache ){ + if( pcache1.separateCache ){ pGroup = (PGroup*)&pCache[1]; pGroup->mxPinned = 10; }else{ @@ -690,10 +698,9 @@ static sqlite3_pcache *pcache1Create(int szPage, int szExtra, int bPurgeable){ pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage; } pcache1LeaveMutex(pGroup); - if( separateCache - && sqlite3GlobalConfig.szPage==0 - && sqlite3GlobalConfig.nPage!=0 - ){ + /* Try to initialize the local bulk pagecache line allocation if using + ** separate caches and if nPage!=0 */ + if( pcache1.separateCache && sqlite3GlobalConfig.nPage!=0 ){ int szBulk; char *zBulk; sqlite3BeginBenignMalloc(); From c54357cc2ae6ff5526f3dd38c1f28fb633a36117 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 7 Jul 2015 14:06:18 +0000 Subject: [PATCH 3/8] Simplify the page recycling condition in pcache1. Fix test cases to work with the latest changes. FossilOrigin-Name: 5b60df5503f61922326b3e10e94aa197b17afe4b --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/pcache1.c | 9 ++++----- test/memdb.test | 7 +++---- test/memsubsys1.test | 4 +++- test/pcache2.test | 2 ++ 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/manifest b/manifest index 4622da25d7..bd367c068c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C A\sunified\scache\sis\snow\sonly\sused\sfor\sSQLITE_ENABLE_MEMORY_MANAGEMENT,\sor\sif\nSQLITE_CONFIG_PAGECACHE\sdefines\sa\sshared\sstart-time\spage\scache\sbuffer\sand\sthe\napplication\sis\ssingle-threaded. -D 2015-07-06T20:57:22.615 +C Simplify\sthe\spage\srecycling\scondition\sin\spcache1.\s\sFix\stest\scases\sto\swork\nwith\sthe\slatest\schanges. +D 2015-07-07T14:06:18.833 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 017bf0511d1b2dd1db5e16488fbf75a17b526cbc F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -319,7 +319,7 @@ F src/pager.h 6d435f563b3f7fcae4b84433b76a6ac2730036e2 F src/parse.y 6d60dda8f8d418b6dc034f1fbccd816c459983a8 F src/pcache.c cde06aa50962595e412d497e22fd2e07878ba1f0 F src/pcache.h 9968603796240cdf83da7e7bef76edf90619cea9 -F src/pcache1.c 17c392b4208ea6e1e5d220be18bcfebac07110b1 +F src/pcache1.c 1b6bc285d8d6a1a7df41e345cb45914093aecfdf F src/pragma.c c1f4d012ea9f6b1ce52d341b2cd0ad72d560afd7 F src/pragma.h b8632d7cdda7b25323fa580e3e558a4f0d4502cc F src/prepare.c 82e5db1013846a819f198336fed72c44c974e7b1 @@ -843,9 +843,9 @@ F test/mallocL.test 252ddc7eb4fbf75364eab17b938816085ff1fc17 F test/malloc_common.tcl aac62499b76be719fac31e7a3e54a7fd53272e7f F test/manydb.test 28385ae2087967aa05c38624cec7d96ec74feb3e F test/mem5.test c6460fba403c5703141348cd90de1c294188c68f -F test/memdb.test fcb5297b321b562084fc79d64d5a12a1cd2b639b +F test/memdb.test c1f2a343ad14398d5d6debda6ea33e80d0dafcc7 F test/memleak.test 10b9c6c57e19fc68c32941495e9ba1c50123f6e2 -F test/memsubsys1.test 690d142525a7d31efb638b0d232e25fac3afeb1a +F test/memsubsys1.test 1733c617e246642db5bf3b9f78c18e2b14fac96c F test/memsubsys2.test 3a1c1a9de48e5726faa85108b02459fae8cb9ee9 F test/minmax.test 42fbad0e81afaa6e0de41c960329f2b2c3526efd F test/minmax2.test b44bae787fc7b227597b01b0ca5575c7cb54d3bc @@ -900,7 +900,7 @@ F test/pagerfault3.test 1003fcda009bf48a8e22a516e193b6ef0dd1bbd8 F test/pageropt.test 6b8f6a123a5572c195ad4ae40f2987007923bbd6 F test/pagesize.test 5769fc62d8c890a83a503f67d47508dfdc543305 F test/pcache.test b09104b03160aca0d968d99e8cd2c5b1921a993d -F test/pcache2.test a83efe2dec0d392f814bfc998def1d1833942025 +F test/pcache2.test ec3ae192f444ee6a0a80d1fd80d99695d884bfb3 F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff F test/permutations.test 6a88fd9ca15b804e9c20990773262ca67494058f F test/pragma.test be7195f0aa72bdb8a512133e9640ac40f15b57a2 @@ -1364,7 +1364,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P aa7341c8736732a0a59f6688cc34e78be02a7bfc -R ab876e072a5f820e07c8ea2cb7e263ca +P d5ff1d69054d51a55eff6e1979971822db7f8f30 +R 968aaca5a1f6e381bde3c0ae75591e74 U drh -Z d6cf6ae811ec210c263fdd6a92d21a0f +Z 609b7f68c8ef0f31b06857cf6a1355d8 diff --git a/manifest.uuid b/manifest.uuid index d027464ae1..68d4259bf2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d5ff1d69054d51a55eff6e1979971822db7f8f30 \ No newline at end of file +5b60df5503f61922326b3e10e94aa197b17afe4b \ No newline at end of file diff --git a/src/pcache1.c b/src/pcache1.c index c34d0bba1c..71c5971c3a 100644 --- a/src/pcache1.c +++ b/src/pcache1.c @@ -818,11 +818,10 @@ static SQLITE_NOINLINE PgHdr1 *pcache1FetchStage2( assert( pCache->nHash>0 && pCache->apHash ); /* Step 4. Try to recycle a page. */ - if( pCache->bPurgeable && pGroup->pLruTail && ( - (pCache->nPage+1>=pCache->nMax) - || pGroup->nCurrentPage>=pGroup->nMaxPage - || pcache1UnderMemoryPressure(pCache) - )){ + if( pCache->bPurgeable + && pGroup->pLruTail + && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache)) + ){ PCache1 *pOther; pPage = pGroup->pLruTail; assert( pPage->isPinned==0 ); diff --git a/test/memdb.test b/test/memdb.test index a2efc0369b..7bad26f526 100644 --- a/test/memdb.test +++ b/test/memdb.test @@ -419,11 +419,10 @@ ifcapable autovacuum { INSERT INTO t1 VALUES(randstr(1000,1000)); INSERT INTO t1 VALUES(randstr(1000,1000)); } - set memused [lindex [sqlite3_status SQLITE_STATUS_MEMORY_USED 0] 1] - set pgovfl [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 1] + set before [db one {PRAGMA page_count}] execsql { DELETE FROM t1 } - set memused2 [lindex [sqlite3_status SQLITE_STATUS_MEMORY_USED 0] 1] - expr {($memused2 + 2048 < $memused) || $pgovfl==0} + set after [db one {PRAGMA page_count}] + expr {$before>$after} } {1} } diff --git a/test/memsubsys1.test b/test/memsubsys1.test index 891558fd52..3eb3cd4a95 100644 --- a/test/memsubsys1.test +++ b/test/memsubsys1.test @@ -75,6 +75,7 @@ set xtra_size 290 db close sqlite3_shutdown sqlite3_config_lookaside 0 0 +sqlite3_config_pagecache 0 0 sqlite3_initialize reset_highwater_marks build_test_db memsubsys1-1 {PRAGMA page_size=1024} @@ -115,10 +116,10 @@ do_test memsubsys1-2.5 { db close sqlite3_shutdown sqlite3_config_pagecache [expr 512+$xtra_size] 20 +sqlite3_config singlethread sqlite3_initialize reset_highwater_marks build_test_db memsubsys1-3.1 {PRAGMA page_size=1024} -#show_memstats do_test memsubsys1-3.1.3 { set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2] } 0 @@ -312,6 +313,7 @@ sqlite3_config_memstatus 1 sqlite3_config_pagecache 0 0 sqlite3_config_scratch 0 0 sqlite3_config_lookaside 100 500 +sqlite3_config serialized sqlite3_initialize autoinstall_test_functions finish_test diff --git a/test/pcache2.test b/test/pcache2.test index 77e7a26132..1c15b8b56a 100644 --- a/test/pcache2.test +++ b/test/pcache2.test @@ -24,6 +24,7 @@ do_test pcache2-1.1 { sqlite3_reset_auto_extension sqlite3_shutdown sqlite3_config_pagecache 6000 100 + sqlite3_config singlethread sqlite3_initialize autoinstall_test_functions sqlite3_status SQLITE_STATUS_PAGECACHE_USED 1 @@ -73,6 +74,7 @@ catch {db2 close} sqlite3_reset_auto_extension sqlite3_shutdown sqlite3_config_pagecache 0 0 +sqlite3_config serialized sqlite3_initialize autoinstall_test_functions From fd5ae9649c5293d7f05fe8b6b6038663987ee454 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 7 Jul 2015 15:14:16 +0000 Subject: [PATCH 4/8] No need to test sqlite3GlobalConfig.bCoreMutex when SQLITE_THREADSAFE==0. FossilOrigin-Name: 26db0fee06947d75621237a641b9652b312b3b37 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pcache1.c | 4 +++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index bd367c068c..ebdaa318e2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplify\sthe\spage\srecycling\scondition\sin\spcache1.\s\sFix\stest\scases\sto\swork\nwith\sthe\slatest\schanges. -D 2015-07-07T14:06:18.833 +C No\sneed\sto\stest\ssqlite3GlobalConfig.bCoreMutex\swhen\sSQLITE_THREADSAFE==0. +D 2015-07-07T15:14:16.002 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 017bf0511d1b2dd1db5e16488fbf75a17b526cbc F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -319,7 +319,7 @@ F src/pager.h 6d435f563b3f7fcae4b84433b76a6ac2730036e2 F src/parse.y 6d60dda8f8d418b6dc034f1fbccd816c459983a8 F src/pcache.c cde06aa50962595e412d497e22fd2e07878ba1f0 F src/pcache.h 9968603796240cdf83da7e7bef76edf90619cea9 -F src/pcache1.c 1b6bc285d8d6a1a7df41e345cb45914093aecfdf +F src/pcache1.c e3b0de837c9af01335e7e59fa8290dfa9338b2a3 F src/pragma.c c1f4d012ea9f6b1ce52d341b2cd0ad72d560afd7 F src/pragma.h b8632d7cdda7b25323fa580e3e558a4f0d4502cc F src/prepare.c 82e5db1013846a819f198336fed72c44c974e7b1 @@ -1364,7 +1364,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P d5ff1d69054d51a55eff6e1979971822db7f8f30 -R 968aaca5a1f6e381bde3c0ae75591e74 +P 5b60df5503f61922326b3e10e94aa197b17afe4b +R 2d7b920ac2e4dfd8e6b212c060ee3e55 U drh -Z 609b7f68c8ef0f31b06857cf6a1355d8 +Z 96d25228913b7734acfab488bf16d902 diff --git a/manifest.uuid b/manifest.uuid index 68d4259bf2..cd9a67d080 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5b60df5503f61922326b3e10e94aa197b17afe4b \ No newline at end of file +26db0fee06947d75621237a641b9652b312b3b37 \ No newline at end of file diff --git a/src/pcache1.c b/src/pcache1.c index 71c5971c3a..90989bc1db 100644 --- a/src/pcache1.c +++ b/src/pcache1.c @@ -633,9 +633,11 @@ static int pcache1Init(void *NotUsed){ */ #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) pcache1.separateCache = 0; -#else +#elif SQLITE_THREADSAFE pcache1.separateCache = sqlite3GlobalConfig.pPage==0 || sqlite3GlobalConfig.bCoreMutex>0; +#else + pcache1.separateCache = sqlite3GlobalConfig.pPage==0; #endif #if SQLITE_THREADSAFE From 4297c7c4be95f3e6d906a64dd52d2329b45ff17b Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 7 Jul 2015 21:14:42 +0000 Subject: [PATCH 5/8] Add a compile-time constant for configuring the default pagecache setup. FossilOrigin-Name: ad5fdfbac85682f0f0dee62e1086f40026a58be2 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/global.c | 2 +- src/sqliteInt.h | 10 ++++++++++ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index ebdaa318e2..7c9dd2b539 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C No\sneed\sto\stest\ssqlite3GlobalConfig.bCoreMutex\swhen\sSQLITE_THREADSAFE==0. -D 2015-07-07T15:14:16.002 +C Add\sa\scompile-time\sconstant\sfor\sconfiguring\sthe\sdefault\spagecache\ssetup. +D 2015-07-07T21:14:42.575 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 017bf0511d1b2dd1db5e16488fbf75a17b526cbc F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -283,7 +283,7 @@ F src/expr.c c5c58e4d01c7ceb2266791d8d877f1b23a88e316 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c c9b63a217d86582c22121699a47f22f524608869 F src/func.c a98ea5880dc50e9ca6dd6f57079a37b9cfcdecf1 -F src/global.c 32c0ebfdca59db55c761f1405abf7bdfd24ecae0 +F src/global.c 508e4087f7b41d688e4762dcf4d4fe28cfbc87f9 F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 @@ -332,7 +332,7 @@ F src/shell.c 8af3cced094aebb5f57a8ad739b9dafc7867eed7 F src/sqlite.h.in 3d951bf985839de7fcf4d3f69568bb4df2641abe F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h be1a718b7d2ce40ceba725ae92c8eb5f18003066 -F src/sqliteInt.h bc2cb1755150fc0b490d1af23ac2911b03f2f92d +F src/sqliteInt.h d8d420d66a5c403b119696159b69f71cd53840ce F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c f266ad8a2892d659b74f0f50cb6a88b6e7c12179 F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e @@ -1364,7 +1364,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 5b60df5503f61922326b3e10e94aa197b17afe4b -R 2d7b920ac2e4dfd8e6b212c060ee3e55 +P 26db0fee06947d75621237a641b9652b312b3b37 +R eddaba760dcd1fbd940dd405a17b49da U drh -Z 96d25228913b7734acfab488bf16d902 +Z 4021e6ca5eea0db9e457b6c7679c87e9 diff --git a/manifest.uuid b/manifest.uuid index cd9a67d080..799437db10 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -26db0fee06947d75621237a641b9652b312b3b37 \ No newline at end of file +ad5fdfbac85682f0f0dee62e1086f40026a58be2 \ No newline at end of file diff --git a/src/global.c b/src/global.c index 3b1e804bb8..ef4fe56ae1 100644 --- a/src/global.c +++ b/src/global.c @@ -186,7 +186,7 @@ SQLITE_WSD struct Sqlite3Config sqlite3Config = { 0, /* nScratch */ (void*)0, /* pPage */ 0, /* szPage */ - 100, /* nPage */ + SQLITE_DEFAULT_PCACHE_INITSZ, /* nPage */ 0, /* mxParserStack */ 0, /* sharedCacheEnabled */ SQLITE_SORTER_PMASZ, /* szPma */ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index eaf433b7a1..199a1cc662 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -509,6 +509,16 @@ # define SQLITE_MAX_WORKER_THREADS SQLITE_DEFAULT_WORKER_THREADS #endif +/* +** The default initial allocation for the pagecache when using separate +** pagecaches for each database connection. A positive number is the +** number of pages. A negative number N translations means that a buffer +** of -1024*N bytes is allocated and used for as many pages as it will hold. +*/ +#ifndef SQLITE_DEFAULT_PCACHE_INITSZ +# define SQLITE_DEFAULT_PCACHE_INITSZ 100 +#endif + /* ** GCC does not define the offsetof() macro so we'll have to do it From e56d43010dc14f5a0a8651205325e4e15cbb9ff6 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 8 Jul 2015 01:22:52 +0000 Subject: [PATCH 6/8] Avoid left-shifting bits into the sign of a signed integer, as such behavior is technically undefined. FossilOrigin-Name: 9417b4021b779876dcb3b9be636f01f4055eb54e --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 7c9dd2b539..77fde56543 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\scompile-time\sconstant\sfor\sconfiguring\sthe\sdefault\spagecache\ssetup. -D 2015-07-07T21:14:42.575 +C Avoid\sleft-shifting\sbits\sinto\sthe\ssign\sof\sa\ssigned\sinteger,\sas\ssuch\sbehavior\nis\stechnically\sundefined. +D 2015-07-08T01:22:52.331 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 017bf0511d1b2dd1db5e16488fbf75a17b526cbc F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -269,7 +269,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c 4d9134dc988a87838c06056c89c0e8c4700a0452 F src/bitvec.c d1f21d7d91690747881f03940584f4cc548c9d3d F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c 740ab30df845f4a2c2bdb731ed191b4b63b2b2eb +F src/btree.c 781deff0d5af639e8dd4f83ec963cc3bbf8cffc2 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 2ad754dd4528baa8d0946a593cc373b890bf859e F src/build.c b3f15255d5b16e42dafeaa638fd4f8a47c94ed70 @@ -1364,7 +1364,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 26db0fee06947d75621237a641b9652b312b3b37 -R eddaba760dcd1fbd940dd405a17b49da +P ad5fdfbac85682f0f0dee62e1086f40026a58be2 +R ffdb1dc8cf76fb977c83d0c8ad3dcce5 U drh -Z 4021e6ca5eea0db9e457b6c7679c87e9 +Z 1578fd578fb2f64903bdcd3127f0d5d4 diff --git a/manifest.uuid b/manifest.uuid index 799437db10..bd9adfaf63 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ad5fdfbac85682f0f0dee62e1086f40026a58be2 \ No newline at end of file +9417b4021b779876dcb3b9be636f01f4055eb54e \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index f353e8df1f..17c7bb67c3 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9119,7 +9119,7 @@ static int checkTreePage( assert( (u32)i<=usableSize-4 ); /* Enforced by btreeInitPage() */ size = get2byte(&data[i+2]); assert( (u32)(i+size)<=usableSize ); /* Enforced by btreeInitPage() */ - btreeHeapInsert(heap, (i<<16)|(i+size-1)); + btreeHeapInsert(heap, (((u32)i)<<16)|(i+size-1)); /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a ** big-endian integer which is the offset in the b-tree page of the next ** freeblock in the chain, or zero if the freeblock is the last on the From 52d9f40b7def9c5fe30b6b4dd5a1f263b17619ae Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 8 Jul 2015 13:40:50 +0000 Subject: [PATCH 7/8] Do not do the bulk pcache1 allocations if SQLITE_CONFIG_PAGECACHE specifies a global page cache buffer. FossilOrigin-Name: 75d98dae676996a05e97b09b19e34463e8f30d51 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pcache1.c | 5 ++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 77fde56543..d9c3660327 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sleft-shifting\sbits\sinto\sthe\ssign\sof\sa\ssigned\sinteger,\sas\ssuch\sbehavior\nis\stechnically\sundefined. -D 2015-07-08T01:22:52.331 +C Do\snot\sdo\sthe\sbulk\spcache1\sallocations\sif\sSQLITE_CONFIG_PAGECACHE\sspecifies\na\sglobal\spage\scache\sbuffer. +D 2015-07-08T13:40:50.550 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 017bf0511d1b2dd1db5e16488fbf75a17b526cbc F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -319,7 +319,7 @@ F src/pager.h 6d435f563b3f7fcae4b84433b76a6ac2730036e2 F src/parse.y 6d60dda8f8d418b6dc034f1fbccd816c459983a8 F src/pcache.c cde06aa50962595e412d497e22fd2e07878ba1f0 F src/pcache.h 9968603796240cdf83da7e7bef76edf90619cea9 -F src/pcache1.c e3b0de837c9af01335e7e59fa8290dfa9338b2a3 +F src/pcache1.c 1f88fe632a67574e61a4d52f08e21338648c4016 F src/pragma.c c1f4d012ea9f6b1ce52d341b2cd0ad72d560afd7 F src/pragma.h b8632d7cdda7b25323fa580e3e558a4f0d4502cc F src/prepare.c 82e5db1013846a819f198336fed72c44c974e7b1 @@ -1364,7 +1364,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P ad5fdfbac85682f0f0dee62e1086f40026a58be2 -R ffdb1dc8cf76fb977c83d0c8ad3dcce5 +P 9417b4021b779876dcb3b9be636f01f4055eb54e +R dc45b55e45fc287d8da6e081b45bc4d0 U drh -Z 1578fd578fb2f64903bdcd3127f0d5d4 +Z 0743262729e38494d19c03648108bfa3 diff --git a/manifest.uuid b/manifest.uuid index bd9adfaf63..12460e3042 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9417b4021b779876dcb3b9be636f01f4055eb54e \ No newline at end of file +75d98dae676996a05e97b09b19e34463e8f30d51 \ No newline at end of file diff --git a/src/pcache1.c b/src/pcache1.c index 90989bc1db..ed2700852d 100644 --- a/src/pcache1.c +++ b/src/pcache1.c @@ -702,7 +702,10 @@ static sqlite3_pcache *pcache1Create(int szPage, int szExtra, int bPurgeable){ pcache1LeaveMutex(pGroup); /* Try to initialize the local bulk pagecache line allocation if using ** separate caches and if nPage!=0 */ - if( pcache1.separateCache && sqlite3GlobalConfig.nPage!=0 ){ + if( pcache1.separateCache + && sqlite3GlobalConfig.nPage!=0 + && sqlite3GlobalConfig.pPage==0 + ){ int szBulk; char *zBulk; sqlite3BeginBenignMalloc(); From 7b341e6f99cd3981f1a39c1ba2a6e4973eb45e36 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 8 Jul 2015 14:13:44 +0000 Subject: [PATCH 8/8] Comment fix. No changes to code. FossilOrigin-Name: c1e2ed0ef4d3436d19d3203c5fb553caac53659e --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pcache1.c | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index d9c3660327..4fa0ddf103 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\sdo\sthe\sbulk\spcache1\sallocations\sif\sSQLITE_CONFIG_PAGECACHE\sspecifies\na\sglobal\spage\scache\sbuffer. -D 2015-07-08T13:40:50.550 +C Comment\sfix.\s\sNo\schanges\sto\scode. +D 2015-07-08T14:13:44.573 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 017bf0511d1b2dd1db5e16488fbf75a17b526cbc F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -319,7 +319,7 @@ F src/pager.h 6d435f563b3f7fcae4b84433b76a6ac2730036e2 F src/parse.y 6d60dda8f8d418b6dc034f1fbccd816c459983a8 F src/pcache.c cde06aa50962595e412d497e22fd2e07878ba1f0 F src/pcache.h 9968603796240cdf83da7e7bef76edf90619cea9 -F src/pcache1.c 1f88fe632a67574e61a4d52f08e21338648c4016 +F src/pcache1.c 3f4c87cf913f2de8189026d9a5223ddaf55eaf6b F src/pragma.c c1f4d012ea9f6b1ce52d341b2cd0ad72d560afd7 F src/pragma.h b8632d7cdda7b25323fa580e3e558a4f0d4502cc F src/prepare.c 82e5db1013846a819f198336fed72c44c974e7b1 @@ -1364,7 +1364,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 9417b4021b779876dcb3b9be636f01f4055eb54e -R dc45b55e45fc287d8da6e081b45bc4d0 +P 75d98dae676996a05e97b09b19e34463e8f30d51 +R e0f37cdeba600c01a32ef205d5f6df52 U drh -Z 0743262729e38494d19c03648108bfa3 +Z cb924bafedede368f45cad3c12c2aa68 diff --git a/manifest.uuid b/manifest.uuid index 12460e3042..fb850df2b9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -75d98dae676996a05e97b09b19e34463e8f30d51 \ No newline at end of file +c1e2ed0ef4d3436d19d3203c5fb553caac53659e \ No newline at end of file diff --git a/src/pcache1.c b/src/pcache1.c index ed2700852d..a345e6760f 100644 --- a/src/pcache1.c +++ b/src/pcache1.c @@ -41,7 +41,8 @@ ** ** If SQLITE_PCACHE_SEPARATE_HEADER is defined, then the extension is obtained ** using a separate memory allocation from the database page content. This -** seeks to overcome the "clownfoot" problem of allocating a few bytes more +** seeks to overcome the "clownshoe" problem (also called "internal +** fragmentation" in academic literature) of allocating a few bytes more ** than a power of two with the memory allocator rounding up to the next ** power of two, and leaving the rounded-up space unused. **