aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2013-03-25 23:09:28 +0000
committerdrh <drh@noemail.net>2013-03-25 23:09:28 +0000
commit0d0614bdc6e59c1cb52bc79fdf8dafbbc78f57f9 (patch)
tree409fd2a1a127c4019c63da08d0d182db3d76a9be /src
parentd1ab8065c1039db43eb413702cafb3baa500d69a (diff)
downloadsqlite-0d0614bdc6e59c1cb52bc79fdf8dafbbc78f57f9.tar.gz
sqlite-0d0614bdc6e59c1cb52bc79fdf8dafbbc78f57f9.zip
Memory-mapped I/O is now on by default. The "PRAGMA mmap_limit(N)" can be
used to issue a hint to the VFS to limit mmap space to N bytes. The VFS is free to ignore that hint if desired. However, if "PRAGMA mmap_limit(0)" is used, xFetch is never called. FossilOrigin-Name: 1b37c4effdd03aa2ea938a71b4f22ed27391689b
Diffstat (limited to 'src')
-rw-r--r--src/btree.c4
-rw-r--r--src/btree.h2
-rw-r--r--src/os_unix.c15
-rw-r--r--src/pager.c22
-rw-r--r--src/pager.h2
-rw-r--r--src/pragma.c25
-rw-r--r--src/sqlite.h.in8
-rw-r--r--src/sqliteInt.h1
-rw-r--r--src/sqliteLimit.h7
9 files changed, 41 insertions, 45 deletions
diff --git a/src/btree.c b/src/btree.c
index 59970ded7..04cc20d5c 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -2134,11 +2134,11 @@ int sqlite3BtreeSetCacheSize(Btree *p, int mxPage){
** Change the limit on the amount of the database file that may be
** memory mapped.
*/
-int sqlite3BtreeSetMmapSize(Btree *p, int nMap){
+int sqlite3BtreeSetMmapLimit(Btree *p, sqlite3_int64 mxMmap){
BtShared *pBt = p->pBt;
assert( sqlite3_mutex_held(p->db->mutex) );
sqlite3BtreeEnter(p);
- sqlite3PagerSetMmapsize(pBt->pPager, nMap);
+ sqlite3PagerSetMmapLimit(pBt->pPager, mxMmap);
sqlite3BtreeLeave(p);
return SQLITE_OK;
}
diff --git a/src/btree.h b/src/btree.h
index f2cca2fc7..23f6ad706 100644
--- a/src/btree.h
+++ b/src/btree.h
@@ -63,7 +63,7 @@ int sqlite3BtreeOpen(
int sqlite3BtreeClose(Btree*);
int sqlite3BtreeSetCacheSize(Btree*,int);
-int sqlite3BtreeSetMmapSize(Btree*, int);
+int sqlite3BtreeSetMmapLimit(Btree*,sqlite3_int64);
int sqlite3BtreeSetSafetyLevel(Btree*,int,int,int);
int sqlite3BtreeSyncDisabled(Btree*);
int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
diff --git a/src/os_unix.c b/src/os_unix.c
index 625f41340..8a8516bcd 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -225,6 +225,11 @@ struct unixFile {
const char *zPath; /* Name of the file */
unixShm *pShm; /* Shared memory segment information */
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 */
+ void *pMapRegion; /* Memory mapped region */
#ifdef __QNXNTO__
int sectorSize; /* Device sector size */
int deviceCharacteristics; /* Precomputed device characteristics */
@@ -251,11 +256,6 @@ struct unixFile {
unsigned char inNormalWrite; /* True if in a normal write operation */
#endif
- sqlite3_int64 mmapSize; /* Usable size of mapping at pMapRegion */
- sqlite3_int64 mmapOrigsize; /* Actual size of mapping at pMapRegion */
- sqlite3_int64 mmapLimit; /* Configured FCNTL_MMAP_SIZE value */
- void *pMapRegion; /* Memory mapped region */
- int nFetchOut; /* Number of outstanding xFetch refs */
#ifdef SQLITE_TEST
/* In test mode, increase the size of this structure a bit so that
@@ -3699,7 +3699,7 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){
}
return SQLITE_OK;
}
- case SQLITE_FCNTL_MMAP_SIZE: {
+ case SQLITE_FCNTL_MMAP_LIMIT: {
pFile->mmapLimit = *(i64*)pArg;
return SQLITE_OK;
}
@@ -4528,7 +4528,7 @@ static void unixUnmapfile(unixFile *pFd){
** 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_SIZE, whichever is smaller.
+** using SQLITE_FCNTL_MMAP_LIMIT, 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
@@ -4969,6 +4969,7 @@ static int fillInUnixFile(
pNew->pVfs = pVfs;
pNew->zPath = zFilename;
pNew->ctrlFlags = (u8)ctrlFlags;
+ pNew->mmapLimit = SQLITE_DEFAULT_MMAP_LIMIT;
if( sqlite3_uri_boolean(((ctrlFlags & UNIXFILE_URI) ? zFilename : 0),
"psow", SQLITE_POWERSAFE_OVERWRITE) ){
pNew->ctrlFlags |= UNIXFILE_PSOW;
diff --git a/src/pager.c b/src/pager.c
index b7534deb0..4cce84423 100644
--- a/src/pager.c
+++ b/src/pager.c
@@ -657,8 +657,8 @@ struct Pager {
char dbFileVers[16]; /* Changes whenever database file changes */
u8 bUseFetch; /* True to use xFetch() */
- int nMapCfgLimit; /* Configured limit value */
int nMmapOut; /* Number of mmap pages currently outstanding */
+ sqlite3_int64 mxMmap; /* Desired maximum mmap size */
PgHdr *pFree; /* List of free mmap page headers (pDirty) */
/*
** End of the routinely-changing class members
@@ -3354,23 +3354,15 @@ void sqlite3PagerSetCachesize(Pager *pPager, int mxPage){
}
/*
-** Invoke SQLITE_FCNTL_MMAP_SIZE based on the current value of nMapCfgLimit.
+** Invoke SQLITE_FCNTL_MMAP_LIMIT based on the current value of mxMmap.
*/
static void pagerFixMaplimit(Pager *pPager){
sqlite3_file *fd = pPager->fd;
if( isOpen(fd) ){
- pPager->bUseFetch = (fd->pMethods->iVersion>=3) && pPager->nMapCfgLimit!=0;
+ pPager->bUseFetch = (fd->pMethods->iVersion>=3) && pPager->mxMmap>0;
if( pPager->bUseFetch ){
- void *p;
- i64 nMapLimit;
- if( pPager->nMapCfgLimit<0 ){
- nMapLimit = (i64)pPager->nMapCfgLimit * -1024;
- }else{
- nMapLimit = (i64)pPager->nMapCfgLimit * pPager->pageSize;
- }
-
- p = (void *)&nMapLimit;
- sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_MMAP_SIZE, p);
+ sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_MMAP_LIMIT,
+ (void*)&pPager->mxMmap);
}
}
}
@@ -3378,8 +3370,8 @@ static void pagerFixMaplimit(Pager *pPager){
/*
** Change the maximum size of any memory mapping made of the database file.
*/
-void sqlite3PagerSetMmapsize(Pager *pPager, int nMap){
- pPager->nMapCfgLimit = nMap;
+void sqlite3PagerSetMmapLimit(Pager *pPager, sqlite3_int64 mxMmap){
+ pPager->mxMmap = mxMmap;
pagerFixMaplimit(pPager);
}
diff --git a/src/pager.h b/src/pager.h
index 81ab30c11..6f659136e 100644
--- a/src/pager.h
+++ b/src/pager.h
@@ -108,7 +108,7 @@ void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *);
int sqlite3PagerSetPagesize(Pager*, u32*, int);
int sqlite3PagerMaxPageCount(Pager*, int);
void sqlite3PagerSetCachesize(Pager*, int);
-void sqlite3PagerSetMmapsize(Pager *, int);
+void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64);
void sqlite3PagerShrink(Pager*);
void sqlite3PagerSetSafetyLevel(Pager*,int,int,int);
int sqlite3PagerLockingMode(Pager *, int);
diff --git a/src/pragma.c b/src/pragma.c
index 9b31797d3..cd1cfbe21 100644
--- a/src/pragma.c
+++ b/src/pragma.c
@@ -745,26 +745,23 @@ void sqlite3Pragma(
}else
/*
- ** PRAGMA [database.]mmap_size
- ** PRAGMA [database.]mmap_size=N
+ ** PRAGMA [database.]mmap_limit(N)
**
- ** Used to set or query the mapping size limit. The mapping size limit is
+ ** 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 it is set to a positive value, then it is
- ** interpreted as a maximum size in pages. If set to less than zero, then
- ** the absolute value is interpreted as a size limit in KB.
+ ** is not used at all. The parameter N is measured in bytes.
**
- ** The default value is zero (do not use memory mapped IO).
+ ** 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_size")==0 ){
+ if( sqlite3StrICmp(zLeft,"mmap_limit")==0 ){
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
- if( !zRight ){
- returnSingleInt(pParse, "mmap_size", pDb->pSchema->mmap_size);
- }else{
- int size = sqlite3Atoi(zRight);
- pDb->pSchema->mmap_size = size;
- sqlite3BtreeSetMmapSize(pDb->pBt, pDb->pSchema->mmap_size);
+ if( zRight ){
+ sqlite3_int64 size;
+ sqlite3Atoi64(zRight, &size, 1000, SQLITE_UTF8);
+ sqlite3BtreeSetMmapLimit(pDb->pBt, size);
}
}else
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index 72f8d3293..acb49bf5f 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -886,9 +886,9 @@ 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_SIZE]]
-** The argument is assumed to point to a value of type sqlite3_int64. An
-** advisory maximum amount of this file to memory map in bytes.
+** <li>[[SQLITE_FCNTL_MMAP_LIMIT]]
+** The argument is assumed to pointer to a value of type sqlite3_int64 that
+** is an advisory maximum number of bytes in the file to memory map.
**
** </ul>
*/
@@ -908,7 +908,7 @@ struct sqlite3_io_methods {
#define SQLITE_FCNTL_PRAGMA 14
#define SQLITE_FCNTL_BUSYHANDLER 15
#define SQLITE_FCNTL_TEMPFILENAME 16
-#define SQLITE_FCNTL_MMAP_SIZE 18
+#define SQLITE_FCNTL_MMAP_LIMIT 18
/*
** CAPI3REF: Mutex Handle
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 59483bc87..129c4c5ea 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -746,7 +746,6 @@ struct Schema {
u8 enc; /* Text encoding used by this database */
u16 flags; /* Flags associated with this schema */
int cache_size; /* Number of pages to use in the cache */
- int mmap_size; /* Number of pages to memory map */
};
/*
diff --git a/src/sqliteLimit.h b/src/sqliteLimit.h
index c7aee53ce..201313945 100644
--- a/src/sqliteLimit.h
+++ b/src/sqliteLimit.h
@@ -206,3 +206,10 @@
#ifndef SQLITE_MAX_TRIGGER_DEPTH
# define SQLITE_MAX_TRIGGER_DEPTH 1000
#endif
+
+/*
+** Default maximum size of memory used by xFetch in the VFS.
+*/
+#ifndef SQLITE_DEFAULT_MMAP_LIMIT
+# define SQLITE_DEFAULT_MMAP_LIMIT (256*1024*1024)
+#endif