From: drh Date: Wed, 9 Nov 2011 14:23:04 +0000 (+0000) Subject: A negative value N for the cache_size pragma adjusts the number of cache X-Git-Tag: mountain-lion~9^2~17^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3b42abb35b19df09b5f37877161a8eed8ee1e118;p=thirdparty%2Fsqlite.git A negative value N for the cache_size pragma adjusts the number of cache pages to use approximately N kibibytes of memory. FossilOrigin-Name: b3faa680aedc94ed8aa2819228c0d304b181cc51 --- diff --git a/manifest b/manifest index fc92f8fff3..9fb4c8839b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C For\sthe\smem1.c\ssystem\smalloc\simplementation,\suse\sthe\smalloc_usable_size()\nfunction\sif\sthe\sHAVE_MALLOC_USABLE_SIZE\smacro\sis\sdefined.\s\sUpdate\sautoconf\nto\slook\sfor\sthat\sfunction\swhen\sconfiguring. -D 2011-11-09T01:53:25.593 +C A\snegative\svalue\sN\sfor\sthe\scache_size\spragma\sadjusts\sthe\snumber\sof\scache\npages\sto\suse\sapproximately\sN\skibibytes\sof\smemory. +D 2011-11-09T14:23:04.394 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5b4a3e12a850b021547e43daf886b25133b44c07 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -171,10 +171,10 @@ F src/os_win.c 49d418916428a59d773f39993db0ecde56ab4c37 F src/pager.c db33d4bf1e3e019c34c220971cc6c3aa07c30f54 F src/pager.h 9f81b08efb06db4ba8be69446e10b005c351373d F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58 -F src/pcache.c 8820564f6e32842190f06df545d964a5491ddae4 +F src/pcache.c b9d52e9f844d91c27c161279234f273fc02abc71 F src/pcache.h c770382f9fae4ca5025c5523bd0aa13cd6ddc6f8 F src/pcache1.c 9a42ace8022b3d38175c3b41802aa9bccd9c6a3a -F src/pragma.c da8ef96b3eec351e81e0061c39810e548bcc96d7 +F src/pragma.c c5ba7627fbdedc02c7b8f52e77a3bceb030cf5ed F src/prepare.c e64261559a3187698a3e7e6c8b001a4f4f98dab4 F src/printf.c 03104cbff6959ff45df69dc9060ba6212f60a869 F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 @@ -627,7 +627,7 @@ F test/pagesize.test 1dd51367e752e742f58e861e65ed7390603827a0 F test/pcache.test 065aa286e722ab24f2e51792c1f093bf60656b16 F test/pcache2.test a83efe2dec0d392f814bfc998def1d1833942025 F test/permutations.test 522823b47238cb1754198f80817fe9f9158ede55 -F test/pragma.test 1ea0c85be853135bb7468e6eed48ee12b04794d4 +F test/pragma.test 7fa35e53085812dac94c2bfcbb02c2a4ad35df5e F test/pragma2.test 3a55f82b954242c642f8342b17dffc8b47472947 F test/printf.test ec9870c4dce8686a37818e0bf1aba6e6a1863552 F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301 @@ -974,7 +974,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 -P 4da7095683ec821414e255419d63a24dbd9d726d -R c213b277008496abb081e494c07b96f8 +P 2e8ab3cedfebc33a831837792b523d1aa7cdc6b7 +R f79cb2e5e3c648503ef136bcf9a7e813 U drh -Z adde38f0bee72bcf55d83cbeb4f89a8f +Z ee913c4e43d90078be9388d453dfd115 diff --git a/manifest.uuid b/manifest.uuid index 88ba491fc8..a97b46c07b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2e8ab3cedfebc33a831837792b523d1aa7cdc6b7 \ No newline at end of file +b3faa680aedc94ed8aa2819228c0d304b181cc51 \ No newline at end of file diff --git a/src/pcache.c b/src/pcache.c index 6c68ddee61..a504633919 100644 --- a/src/pcache.c +++ b/src/pcache.c @@ -20,7 +20,7 @@ struct PCache { PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */ PgHdr *pSynced; /* Last synced page in dirty page list */ int nRef; /* Number of referenced pages */ - int nMax; /* Configured cache size */ + int szCache; /* Configured cache size */ int szPage; /* Size of every page in this cache */ int szExtra; /* Size of extra space for each page */ int bPurgeable; /* True if pages are on backing store */ @@ -181,7 +181,7 @@ void sqlite3PcacheOpen( p->bPurgeable = bPurgeable; p->xStress = xStress; p->pStress = pStress; - p->nMax = 100; + p->szCache = 100; } /* @@ -198,6 +198,17 @@ void sqlite3PcacheSetPageSize(PCache *pCache, int szPage){ pCache->szPage = szPage; } +/* +** Compute the number of pages of cache requested. +*/ +static int numberOfCachePages(PCache *p){ + if( p->szCache>=0 ){ + return p->szCache; + }else{ + return (-1024*p->szCache)/(p->szPage+p->szExtra); + } +} + /* ** Try to obtain a page from the cache. */ @@ -226,7 +237,7 @@ int sqlite3PcacheFetch( if( !p ){ return SQLITE_NOMEM; } - sqlite3GlobalConfig.pcache2.xCachesize(p, pCache->nMax); + sqlite3GlobalConfig.pcache2.xCachesize(p, numberOfCachePages(pCache)); pCache->pCache = p; } @@ -259,7 +270,7 @@ int sqlite3PcacheFetch( "spill page %d making room for %d - cache used: %d/%d", pPg->pgno, pgno, sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache), - pCache->nMax); + numberOfCachePages(pCache)); #endif rc = pCache->xStress(pCache->pStress, pPg); if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){ @@ -569,7 +580,7 @@ int sqlite3PcachePagecount(PCache *pCache){ ** Get the suggested cache-size value. */ int sqlite3PcacheGetCachesize(PCache *pCache){ - return pCache->nMax; + return numberOfCachePages(pCache); } #endif @@ -577,9 +588,10 @@ int sqlite3PcacheGetCachesize(PCache *pCache){ ** Set the suggested cache-size value. */ void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){ - pCache->nMax = mxPage; + pCache->szCache = mxPage; if( pCache->pCache ){ - sqlite3GlobalConfig.pcache2.xCachesize(pCache->pCache, mxPage); + sqlite3GlobalConfig.pcache2.xCachesize(pCache->pCache, + numberOfCachePages(pCache)); } } diff --git a/src/pragma.c b/src/pragma.c index 13a973347b..5f33ee99d7 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -684,14 +684,11 @@ void sqlite3Pragma( ** PRAGMA [database.]cache_size=N ** ** The first form reports the current local setting for the - ** page cache size. The local setting can be different from - ** the persistent cache size value that is stored in the database - ** file itself. The value returned is the maximum number of - ** pages in the page cache. The second form sets the local - ** page cache size value. It does not change the persistent - ** cache size stored on the disk so the cache size will revert - ** to its default value when the database is closed and reopened. - ** N should be a positive integer. + ** page cache size. The second form sets the local + ** page cache size value. If N is positive then that is the + ** number of pages in the cache. If N is negative, then the + ** number of pages is adjusted so that the cache uses -N kibibytes + ** of memory. */ if( sqlite3StrICmp(zLeft,"cache_size")==0 ){ if( sqlite3ReadSchema(pParse) ) goto pragma_out; @@ -699,7 +696,7 @@ void sqlite3Pragma( if( !zRight ){ returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size); }else{ - int size = sqlite3AbsInt32(sqlite3Atoi(zRight)); + int size = sqlite3Atoi(zRight); pDb->pSchema->cache_size = size; sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); } diff --git a/test/pragma.test b/test/pragma.test index 0cad25a37d..cbe35ea806 100644 --- a/test/pragma.test +++ b/test/pragma.test @@ -99,7 +99,7 @@ do_test pragma-1.5 { PRAGMA default_cache_size; PRAGMA synchronous; } -} [list 4321 $DFLT_CACHE_SZ 0] +} [list -4321 $DFLT_CACHE_SZ 0] do_test pragma-1.6 { execsql { PRAGMA synchronous=ON; @@ -107,7 +107,7 @@ do_test pragma-1.6 { PRAGMA default_cache_size; PRAGMA synchronous; } -} [list 4321 $DFLT_CACHE_SZ 1] +} [list -4321 $DFLT_CACHE_SZ 1] do_test pragma-1.7 { db close sqlite3 db test.db