Refactoring the mmap interface. The controlling pragma is now "mmap_size"

instead of "mmap_limit".  Also change SQLITE_CONFIG_MMAP_LIMIT and
SQLITE_FCNTL_MMAP_LIMIT to SQLITE_CONFIG_MMAP_SIZE and
SQLITE_FCNTL_MMAP_SIZE, respecctively.  
The default mmap_size is now always 0, meaning that
memory mapped I/O is off by default.  There is a new compile-time option
SQLITE_MAX_MMAP_SIZE that determines a hard upper bound on the mmap_size.
Setting SQLITE_MAX_MMAP_SIZE to zero disables the memory-mapped I/O logic
and causes it to be omitted from the build.  An extra argument is added
to SQLITE_CONFIG_MMAP_SIZE that can optionally lower the SQLITE_MAX_MMAP_SIZE
at start-time. The SQLITE_MAX_MMAP_SIZE is zero for platforms where we 
know that it does not work, meaning that it cannot be turned on by mistake
on those platforms.

FossilOrigin-Name: ea1404a10abd7f68e1f8e0708c8a3199d1f79665
This commit is contained in:
drh 2013-04-15 17:03:42 +00:00
parent a1710cc2ea
commit 9b4c59fa1b
31 changed files with 245 additions and 213 deletions

View File

