Skip to content

Commit

Permalink
Change the mmap_limit pragma to report the new limit, or to report the
Browse files Browse the repository at this point in the history
existing limit if called with no arguments.  Report the default mmap_limit
as part of PRAGMA compile_options.  Set the default mmmap_limit to 0 for
all systems other than linux, mac, windows, and solaris.
  • Loading branch information
D. Richard Hipp committed Apr 3, 2013
1 parent cf5344e commit e76909d
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 18 deletions.
3 changes: 3 additions & 0 deletions src/ctime.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ 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),
#endif
#ifdef SQLITE_DISABLE_DIRSYNC
"DISABLE_DIRSYNC",
#endif
Expand Down
4 changes: 3 additions & 1 deletion src/os_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -3710,7 +3710,9 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){
return SQLITE_OK;
}
case SQLITE_FCNTL_MMAP_LIMIT: {
pFile->mmapLimit = *(i64*)pArg;
i64 newLimit = *(i64*)pArg;
*(i64*)pArg = pFile->mmapLimit;
if( newLimit>=0 ) pFile->mmapLimit = newLimit;
return SQLITE_OK;
}
#ifdef SQLITE_DEBUG
Expand Down
4 changes: 3 additions & 1 deletion src/os_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -2837,7 +2837,9 @@ static int winFileControl(sqlite3_file *id, int op, void *pArg){
return SQLITE_OK;
}
case SQLITE_FCNTL_MMAP_LIMIT: {
pFile->mmapLimit = *(i64*)pArg;
i64 newLimit = *(i64*)pArg;
*(i64*) = pFile->mmapLimit;
if( newLimit>=0 ) pFile->mmapLimit = newLimit;
return SQLITE_OK;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/pager.c
Original file line number Diff line number Diff line change
Expand Up @@ -3358,9 +3358,10 @@ void sqlite3PagerSetCachesize(Pager *pPager, int mxPage){
static void pagerFixMaplimit(Pager *pPager){
sqlite3_file *fd = pPager->fd;
if( isOpen(fd) ){
sqlite3_int64 mx;
pPager->bUseFetch = (fd->pMethods->iVersion>=3) && pPager->mxMmap>0;
sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_MMAP_LIMIT,
(void*)&pPager->mxMmap);
mx = pPager->mxMmap;
sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_MMAP_LIMIT, &mx);
}
}

Expand Down
14 changes: 9 additions & 5 deletions src/pragma.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,19 +759,23 @@ void sqlite3Pragma(
** upper layers will never invoke the xFetch interfaces to the VFS.
*/
if( sqlite3StrICmp(zLeft,"mmap_limit")==0 ){
sqlite3_int64 mx;
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
if( zRight ){
sqlite3_int64 size;
int ii;
sqlite3Atoi64(zRight, &size, 1000, SQLITE_UTF8);
if( size<0 ) size = sqlite3GlobalConfig.mxMmap;
if( pId2->n==0 ) db->mxMmap = size;
sqlite3Atoi64(zRight, &mx, 1000, SQLITE_UTF8);
if( mx<0 ) mx = sqlite3GlobalConfig.mxMmap;
if( pId2->n==0 ) db->mxMmap = mx;
for(ii=db->nDb-1; ii>=0; ii--){
if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
sqlite3BtreeSetMmapLimit(db->aDb[ii].pBt, size);
sqlite3BtreeSetMmapLimit(db->aDb[ii].pBt, mx);
}
}
}
mx = -1;
if( sqlite3_file_control(db,zDb,SQLITE_FCNTL_MMAP_LIMIT,&mx)==SQLITE_OK ){
returnSingleInt(pParse, "mmap_limit", mx);
}
}else

/*
Expand Down
4 changes: 3 additions & 1 deletion src/sqlite.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,9 @@ struct sqlite3_io_methods {
**
** <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.
** 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 original value pointed to is negative.
**
** </ul>
*/
Expand Down
10 changes: 3 additions & 7 deletions src/sqliteLimit.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,9 @@
#ifndef SQLITE_DEFAULT_MMAP_LIMIT
# if defined(__linux__) \
|| defined(_WIN32) \
|| (defined(__APPLE__) && defined(__MACH__) && !defined(TARGET_OS_IPHONE)) \
|| defined(__sun) \
|| defined(__DragonFly__) \
|| defined(__FreeBSD__) \
|| defined(__NetBSD__) \
|| defined(__OpenBSD__)
# define SQLITE_DEFAULT_MMAP_LIMIT (256*1024*1024)
|| (defined(__APPLE__) && defined(__MACH__)) \
|| defined(__sun)
# define SQLITE_DEFAULT_MMAP_LIMIT 268435456 /* = 256*1024*1024 */
# else
# define SQLITE_DEFAULT_MMAP_LIMIT 0
# endif
Expand Down
2 changes: 1 addition & 1 deletion test/mmap1.test
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ do_execsql_test 2.1 {
INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; -- 16
INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; -- 32
PRAGMA wal_checkpoint;
} {wal 0 103 103}
} {67108864 wal 0 103 103}

do_execsql_test 2.2 {
PRAGMA auto_vacuum;
Expand Down

0 comments on commit e76909d

Please sign in to comment.