@ -1,5 +1,5 @@
C Fix\sa\sformatting\stypo\sin\sa\scomment.\s\sNo\schanges\sto\scode.
D 2013-04-15T13:10:30.554
C Refactoring\sthe\smmap\sinterface.\s\sThe\scontrolling\spragma\sis\snow\s"mmap_size"\ninstead\sof\s"mmap_limit".\s\sAlso\schange\sSQLITE_CONFIG_MMAP_LIMIT\sand\nSQLITE_FCNTL_MMAP_LIMIT\sto\sSQLITE_CONFIG_MMAP_SIZE\sand\nSQLITE_FCNTL_MMAP_SIZE,\srespecctively.\s\s\nThe\sdefault\smmap_size\sis\snow\salways\s0,\smeaning\sthat\nmemory\smapped\sI/O\sis\soff\sby\sdefault.\s\sThere\sis\sa\snew\scompile-time\soption\nSQLITE_MAX_MMAP_SIZE\sthat\sdetermines\sa\shard\supper\sbound\son\sthe\smmap_size.\nSetting\sSQLITE_MAX_MMAP_SIZE\sto\szero\sdisables\sthe\smemory-mapped\sI/O\slogic\nand\scauses\sit\sto\sbe\somitted\sfrom\sthe\sbuild.\s\sAn\sextra\sargument\sis\sadded\nto\sSQLITE_CONFIG_MMAP_SIZE\sthat\scan\soptionally\slower\sthe\sSQLITE_MAX_MMAP_SIZE\nat\sstart-time.\sThe\sSQLITE_MAX_MMAP_SIZE\sis\szero\sfor\splatforms\swhere\swe\s\nknow\sthat\sit\sdoes\snot\swork,\smeaning\sthat\sit\scannot\sbe\sturned\son\sby\smistake\non\sthose\splatforms.
D 2013-04-15T17:03:42.119
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 3dd3fcb87b70c78d99b2c8a03e44ec86d6ca9ce2
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -110,8 +110,8 @@ F mkextw.sh 4123480947681d9b434a5e7b1ee08135abe409ac
F mkopcodec.awk f6fccee29e68493bfd90a2e0466ede5fa94dd2fc
F mkopcodeh.awk 29b84656502eee5f444c3147f331ee686956ab0e
F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83
F mptest/config01.test 3f4ddeb152a4f83872f0fa7fcb48d9fd609893da
F mptest/config02.test 962913ed2b537d60de4126db7fe54716865cdd22
F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271
F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504
F mptest/crash01.test a5f31998ed48de8267d6620e8af107ec148e5f12
F mptest/crash02.subtest f4ef05adcd15d60e5d2bd654204f2c008b519df8
F mptest/mptest.c 2a263e88f18762ac5d7fb56749d2d2ea8e22cb93
@ -127,20 +127,20 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
F src/backup.c b266767351ae2d847716c56fcb2a1fea7c761c03
F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb
F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7
F src/btree.c 5f2c4fe72f663bba837c5d01a732799c1d1c93f8
F src/btree.c 480a6d255cc4f066029daf23dd54acf152cd0e13
F src/btree.h d9490cd37aaeb530a41b07f06e1262950b1be916
F src/btreeInt.h eecc84f02375b2bb7a44abbcbbe3747dde73edb2
F src/build.c 083da8466fd7e481cb8bd5264398f537507f6176
F src/callback.c d7e46f40c3cf53c43550b7da7a1d0479910b62cc
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
F src/ctime.c 61a53c7e0db5e7ba60cf23b73deaf6779aa715d3
F src/ctime.c 726e88b7282e7f348f805437db3222f97a136d35
F src/date.c 067a81c9942c497aafd2c260e13add8a7d0c7dd4
F src/delete.c aeabdabeeeaa0584127f291baa9617153d334778
F src/expr.c 48048fca951eedbc74aa32262154410d56c83812
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
F src/fkey.c e16942bd5c8a868ac53287886464a5ed0e72b179
F src/func.c d3fdcff9274bc161152e67ed3f626841c247f4b9
F src/global.c d2494a1cea8f66a2cab8258449df07f8f0ae6330
F src/global.c 5caf4deab621abb45b4c607aad1bd21c20aac759
F src/hash.c ac3470bbf1ca4ae4e306a8ecb0fdf1731810ffe4
F src/hash.h 8890a25af81fb85a9ad7790d32eedab4b994da22
F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08
@ -149,7 +149,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d
F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12
F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b
F src/loadext.c 1422eba4aa2b1fb5f7b3aef574752272477d21e2
F src/main.c 54a841854734b6731c4d026834788cac6a19f3d1
F src/main.c de47c3e6b68f512b9e64ba2533ee4eecc9d501c1
F src/malloc.c fe085aa851b666b7c375c1ff957643dc20a04bf6
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
F src/mem1.c 437c7c4af964895d4650f29881df63535caaa1fa
@ -163,30 +163,30 @@ F src/mutex_noop.c 7682796b7d8d39bf1c138248858efcd10c9e1553
F src/mutex_unix.c c3a4e00f96ba068a8dbef34084465979aaf369cc
F src/mutex_w32.c 32a9b3841e2d757355f0012b860b1bc5e01eafa0
F src/notify.c 976dd0f6171d4588e89e874fcc765e92914b6d30
F src/os.c ca679b293a6233327e418fd1dde2cd5db3e90932
F src/os.c b4ad71336fd96f97776f75587cd9e8218288f5be
F src/os.h ae08bcc5f6ec6b339f4a2adf3931bb88cc14c3e4
F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
F src/os_unix.c 5707fcb125f043e2d3376ea862e8ec83633c5e0e
F src/os_win.c 426563476ac4b0939c1bb2a59c6330e6864db5b0
F src/pager.c 28f45e60d9a173368872d6e688e7a848c3926344
F src/os_unix.c 0a561eae5965c9371300b0419027f5ae9f847af2
F src/os_win.c 873bbc5dff8eb9f2bf8d9287d29df082eacb8391
F src/pager.c a55adacb1842b83354198c408e7adde95ecd1189
F src/pager.h 5cb78b8e1adfd5451e600be7719f5a99d87ac3b1
F src/parse.y 5d5e12772845805fdfeb889163516b84fbb9ae95
F src/pcache.c f8043b433a57aba85384a531e3937a804432a346
F src/pcache.h a5e4f5d9f5d592051d91212c5949517971ae6222
F src/pcache1.c 9fd22671c270b35131ef480bbc00392b8b5f8ab9
F src/pragma.c 216d6c24520f7b2e267a2356e5d3269d28690f49
F src/pragma.c 3eacf001cbf4becbd494f8d82d08fdf1648cf8cb
F src/prepare.c 743e484233c51109666d402f470523553b41797c
F src/printf.c 4a9f882f1c1787a8b494a2987765acf9d97ac21f
F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50
F src/resolve.c 10a1b332e3eb36e5d561085e18c58a8578cd7d73
F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0
F src/select.c 01540bcd3df3c8f1187158e77986028b1c667258
F src/shell.c 319b7791cee6c763b60fde1b590bfaf62613cf37
F src/sqlite.h.in 696ecfc764a32b47daaaf0e10438ff2aaa0739e0
F src/shell.c 06bca04044b312ccadc43bf72385e7440cf60d1b
F src/sqlite.h.in d897fd15b9c74d4e78e4c42319484ceb1649c5d7
F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0
F src/sqlite3ext.h 7183ab832e23db0f934494f16928da127a571d75
F src/sqliteInt.h 7580edf7e7e13af8dff6152666e4ea32535abf8c
F src/sqliteLimit.h 3ea5c07b370b8033c30f66515ccf4e875c252429
F src/sqliteInt.h 9933ad95b2c1e017f16428e9c0a929867598c2ae
F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
F src/status.c bedc37ec1a6bb9399944024d63f4c769971955a9
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
F src/tclsqlite.c 9a716c737590d2f129d71c8fc7065e5aba0e7222
@ -203,7 +203,7 @@ F src/test_async.c 0612a752896fad42d55c3999a5122af10dcf22ad
F src/test_autoext.c 30e7bd98ab6d70a62bb9ba572e4c7df347fe645e
F src/test_backup.c c129c91127e9b46e335715ae2e75756e25ba27de
F src/test_btree.c 5b89601dcb42a33ba8b820a6b763cc9cb48bac16
F src/test_config.c b6f5d680f0cf03d0ae9d6165bd2e447d9b356e4a
F src/test_config.c 49c99b714c1dab68aa6b37d53681a4278982be8d
F src/test_demovfs.c 20a4975127993f4959890016ae9ce5535a880094
F src/test_devsym.c e7498904e72ba7491d142d5c83b476c4e76993bc
F src/test_fs.c 8f786bfd0ad48030cf2a06fb1f050e9c60a150d7
@ -376,7 +376,7 @@ F test/cse.test 277350a26264495e86b1785f34d2d0c8600e021c
F test/ctime.test 7bd009071e242aac4f18521581536b652b789a47
F test/date.test f3228180c87bbe5d39c9397bf001c0095c3821b9
F test/dbstatus.test 207e5b63fcb7b9c3bb8e1fdf38ebd4654ad0e54b
F test/dbstatus2.test f329941d5f4a8bc0ba6ec5735897ef0cf34e2f5f
F test/dbstatus2.test 10418e62b3db5dca070f0c3eef3ea13946f339c2
F test/default.test 6faf23ccb300114924353007795aa9a8ec0aa9dc
F test/delete.test a065b05d2ebf60fd16639c579a4adfb7c381c701
F test/delete2.test 3a03f2cca1f9a67ec469915cb8babd6485db43fa
@ -410,7 +410,7 @@ F test/eqp.test 46aa946dd55c90635327898275d3e533d23a9845
F test/errmsg.test 050717f1c6a5685de9c79f5f9f6b83d7c592f73a
F test/eval.test bc269c365ba877554948441e91ad5373f9f91be3
F test/exclusive.test a1b324cb21834a490cd052d409d34789cfef57cb
F test/exclusive2.test 354bdabe299a2546c898dff42f79079ff1590d88
F test/exclusive2.test 881193eccec225cfed9d7f744b65e57f26adee25
F test/exec.test e949714dc127eaa5ecc7d723efec1ec27118fdd7
F test/exists.test 8f7b27b61c2fbe5822f0a1f899c715d14e416e30
F test/expr.test 67c9fd6f8f829e239dc8b0f4a08a73c08b09196d
@ -515,7 +515,7 @@ F test/fts4merge2.test 5faa558d1b672f82b847d2a337465fa745e46891
F test/fts4merge3.test aab02a09f50fe6baaddc2e159c3eabc116d45fc7
F test/fts4unicode.test 25ccad45896f8e50f6a694cff738a35f798cdb40
F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d
F test/func.test a4f24707e6af0bcd4cb5b856af4462db40b047b1
F test/func.test b0fc34fdc36897769651975a2b0a606312753643
F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f
F test/func3.test 001021e5b88bd02a3b365a5c5fd8f6f49d39744a
F test/fuzz-oss1.test 4912e528ec9cf2f42134456933659d371c9e0d74
@ -533,7 +533,7 @@ F test/in2.test 5d4c61d17493c832f7d2d32bef785119e87bde75
F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0
F test/in4.test 64f3cc1acde1b9161ccdd8e5bde3daefdb5b2617
F test/in5.test 99f9a40af01711b06d2d614ecfe96129f334fba3
F test/incrblob.test 2100cb8964e4a106e5ca9bf80e2c5c3e8be33f77
F test/incrblob.test e81846d214f3637622620fbde7cd526781cfe328
F test/incrblob2.test edc3a96e557bd61fb39acc8d2edd43371fbbaa19
F test/incrblob3.test aedbb35ea1b6450c33b98f2b6ed98e5020be8dc7
F test/incrblob4.test 09be37d3dd996a31ea6993bba7837ece549414a8
@ -637,7 +637,7 @@ F test/misc5.test 528468b26d03303b1f047146e5eefc941b9069f5
F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91
F test/misc7.test dd82ec9250b89178b96cd28b2aca70639d21e5b3
F test/misuse.test ba4fb5d1a6101d1c171ea38b3c613d0661c83054
F test/mmap1.test f064a9025136cd688c982ccdae81c7b4fac95724
F test/mmap1.test 0b5802cf64acaa509ea889b3c708196cc6eb9d31
F test/mmap2.test a5ba639f90b5fc487400a49e158e14e465943e98
F test/multiplex.test e08cc7177bd6d85990ee1d71100bb6c684c02256
F test/multiplex2.test 580ca5817c7edbe4cc68fa150609c9473393003a
@ -657,17 +657,17 @@ F test/orderby2.test bc11009f7cd99d96b1b11e57b199b00633eb5b04
F test/orderby3.test 8619d06a3debdcd80a27c0fdea5c40b468854b99
F test/orderby4.test 4d39bfbaaa3ae64d026ca2ff166353d2edca4ba4
F test/oserror.test 50417780d0e0d7cd23cf12a8277bb44024765df3
F test/pager1.test 134144862f6a98f862dc2edda1b10ff499141bfa
F test/pager1.test 30e63afd425fea12285e9ec5fa1fd000808031f1
F test/pager2.test 67b8f40ae98112bcdba1f2b2d03ea83266418c71
F test/pager3.test 3856d9c80839be0668efee1b74811b1b7f7fc95f
F test/pagerfault.test bba948be0564254b823ec6ca1fd95fbbfb0839a3
F test/pagerfault.test 8483e65d33d5636e5b7656204bb274d826e728d9
F test/pagerfault2.test 1f79ea40d1133b2683a2f811b00f2399f7ec2401
F test/pagerfault3.test f16e2efcb5fc9996d1356f7cbc44c998318ae1d7
F test/pageropt.test d6b695e6c12290c406150fc51eec32878d48df4c
F test/pageropt.test 6b8f6a123a5572c195ad4ae40f2987007923bbd6
F test/pagesize.test 1dd51367e752e742f58e861e65ed7390603827a0
F test/pcache.test 065aa286e722ab24f2e51792c1f093bf60656b16
F test/pcache2.test a83efe2dec0d392f814bfc998def1d1833942025
F test/permutations.test b6cb45ce4d3193b831231025c9d30c77317dd240
F test/permutations.test d2918e9ee6d0008292e5a70e90eed23b0440ca88
F test/pragma.test 60d29cd3d8098a2c20bf4c072810f99e3bf2757a
F test/pragma2.test 3a55f82b954242c642f8342b17dffc8b47472947
F test/printf.test ec9870c4dce8686a37818e0bf1aba6e6a1863552
@ -758,7 +758,7 @@ F test/substr.test 18f57c4ca8a598805c4d64e304c418734d843c1a
F test/superlock.test 1cde669f68d2dd37d6c9bd35eee1d95491ae3fc2
F test/sync.test a34cd43e98b7fb84eabbf38f7ed8f7349b3f3d85
F test/syscall.test a653783d985108c4912cc64d341ffbbb55ad2806
F test/sysfault.test 503f72712b2b21cb80dc9899e53c2e39484d0313
F test/sysfault.test fa776e60bf46bdd3ae69f0b73e46ee3977a58ae6
F test/table.test a59d985ca366e39b17b175f387f9d5db5a18d4e2
F test/tableapi.test 2674633fa95d80da917571ebdd759a14d9819126
F test/tclsqlite.test 37a61c2da7e3bfe3b8c1a2867199f6b860df5d43
@ -962,11 +962,11 @@ F test/vtabF.test fd5ad376f5a34fe0891df1f3cddb4fe7c3eb077e
F test/vtab_alter.test 9e374885248f69e251bdaacf480b04a197f125e5
F test/vtab_err.test 0d4d8eb4def1d053ac7c5050df3024fd47a3fbd8
F test/vtab_shared.test 82f463886e18d7f8395a4b6167c91815efe54839
F test/wal.test 20fb8d0f8e65e50eb675994cc3a4f0e692fd4faf
F test/wal.test 0b4837cd5e9283c116d30810a6859bed7425a95e
F test/wal2.test d4b470f13c87f6d8268b004380afa04c3c67cb90
F test/wal3.test b22eb662bcbc148c5f6d956eaf94b047f7afe9c0
F test/wal4.test 4744e155cd6299c6bd99d3eab1c82f77db9cdb3c
F test/wal5.test 13c980d4d8d2d6b558361f19bed4ab31d41a2c7c
F test/wal5.test 8f888b50f66b78821e61ed0e233ded5de378224b
F test/wal6.test 2e3bc767d9c2ce35c47106148d43fcbd072a93b3
F test/wal7.test 2ae8f427d240099cc4b2dfef63cff44e2a68a1bd
F test/wal8.test b3ee739fe8f7586aaebdc2367f477ebcf3e3b034
@ -1004,7 +1004,7 @@ F test/whereD.test 3f3ee93825c94804f1fc91eef2de0d365981759a
F test/whereE.test 7bd34945797efef15819368479bacc34215e4e1d
F test/whereF.test a0e296643cabe5278379bc1a0aa158cf3c54a1c9
F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31
F test/win32lock.test 21810396eee150680cc398970839e6abdcb807b9
F test/win32lock.test 7a6bd73a5dcdee39b5bb93e92395e1773a194361
F test/zeroblob.test caaecfb4f908f7bc086ed238668049f96774d688
F test/zerodamage.test e7f77fded01dfcdf92ac2c5400f1e35d7a21463c
F tool/build-all-msvc.bat 74fb6e5cca66ebdb6c9bbafb2f8b802f08146d38 x
@ -1051,7 +1051,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
P d0d5af79a005de30194863c57c5018ee75e03581
R 18db1cd249206022b16580a94625cafa
P 3412424990c93d2978e819e6099811f1cdde316d
R aa0c6ea54adf9732b395ebf6e1c98243
U drh
Z 4a78dc5e25d8c90b818007b69b504f95
Z 71eb761a9109889dcfada6d3231b23c2

View File

@ -1 +1 @@
3412424990c93d2978e819e6099811f1cdde316d
ea1404a10abd7f68e1f8e0708c8a3199d1f79665

View File

@ -5,11 +5,11 @@
PRAGMA page_size=8192;
--task 1
PRAGMA journal_mode=PERSIST;
PRAGMA mmap_limit=0;
PRAGMA mmap_size=0;
--end
--task 2
PRAGMA journal_mode=TRUNCATE;
PRAGMA mmap_limit=28672;
PRAGMA mmap_size=28672;
--end
--task 3
PRAGMA journal_mode=MEMORY;
@ -17,6 +17,9 @@ PRAGMA page_size=8192;
--task 4
PRAGMA journal_mode=OFF;
--end
--task 4
PRAGMA mmap_size(268435456);
--end
--source multiwrite01.test
--wait all
PRAGMA page_size=16384;

View File

@ -3,16 +3,19 @@
*/
PRAGMA page_size=512;
--task 1
PRAGMA mmap_limit=0;
PRAGMA mmap_size=0;
--end
--task 2
PRAGMA mmap_limit=28672;
PRAGMA mmap_size=28672;
--end
--task 3
PRAGMA mmap_limit=8192;
PRAGMA mmap_size=8192;
--end
--task 4
PRAGMA mmap_limit=65536;
PRAGMA mmap_size=65536;
--end
--task 5
PRAGMA mmap_size=268435456;
--end
--source multiwrite01.test
--source crash02.subtest

View File

@ -1876,7 +1876,7 @@ int sqlite3BtreeOpen(
rc = sqlite3PagerOpen(pVfs, &pBt->pPager, zFilename,
EXTRA_SIZE, flags, vfsFlags, pageReinit);
if( rc==SQLITE_OK ){
sqlite3PagerSetMmapLimit(pBt->pPager, db->mxMmap);
sqlite3PagerSetMmapLimit(pBt->pPager, db->szMmap);
rc = sqlite3PagerReadFileheader(pBt->pPager,sizeof(zDbHeader),zDbHeader);
}
if( rc!=SQLITE_OK ){
@ -2147,11 +2147,11 @@ int sqlite3BtreeSetCacheSize(Btree *p, int mxPage){
** Change the limit on the amount of the database file that may be
** memory mapped.
*/
int sqlite3BtreeSetMmapLimit(Btree *p, sqlite3_int64 mxMmap){
int sqlite3BtreeSetMmapLimit(Btree *p, sqlite3_int64 szMmap){
BtShared *pBt = p->pBt;
assert( sqlite3_mutex_held(p->db->mutex) );
sqlite3BtreeEnter(p);
sqlite3PagerSetMmapLimit(pBt->pPager, mxMmap);
sqlite3PagerSetMmapLimit(pBt->pPager, szMmap);
sqlite3BtreeLeave(p);
return SQLITE_OK;
}

View File

@ -57,8 +57,8 @@ static const char * const azCompileOpt[] = {
#ifdef SQLITE_DEFAULT_LOCKING_MODE
"DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE),
#endif
#ifdef SQLITE_DEFAULT_MMAP_LIMIT
"DEFAULT_MMAP_LIMIT=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_LIMIT),
#ifdef SQLITE_DEFAULT_MMAP_SIZE
"DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE),
#endif
#ifdef SQLITE_DISABLE_DIRSYNC
"DISABLE_DIRSYNC",
@ -66,9 +66,6 @@ static const char * const azCompileOpt[] = {
#ifdef SQLITE_DISABLE_LFS
"DISABLE_LFS",
#endif
#ifdef SQLITE_DISABLE_MMAP
"DISABLE_MMAP",
#endif
#ifdef SQLITE_ENABLE_ATOMIC_WRITE
"ENABLE_ATOMIC_WRITE",
#endif
@ -153,6 +150,9 @@ static const char * const azCompileOpt[] = {
#ifdef SQLITE_LOCK_TRACE
"LOCK_TRACE",
#endif
#ifdef SQLITE_MAX_MMAP_SIZE
"MAX_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE),
#endif
#ifdef SQLITE_MAX_SCHEMA_RETRY
"MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY),
#endif

View File

@ -156,7 +156,8 @@ SQLITE_WSD struct Sqlite3Config sqlite3Config = {
(void*)0, /* pHeap */
0, /* nHeap */
0, 0, /* mnHeap, mxHeap */
SQLITE_DEFAULT_MMAP_LIMIT, /* mxMmap */
SQLITE_DEFAULT_MMAP_SIZE, /* szMmap */
SQLITE_MAX_MMAP_SIZE, /* mxMmap */
(void*)0, /* pScratch */
0, /* szScratch */
0, /* nScratch */

View File

@ -496,10 +496,16 @@ int sqlite3_config(int op, ...){
}
#endif
case SQLITE_CONFIG_MMAP_LIMIT: {
case SQLITE_CONFIG_MMAP_SIZE: {
sqlite3_int64 szMmap = va_arg(ap, sqlite3_int64);
sqlite3_int64 mxMmap = va_arg(ap, sqlite3_int64);
if( mxMmap<0 ) mxMmap = SQLITE_DEFAULT_MMAP_LIMIT;
if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ){
mxMmap = SQLITE_MAX_MMAP_SIZE;
}
sqlite3GlobalConfig.mxMmap = mxMmap;
if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
if( szMmap>mxMmap) szMmap = mxMmap;
sqlite3GlobalConfig.szMmap = szMmap;
break;
}
@ -2323,7 +2329,7 @@ static int openDatabase(
memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
db->autoCommit = 1;
db->nextAutovac = -1;
db->mxMmap = sqlite3GlobalConfig.mxMmap;
db->szMmap = sqlite3GlobalConfig.szMmap;
db->nextPagesize = 0;
db->flags |= SQLITE_ShortColNames | SQLITE_AutoIndex | SQLITE_EnableTrigger
#if SQLITE_DEFAULT_FILE_FORMAT<4

View File

@ -141,7 +141,7 @@ int sqlite3OsShmMap(
return id->pMethods->xShmMap(id, iPage, pgsz, bExtend, pp);
}
#if !defined(SQLITE_DISABLE_MMAP)
#if SQLITE_MAX_MMAP_SIZE>0
/* The real implementation of xFetch and xUnfetch */
int sqlite3OsFetch(sqlite3_file *id, i64 iOff, int iAmt, void **pp){
DO_OS_MALLOC_TEST(id);

View File

@ -227,8 +227,8 @@ struct unixFile {
int szChunk; /* Configured by FCNTL_CHUNK_SIZE */
int nFetchOut; /* Number of outstanding xFetch refs */
sqlite3_int64 mmapSize; /* Usable size of mapping at pMapRegion */
sqlite3_int64 mmapOrigsize; /* Actual size of mapping at pMapRegion */
sqlite3_int64 mmapLimit; /* Configured FCNTL_MMAP_LIMIT value */
sqlite3_int64 mmapSizeActual; /* Actual size of mapping at pMapRegion */
sqlite3_int64 mmapSizeMax; /* Configured FCNTL_MMAP_SIZE value */
void *pMapRegion; /* Memory mapped region */
#ifdef __QNXNTO__
int sectorSize; /* Device sector size */
@ -3162,7 +3162,7 @@ static int unixRead(
);
#endif
#if !defined(SQLITE_DISABLE_MMAP)
#if SQLITE_MAX_MMAP_SIZE>0
/* Deal with as much of this read request as possible by transfering
** data from the memory mapping using memcpy(). */
if( offset<pFile->mmapSize ){
@ -3283,7 +3283,7 @@ static int unixWrite(
}
#endif
#if !defined(SQLITE_DISABLE_MMAP)
#if SQLITE_MAX_MMAP_SIZE>0
/* Deal with as much of this write request as possible by transfering
** data from the memory mapping using memcpy(). */
if( offset<pFile->mmapSize ){
@ -3678,7 +3678,7 @@ static int fcntlSizeHint(unixFile *pFile, i64 nByte){
}
}
if( pFile->mmapLimit>0 && nByte>pFile->mmapSize ){
if( pFile->mmapSizeMax>0 && nByte>pFile->mmapSize ){
int rc;
if( pFile->szChunk<=0 ){
if( robust_ftruncate(pFile->h, nByte) ){
@ -3758,11 +3758,14 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){
}
return SQLITE_OK;
}
case SQLITE_FCNTL_MMAP_LIMIT: {
case SQLITE_FCNTL_MMAP_SIZE: {
i64 newLimit = *(i64*)pArg;
*(i64*)pArg = pFile->mmapLimit;
if( newLimit>sqlite3GlobalConfig.mxMmap ){
newLimit = sqlite3GlobalConfig.mxMmap;
}
*(i64*)pArg = pFile->mmapSizeMax;
if( newLimit>=0 ){
pFile->mmapLimit = newLimit;
pFile->mmapSizeMax = newLimit;
if( newLimit<pFile->mmapSize ) pFile->mmapSize = newLimit;
}
return SQLITE_OK;
@ -4574,17 +4577,17 @@ static int unixShmUnmap(
*/
static void unixUnmapfile(unixFile *pFd){
assert( pFd->nFetchOut==0 );
#ifndef SQLITE_DISABLE_MMAP
#if SQLITE_MAX_MMAP_SIZE>0
if( pFd->pMapRegion ){
osMunmap(pFd->pMapRegion, pFd->mmapOrigsize);
osMunmap(pFd->pMapRegion, pFd->mmapSizeActual);
pFd->pMapRegion = 0;
pFd->mmapSize = 0;
pFd->mmapOrigsize = 0;
pFd->mmapSizeActual = 0;
}
#endif
}
#ifndef SQLITE_DISABLE_MMAP
#if SQLITE_MAX_MMAP_SIZE>0
/*
** Return the system page size.
*/
@ -4597,9 +4600,9 @@ static int unixGetPagesize(void){
return (int)sysconf(_SC_PAGESIZE);
#endif
}
#endif /* SQLITE_DISABLE_MMAP */
#endif /* SQLITE_MAX_MMAP_SIZE>0 */
#ifndef SQLITE_DISABLE_MMAP
#if SQLITE_MAX_MMAP_SIZE>0
/*
** Attempt to set the size of the memory mapping maintained by file
** descriptor pFd to nNew bytes. Any existing mapping is discarded.
@ -4608,7 +4611,7 @@ static int unixGetPagesize(void){
**
** unixFile.pMapRegion
** unixFile.mmapSize
** unixFile.mmapOrigsize
** unixFile.mmapSizeActual
**
** If unsuccessful, an error message is logged via sqlite3_log() and
** the three variables above are zeroed. In this case SQLite should
@ -4622,15 +4625,15 @@ static void unixRemapfile(
const char *zErr = "mmap";
int h = pFd->h; /* File descriptor open on db file */
u8 *pOrig = (u8 *)pFd->pMapRegion; /* Pointer to current file mapping */
i64 nOrig = pFd->mmapOrigsize; /* Size of pOrig region in bytes */
i64 nOrig = pFd->mmapSizeActual; /* Size of pOrig region in bytes */
u8 *pNew = 0; /* Location of new mapping */
int flags = PROT_READ; /* Flags to pass to mmap() */
assert( pFd->nFetchOut==0 );
assert( nNew>pFd->mmapSize );
assert( nNew<=pFd->mmapLimit );
assert( nNew<=pFd->mmapSizeMax );
assert( nNew>0 );
assert( pFd->mmapOrigsize>=pFd->mmapSize );
assert( pFd->mmapSizeActual>=pFd->mmapSize );
assert( MAP_FAILED!=0 );
if( (pFd->ctrlFlags & UNIXFILE_RDONLY)==0 ) flags |= PROT_WRITE;
@ -4679,10 +4682,10 @@ static void unixRemapfile(
/* If the mmap() above failed, assume that all subsequent mmap() calls
** will probably fail too. Fall back to using xRead/xWrite exclusively
** in this case. */
pFd->mmapLimit = 0;
pFd->mmapSizeMax = 0;
}
pFd->pMapRegion = (void *)pNew;
pFd->mmapSize = pFd->mmapOrigsize = nNew;
pFd->mmapSize = pFd->mmapSizeActual = nNew;
}
#endif
@ -4703,7 +4706,7 @@ static void unixRemapfile(
** code otherwise.
*/
static int unixMapfile(unixFile *pFd, i64 nByte){
#ifndef SQLITE_DISABLE_MMAP
#if SQLITE_MAX_MMAP_SIZE>0
i64 nMap = nByte;
int rc;
@ -4718,8 +4721,8 @@ static int unixMapfile(unixFile *pFd, i64 nByte){
}
nMap = statbuf.st_size;
}
if( nMap>pFd->mmapLimit ){
nMap = pFd->mmapLimit;
if( nMap>pFd->mmapSizeMax ){
nMap = pFd->mmapSizeMax;
}
if( nMap!=pFd->mmapSize ){
@ -4747,13 +4750,13 @@ static int unixMapfile(unixFile *pFd, i64 nByte){
** release the reference by calling unixUnfetch().
*/
static int unixFetch(sqlite3_file *fd, i64 iOff, int nAmt, void **pp){
#ifndef SQLITE_DISABLE_MMAP
#if SQLITE_MAX_MMAP_SIZE>0
unixFile *pFd = (unixFile *)fd; /* The underlying database file */
#endif
*pp = 0;
#ifndef SQLITE_DISABLE_MMAP
if( pFd->mmapLimit>0 ){
#if SQLITE_MAX_MMAP_SIZE>0
if( pFd->mmapSizeMax>0 ){
if( pFd->pMapRegion==0 ){
int rc = unixMapfile(pFd, -1);
if( rc!=SQLITE_OK ) return rc;
@ -5126,7 +5129,7 @@ static int fillInUnixFile(
pNew->pVfs = pVfs;
pNew->zPath = zFilename;
pNew->ctrlFlags = (u8)ctrlFlags;
pNew->mmapLimit = sqlite3GlobalConfig.mxMmap;
pNew->mmapSizeMax = sqlite3GlobalConfig.mxMmap;
if( sqlite3_uri_boolean(((ctrlFlags & UNIXFILE_URI) ? zFilename : 0),
"psow", SQLITE_POWERSAFE_OVERWRITE) ){
pNew->ctrlFlags |= UNIXFILE_PSOW;

View File

@ -150,12 +150,12 @@ struct winFile {
winceLock local; /* Locks obtained by this instance of winFile */
winceLock *shared; /* Global shared lock memory for the file */
#endif
int nFetchOut; /* Number of outstanding xFetch references */
HANDLE hMap; /* Handle for accessing memory mapping */
void *pMapRegion; /* Area memory mapped */
sqlite3_int64 mmapSize; /* Usable size of mapped region */
sqlite3_int64 mmapOrigsize; /* Actual size of mapped region */
sqlite3_int64 mmapLimit; /* Configured FCNTL_MMAP_LIMIT value */
int nFetchOut; /* Number of outstanding xFetch references */
HANDLE hMap; /* Handle for accessing memory mapping */
void *pMapRegion; /* Area memory mapped */
sqlite3_int64 mmapSize; /* Usable size of mapped region */
sqlite3_int64 mmapSizeActual; /* Actual size of mapped region */
sqlite3_int64 mmapSizeMax; /* Configured FCNTL_MMAP_SIZE value */
};
/*
@ -2148,7 +2148,7 @@ static int winRead(
SimulateIOError(return SQLITE_IOERR_READ);
OSTRACE(("READ %d lock=%d\n", pFile->h, pFile->locktype));
#if !defined(SQLITE_DISABLE_MMAP)
#if SQLITE_MAX_MMAP_SIZE>0
/* Deal with as much of this read request as possible by transfering
** data from the memory mapping using memcpy(). */
if( offset<pFile->mmapSize ){
@ -2214,7 +2214,7 @@ static int winWrite(
OSTRACE(("WRITE %d lock=%d\n", pFile->h, pFile->locktype));
#if !defined(SQLITE_DISABLE_MMAP)
#if SQLITE_MAX_MMAP_SIZE>0
/* Deal with as much of this write request as possible by transfering
** data from the memory mapping using memcpy(). */
if( offset<pFile->mmapSize ){
@ -2325,7 +2325,7 @@ static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){
"winTruncate2", pFile->zPath);
}
#if !defined(SQLITE_DISABLE_MMAP)
#if SQLITE_MAX_MMAP_SIZE>0
/* If the file was truncated to a size smaller than the currently
** mapped region, reduce the effective mapping size as well. SQLite will
** use read() and write() to access data beyond this point from now on.
@ -2842,10 +2842,13 @@ static int winFileControl(sqlite3_file *id, int op, void *pArg){
}
return SQLITE_OK;
}
case SQLITE_FCNTL_MMAP_LIMIT: {
case SQLITE_FCNTL_MMAP_SIZE: {
i64 newLimit = *(i64*)pArg;
*(i64*)pArg = pFile->mmapLimit;
if( newLimit>=0 ) pFile->mmapLimit = newLimit;
if( newLimit>sqlite3GlobalConfig.mxMmap ){
newLimit = sqlite3GlobalConfig.mxMmap;
}
*(i64*)pArg = pFile->mmapSizeMax;
if( newLimit>=0 ) pFile->mmapSizeMax = newLimit;
return SQLITE_OK;
}
}
@ -3523,7 +3526,7 @@ shmpage_out:
*/
static int winUnmapfile(winFile *pFile){
assert( pFile!=0 );
#if !defined(SQLITE_DISABLE_MMAP)
#if SQLITE_MAX_MMAP_SIZE>0
if( pFile->pMapRegion ){
if( !osUnmapViewOfFile(pFile->pMapRegion) ){
pFile->lastErrno = osGetLastError();
@ -3532,7 +3535,7 @@ static int winUnmapfile(winFile *pFile){
}
pFile->pMapRegion = 0;
pFile->mmapSize = 0;
pFile->mmapOrigsize = 0;
pFile->mmapSizeActual = 0;
}
if( pFile->hMap!=NULL ){
if( !osCloseHandle(pFile->hMap) ){
@ -3546,7 +3549,7 @@ static int winUnmapfile(winFile *pFile){
return SQLITE_OK;
}
#if !defined(SQLITE_DISABLE_MMAP)
#if SQLITE_MAX_MMAP_SIZE>0
/*
** Memory map or remap the file opened by file-descriptor pFd (if the file
** is already mapped, the existing mapping is replaced by the new). Or, if
@ -3557,7 +3560,7 @@ static int winUnmapfile(winFile *pFile){
** the mapping to create. Otherwise, if nByte is less than zero, then the
** requested size is the size of the file on disk. The actual size of the
** created mapping is either the requested size or the value configured
** using SQLITE_FCNTL_MMAP_LIMIT, whichever is smaller.
** using SQLITE_FCNTL_MMAP_SIZE, whichever is smaller.
**
** SQLITE_OK is returned if no error occurs (even if the mapping is not
** recreated as a result of outstanding references) or an SQLite error
@ -3576,8 +3579,8 @@ static int winMapfile(winFile *pFd, sqlite3_int64 nByte){
return SQLITE_IOERR_FSTAT;
}
}
if( nMap>pFd->mmapLimit ){
nMap = pFd->mmapLimit;
if( nMap>pFd->mmapSizeMax ){
nMap = pFd->mmapSizeMax;
}
nMap &= ~(sqlite3_int64)(winSysInfo.dwPageSize - 1);
@ -3629,12 +3632,12 @@ static int winMapfile(winFile *pFd, sqlite3_int64 nByte){
}
pFd->pMapRegion = pNew;
pFd->mmapSize = nMap;
pFd->mmapOrigsize = nMap;
pFd->mmapSizeActual = nMap;
}
return SQLITE_OK;
}
#endif /* !defined(SQLITE_DISABLE_MMAP) */
#endif /* SQLITE_MAX_MMAP_SIZE>0 */
/*
** If possible, return a pointer to a mapping of file fd starting at offset
@ -3652,8 +3655,8 @@ static int winFetch(sqlite3_file *fd, i64 iOff, int nAmt, void **pp){
winFile *pFd = (winFile*)fd; /* The underlying database file */
*pp = 0;
#if !defined(SQLITE_DISABLE_MMAP)
if( pFd->mmapLimit>0 ){
#if SQLITE_MAX_MMAP_SIZE>0
if( pFd->mmapSizeMax>0 ){
if( pFd->pMapRegion==0 ){
int rc = winMapfile(pFd, -1);
if( rc!=SQLITE_OK ) return rc;
@ -4129,8 +4132,8 @@ static int winOpen(
pFile->hMap = NULL;
pFile->pMapRegion = 0;
pFile->mmapSize = 0;
pFile->mmapOrigsize = 0;
pFile->mmapLimit = sqlite3GlobalConfig.mxMmap;
pFile->mmapSizeActual = 0;
pFile->mmapSizeMax = sqlite3GlobalConfig.mxMmap;
OpenCounter(+1);
return rc;

View File

@ -658,7 +658,7 @@ struct Pager {
u8 bUseFetch; /* True to use xFetch() */
int nMmapOut; /* Number of mmap pages currently outstanding */
sqlite3_int64 mxMmap; /* Desired maximum mmap size */
sqlite3_int64 szMmap; /* Desired maximum mmap size */
PgHdr *pMmapFreelist; /* List of free mmap page headers (pDirty) */
/*
** End of the routinely-changing class members
@ -774,10 +774,10 @@ static const unsigned char aJournalMagic[] = {
** The macro USEFETCH is true if we are allowed to use the xFetch and xUnfetch
** interfaces to access the database using memory-mapped I/O.
*/
#ifdef SQLITE_DISABLE_MMAP
# define USEFETCH(x) 0
#else
#if SQLITE_MAX_MMAP_SIZE>0
# define USEFETCH(x) ((x)->bUseFetch)
#else
# define USEFETCH(x) 0
#endif
/*
@ -3370,16 +3370,16 @@ void sqlite3PagerSetCachesize(Pager *pPager, int mxPage){
}
/*
** Invoke SQLITE_FCNTL_MMAP_LIMIT based on the current value of mxMmap.
** Invoke SQLITE_FCNTL_MMAP_SIZE based on the current value of szMmap.
*/
static void pagerFixMaplimit(Pager *pPager){
#if !defined(SQLITE_DISABLE_MMAP)
#if SQLITE_MAX_MMAP_SIZE>0
sqlite3_file *fd = pPager->fd;
if( isOpen(fd) ){
sqlite3_int64 mx;
pPager->bUseFetch = (fd->pMethods->iVersion>=3) && pPager->mxMmap>0;
mx = pPager->mxMmap;
sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_MMAP_LIMIT, &mx);
sqlite3_int64 sz;
pPager->bUseFetch = (fd->pMethods->iVersion>=3) && pPager->szMmap>0;
sz = pPager->szMmap;
sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_MMAP_SIZE, &sz);
}
#endif
}
@ -3387,8 +3387,8 @@ static void pagerFixMaplimit(Pager *pPager){
/*
** Change the maximum size of any memory mapping made of the database file.
*/
void sqlite3PagerSetMmapLimit(Pager *pPager, sqlite3_int64 mxMmap){
pPager->mxMmap = mxMmap;
void sqlite3PagerSetMmapLimit(Pager *pPager, sqlite3_int64 szMmap){
pPager->szMmap = szMmap;
pagerFixMaplimit(pPager);
}
@ -4766,7 +4766,7 @@ int sqlite3PagerOpen(
/* pPager->pBusyHandlerArg = 0; */
pPager->xReiniter = xReinit;
/* memset(pPager->aHash, 0, sizeof(pPager->aHash)); */
/* pPager->mxMmap = SQLITE_DEFAULT_MMAP_LIMIT // will be set by btree.c */
/* pPager->szMmap = SQLITE_DEFAULT_MMAP_SIZE // will be set by btree.c */
*ppPager = pPager;
return SQLITE_OK;

View File

@ -746,39 +746,39 @@ void sqlite3Pragma(
}else
/*
** PRAGMA [database.]mmap_limit(N)
** PRAGMA [database.]mmap_size(N)
**
** Used to set mapping size limit. The mapping size limit is
** used to limit the aggregate size of all memory mapped regions of the
** database file. If this parameter is set to zero, then memory mapping
** is not used at all. If N is negative, then the default memory map
** limit determined by sqlite3_config(SQLITE_CONFIG_MMAP_LIMIT) is set.
** limit determined by sqlite3_config(SQLITE_CONFIG_MMAP_SIZE) is set.
** The parameter N is measured in bytes.
**
** This value is advisory. The underlying VFS is free to memory map
** as little or as much as it wants. Except, if N is set to 0 then the
** upper layers will never invoke the xFetch interfaces to the VFS.
*/
if( sqlite3StrICmp(zLeft,"mmap_limit")==0 ){
sqlite3_int64 mx;
if( sqlite3StrICmp(zLeft,"mmap_size")==0 ){
sqlite3_int64 sz;
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
if( zRight ){
int ii;
sqlite3Atoi64(zRight, &mx, 1000, SQLITE_UTF8);
if( mx<0 ) mx = sqlite3GlobalConfig.mxMmap;
if( pId2->n==0 ) db->mxMmap = mx;
sqlite3Atoi64(zRight, &sz, 1000, SQLITE_UTF8);
if( sz<0 ) sz = sqlite3GlobalConfig.szMmap;
if( pId2->n==0 ) db->szMmap = sz;
for(ii=db->nDb-1; ii>=0; ii--){
if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
sqlite3BtreeSetMmapLimit(db->aDb[ii].pBt, mx);
sqlite3BtreeSetMmapLimit(db->aDb[ii].pBt, sz);
}
}
}
mx = -1;
if( sqlite3_file_control(db,zDb,SQLITE_FCNTL_MMAP_LIMIT,&mx)==SQLITE_OK ){
#if defined(SQLITE_DISABLE_MMAP)
mx = 0;
sz = -1;
if( sqlite3_file_control(db,zDb,SQLITE_FCNTL_MMAP_SIZE,&sz)==SQLITE_OK ){
#if SQLITE_MAX_MMAP_SIZE==0
sz = 0;
#endif
returnSingleInt(pParse, "mmap_limit", mx);
returnSingleInt(pParse, "mmap_size", sz);
}
}else

View File

@ -3060,7 +3060,8 @@ int main(int argc, char **argv){
sqlite3_multiplex_initialize(0, 1);
#endif
}else if( strcmp(z,"-mmap")==0 ){
sqlite3_config(SQLITE_CONFIG_MMAP_LIMIT, integerValue(cmdline_option_value(argc,argv,++i)));
sqlite3_int64 sz = integerValue(cmdline_option_value(argc,argv,++i));
sqlite3_config(SQLITE_CONFIG_MMAP_SIZE, sz, sz);
}else if( strcmp(z,"-vfs")==0 ){
sqlite3_vfs *pVfs = sqlite3_vfs_find(cmdline_option_value(argc,argv,++i));
if( pVfs ){

View File

@ -892,15 +892,15 @@ struct sqlite3_io_methods {
** written into memory obtained from [sqlite3_malloc()]. The caller should
** invoke [sqlite3_free()] on the result to avoid a memory leak.
**
** <li>[[SQLITE_FCNTL_MMAP_LIMIT]]
** The [SQLITE_FCNTL_MMAP_LIMIT] file control is used to query or set the
** <li>[[SQLITE_FCNTL_MMAP_SIZE]]
** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the
** maximum number of bytes that will be used for memory-mapped I/O.
** The argument is a pointer to a value of type sqlite3_int64 that
** is an advisory maximum number of bytes in the file to memory map. The
** pointer is overwritten with the old value. The limit is not changed if
** the originally pointed to is negative, and so the current limit can be
** queried by passing in a pointer to a negative number. This file-control
** is used internally to implement [PRAGMA mmap_limit].
** the value originally pointed to is negative, and so the current limit
** can be queried by passing in a pointer to a negative number. This
** file-control is used internally to implement [PRAGMA mmap_size].
**
** </ul>
*/
@ -920,7 +920,7 @@ struct sqlite3_io_methods {
#define SQLITE_FCNTL_PRAGMA 14
#define SQLITE_FCNTL_BUSYHANDLER 15
#define SQLITE_FCNTL_TEMPFILENAME 16
#define SQLITE_FCNTL_MMAP_LIMIT 18
#define SQLITE_FCNTL_MMAP_SIZE 18
/*
** CAPI3REF: Mutex Handle
@ -1650,17 +1650,19 @@ struct sqlite3_mem_methods {
** the connection being passed as the second parameter is being closed. The
** third parameter is passed NULL In this case.
**
** [[SQLITE_CONFIG_MMAP_LIMIT]]
** <dt>SQLITE_CONFIG_MMAP_LIMIT
** <dd>The sole argument should be a 64-bit integer (an sqlite3_int64) that
** is the default maximum number of bytes of process address space that
** should be used for accessing each database file using memory mapping.
** [[SQLITE_CONFIG_MMAP_SIZE]]
** <dt>SQLITE_CONFIG_MMAP_SIZE
** <dd>SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values
** that are the default mmap size limit (the default setting for
** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
** The default setting can be overridden by each database connection using
** either the [PRAGMA mmap_limit] command, or by using the
** [SQLITE_FCNTL_MMAP_LIMIT] file control. The value set here overrides the
** compile-time default that is set using [SQLITE_DEFAULT_MMAP_LIMIT].
** If the argument to this option is negative, then
** the memory map limit is set to the compile-time default.
** either the [PRAGMA mmap_size] command, or by using the
** [SQLITE_FCNTL_MMAP_SIZE] file control. The maximum allowed mmap size
** cannot be changed at run-time. Nor may the maximum allowed mmap size
** exceed the compile-time maximum mmap size set by the
** [SQLITE_MAX_MMAP_SIZE] compile-time option.
** If either argument to this option is negative, then that argument is
** changed to its compile-time default.
** </dl>
*/
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
@ -1684,7 +1686,7 @@ struct sqlite3_mem_methods {
#define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
#define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
#define SQLITE_CONFIG_MMAP_LIMIT 22 /* sqlite3_int64 */
#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
/*
** CAPI3REF: Database Connection Configuration Options

View File

@ -540,13 +540,46 @@ extern const int sqlite3one;
#endif
/*
** Disable MMAP on platforms where it is not supported
** Disable MMAP on platforms where it is known to not work
*/
#if defined(__OpenBSD__) || defined(__QNXNTO__)
# undef SQLITE_DISABLE_MMAP
# define SQLITE_DISABLE_MMAP 1
# undef SQLITE_MAX_MMAP_SIZE
# define SQLITE_MAX_MMAP_SIZE 0
#endif
/*
** Default maximum size of memory used by memory-mapped I/O in the VFS
*/
#ifdef __APPLE__
# include <TargetConditionals.h>
# if TARGET_OS_IPHONE
# undef SQLITE_MAX_MMAP_SIZE
# define SQLITE_MAX_MMAP_SIZE 0
# endif
#endif
#ifndef SQLITE_MAX_MMAP_SIZE
# if defined(__linux__) \
|| defined(_WIN32) \
|| (defined(__APPLE__) && defined(__MACH__)) \
|| defined(__sun)
# define SQLITE_MAX_MMAP_SIZE 2147483648
# else
# define SQLITE_MAX_MMAP_SIZE 0
# endif
#endif
/*
** The default MMAP_SIZE is zero on all platforms. Or, even if a larger
** default MMAP_SIZE is specified at compile-time, make sure that it does
** not exceed the maximum mmap size.
*/
#ifndef SQLITE_DEFAULT_MMAP_SIZE
# define SQLITE_DEFAULT_MMAP_SIZE 0
#endif
#if SQLITE_DEFAULT_MMAP_SIZE>SQLITE_MAX_MMAP_SIZE
# undef SQLITE_DEFAULT_MMAP_SIZE
# define SQLITE_DEFAULT_MMAP_SIZE SQLITE_MAX_MMAP_SIZE
#endif
/*
** An instance of the following structure is used to store the busy-handler
@ -842,7 +875,7 @@ struct sqlite3 {
int nDb; /* Number of backends currently in use */
int flags; /* Miscellaneous flags. See below */
i64 lastRowid; /* ROWID of most recent insert (see above) */
i64 mxMmap; /* Default mmap_limit setting */
i64 szMmap; /* Default mmap_size setting */
unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
int errCode; /* Most recent error code (SQLITE_*) */
int errMask; /* & result codes with this before returning */
@ -2516,7 +2549,8 @@ struct Sqlite3Config {
void *pHeap; /* Heap storage space */
int nHeap; /* Size of pHeap[] */
int mnReq, mxReq; /* Min and max heap requests sizes */
sqlite3_int64 mxMmap; /* Maximum mmap() space per open file */
sqlite3_int64 szMmap; /* mmap() space per open file */
sqlite3_int64 mxMmap; /* Maximum value for szMmap */
void *pScratch; /* Scratch memory */
int szScratch; /* Size of each scratch buffer */
int nScratch; /* Number of scratch buffers */

View File

@ -206,27 +206,3 @@
#ifndef SQLITE_MAX_TRIGGER_DEPTH
# define SQLITE_MAX_TRIGGER_DEPTH 1000
#endif
/*
** Default maximum size of memory used by xFetch in the VFS.
*/
#ifdef SQLITE_DISABLE_MMAP
# undef SQLITE_DEFAULT_MMAP_LIMIT
# define SQLITE_DEFAULT_MMAP_LIMIT 0
#endif
#ifdef __APPLE__
# include <TargetConditionals.h>
# if TARGET_OS_IPHONE
# define SQLITE_DEFAULT_MMAP_LIMIT 0
# endif
#endif
#ifndef SQLITE_DEFAULT_MMAP_LIMIT
# if defined(__linux__) \
|| defined(_WIN32) \
|| (defined(__APPLE__) && defined(__MACH__)) \
|| defined(__sun)
# define SQLITE_DEFAULT_MMAP_LIMIT 268435456 /* = 256*1024*1024 */
# else
# define SQLITE_DEFAULT_MMAP_LIMIT 0
# endif
#endif

View File

@ -87,10 +87,10 @@ static void set_options(Tcl_Interp *interp){
Tcl_SetVar2(interp, "sqlite_options", "lfs", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_DISABLE_MMAP
Tcl_SetVar2(interp, "sqlite_options", "mmap", "0", TCL_GLOBAL_ONLY);
#else
#if SQLITE_MAX_MMAP_SIZE>0
Tcl_SetVar2(interp, "sqlite_options", "mmap", "1", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "mmap", "0", TCL_GLOBAL_ONLY);
#endif
#if 1 /* def SQLITE_MEMDEBUG */

View File

@ -40,7 +40,7 @@ proc db_write {db {reset 0}} {
do_test 1.1 {
db close
sqlite3 db test.db
execsql { PRAGMA mmap_limit = 0 }
execsql { PRAGMA mmap_size = 0 }
expr {[file size test.db] / 1024}
} 6

View File

@ -28,7 +28,7 @@ ifcapable {!pager_pragmas} {
# Tests in this file verify that locking_mode=exclusive causes SQLite to
# use cached pages even if the database is changed on disk. This doesn't
# work with mmap.
if {[permutation]!="nommap"} {
if {[permutation]=="mmap"} {
finish_test
return
}

View File

@ -1273,7 +1273,7 @@ do_test func-29.3 {
sqlite3_db_status db CACHE_MISS 1
db eval {SELECT typeof(+x) FROM t29 ORDER BY id}
} {integer null real blob text}
if {[permutation] == "nommap"} {
if {[permutation] != "mmap"} {
do_test func-29.4 {
set x [lindex [sqlite3_db_status db CACHE_MISS 1] 1]
if {$x>100} {set x many}

View File

@ -123,7 +123,7 @@ foreach AutoVacuumMode [list 0 1] {
forcedelete test.db test.db-journal
sqlite3 db test.db
execsql "PRAGMA mmap_limit = 0"
execsql "PRAGMA mmap_size = 0"
execsql "PRAGMA auto_vacuum = $AutoVacuumMode"
do_test incrblob-2.$AutoVacuumMode.1 {
@ -150,7 +150,7 @@ foreach AutoVacuumMode [list 0 1] {
# Open and close the db to make sure the page cache is empty.
db close
sqlite3 db test.db
execsql "PRAGMA mmap_limit = 0"
execsql "PRAGMA mmap_size = 0"
# Read the last 20 bytes of the blob via a blob handle.
set ::blob [db incrblob blobs v 1]
@ -173,7 +173,7 @@ foreach AutoVacuumMode [list 0 1] {
# Open and close the db to make sure the page cache is empty.
db close
sqlite3 db test.db
execsql "PRAGMA mmap_limit = 0"
execsql "PRAGMA mmap_size = 0"
# Write the second-to-last 20 bytes of the blob via a blob handle.
#
@ -203,7 +203,7 @@ foreach AutoVacuumMode [list 0 1] {
# Open and close the db to make sure the page cache is empty.
db close
sqlite3 db test.db
execsql { PRAGMA mmap_limit = 0 }
execsql { PRAGMA mmap_size = 0 }
execsql { SELECT i FROM blobs }
} {45}

View File

@ -40,17 +40,17 @@ proc register_rblob_code {dbname seed} {
}]
}
foreach {t mmap_limit nRead c2init} {
1.1 { PRAGMA mmap_limit = 67108864 } 4 {PRAGMA mmap_limit = 0}
1.2 { PRAGMA mmap_limit = 53248 } 150 {PRAGMA mmap_limit = 0}
1.3 { PRAGMA mmap_limit = 0 } 344 {PRAGMA mmap_limit = 0}
1.4 { PRAGMA mmap_limit = 67108864 } 4 {PRAGMA mmap_limit = 67108864 }
1.5 { PRAGMA mmap_limit = 53248 } 150 {PRAGMA mmap_limit = 67108864 }
1.6 { PRAGMA mmap_limit = 0 } 344 {PRAGMA mmap_limit = 67108864 }
foreach {t mmap_size nRead c2init} {
1.1 { PRAGMA mmap_size = 67108864 } 4 {PRAGMA mmap_size = 0}
1.2 { PRAGMA mmap_size = 53248 } 150 {PRAGMA mmap_size = 0}
1.3 { PRAGMA mmap_size = 0 } 344 {PRAGMA mmap_size = 0}
1.4 { PRAGMA mmap_size = 67108864 } 4 {PRAGMA mmap_size = 67108864 }
1.5 { PRAGMA mmap_size = 53248 } 150 {PRAGMA mmap_size = 67108864 }
1.6 { PRAGMA mmap_size = 0 } 344 {PRAGMA mmap_size = 67108864 }
} {
do_multiclient_test tn {
sql1 {PRAGMA page_size=1024}
sql1 $mmap_limit
sql1 $mmap_size
sql2 $c2init
code2 [register_rblob_code db2 0]
@ -89,7 +89,7 @@ foreach {t mmap_limit nRead c2init} {
} {64 ok 149}
# Check that the number of pages read by connection 1 indicates that the
# "PRAGMA mmap_limit" command worked.
# "PRAGMA mmap_size" command worked.
do_test $t.$tn.5 { nRead db } $nRead
}
}
@ -106,7 +106,7 @@ db func rblob rblob
do_execsql_test 2.1 {
PRAGMA auto_vacuum = 1;
PRAGMA mmap_limit = 67108864;
PRAGMA mmap_size = 67108864;
PRAGMA journal_mode = wal;
CREATE TABLE t1(a, b, UNIQUE(a, b));
INSERT INTO t1 VALUES(rblob(500), rblob(500));
@ -254,7 +254,7 @@ do_test 5.5 {
} SQLITE_OK
#-------------------------------------------------------------------------
# Test various mmap_limit settings.
# Test various mmap_size settings.
#
foreach {tn1 mmap1 mmap2} {
1 6144 167773
@ -279,8 +279,8 @@ foreach {tn1 mmap1 mmap2} {
code1 [register_rblob_code db 0]
code2 [register_rblob_code db2 444]
sql1 "PRAGMA mmap_limit = $mmap1"
sql2 "PRAGMA mmap_limit = $mmap2"
sql1 "PRAGMA mmap_size = $mmap1"
sql2 "PRAGMA mmap_size = $mmap2"
do_test $tn1.$tn {
for {set i 1} {$i <= 100} {incr i} {

View File

@ -2530,9 +2530,9 @@ if {$::tcl_platform(platform)=="unix"} {
# an error.
#
foreach {tn pragma strsize} {
1 { PRAGMA mmap_limit = 0 } 2400
1 { PRAGMA mmap_size = 0 } 2400
2 { } 2400
3 { PRAGMA mmap_limit = 0 } 4400
3 { PRAGMA mmap_size = 0 } 4400
4 { } 4400
} {
reset_db
@ -2757,7 +2757,7 @@ do_test 42.1 {
db close
sqlite3_test_control_pending_byte 0x0010000
sqlite3 db test.db
db eval { PRAGMA mmap_limit = 0 }
db eval { PRAGMA mmap_size = 0 }
catchsql { SELECT sum(length(y)) FROM t1 }
} {1 {database disk image is malformed}}
do_test 42.2 {
@ -2799,7 +2799,7 @@ do_test 43.1 {
db close
sqlite3 db test.db
db eval { PRAGMA mmap_limit = 0 }
db eval { PRAGMA mmap_size = 0 }
db eval { SELECT * FROM t1 }
sqlite3_db_status db CACHE_MISS 0
} {0 2 0}

View File

@ -1282,7 +1282,7 @@ faultsim_save_and_close
do_faultsim_test pagerfault-28a -faults oom* -prep {
faultsim_restore_and_reopen
execsql { PRAGMA mmap_limit=0 }
execsql { PRAGMA mmap_size=0 }
sqlite3 db2 test.db
db2 eval { SELECT count(*) FROM t2 }

View File

@ -88,7 +88,7 @@ do_test pageropt-1.4 {
# must refill.
#
ifcapable mmap {
set x [expr {[permutation]=="nommap" ? 6 : 1}]
set x [expr {[permutation]=="mmap" ? 1 : 6}]
} else {
set x 6
}

View File

@ -138,10 +138,10 @@ test_suite "veryquick" -prefix "" -description {
test_set $allquicktests -exclude *malloc* *ioerr* *fault*
]
test_suite "nommap" -prefix "nomm-" -description {
test_suite "mmap" -prefix "mm-" -description {
Similar to veryquick. Except with memory mapping disabled.
} -presql {
pragma mmap_limit = 0;
pragma mmap_size = 268435456;
} -files [
test_set $allquicktests -exclude *malloc* *ioerr* *fault* -include malloc.test
]

View File

@ -262,7 +262,7 @@ do_faultsim_test 4 -faults vfsfault-* -prep {
faultsim_restore_and_reopen
file_control_chunksize_test db main 8192
execsql {
PRAGMA mmap_limit = 1000000;
PRAGMA mmap_size = 1000000;
}
} -body {
test_syscall errno mmap EACCES

View File

@ -728,7 +728,7 @@ do_test wal-11.9 {
} {37 1}
sqlite3_wal db test.db
set nWal 39
if {[permutation]=="nommap"} {set nWal 37}
if {[permutation]!="mmap"} {set nWal 37}
ifcapable !mmap {set nWal 37}
do_test wal-11.10 {
execsql {

View File

@ -242,7 +242,7 @@ foreach {testprefix do_wal_checkpoint} {
# However, in mmap() mode, the db is pre-allocated to 2 pages at the
# start of the checkpoint, even though page 2 cannot be written.
set nDb 2
if {[permutation]=="no-mmap"} {set nDb 1}
if {[permutation]!="mmap"} {set nDb 1}
ifcapable !mmap {set nDb 1}
do_test 2.3.$tn.8 { file_page_counts } [list $nDb 4 2 4]
}

View File

@ -27,7 +27,7 @@ proc xLog {error_code msg} {
lappend ::log $msg
}
sqlite3 db test.db
db eval {PRAGMA mmap_limit=0}
db eval {PRAGMA mmap_size=0}
do_test win32lock-1.1 {
db eval {