SQLite

Check-in [2d9f1327fe]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Change the mmap_limit pragma to report the new limit, or to report the 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.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | experimental-mmap
Files: files | file ages | folders
SHA1: 2d9f1327fe79e40435ce1e2594d7cd9a5aea0ef2
User & Date: drh 2013-04-03 13:09:18.208
Context
2013-04-03
13:38
Fix a bug in the detection of iOS when setting the default mmap_limit. (check-in: ac1432b3a8 user: drh tags: experimental-mmap)
13:09
Change the mmap_limit pragma to report the new limit, or to report the 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. (check-in: 2d9f1327fe user: drh tags: experimental-mmap)
11:52
Remove the restriction on using xFetch to load the root pages of tables and indexes. It appears to have been based on a misconception. (check-in: 5b082efead user: dan tags: experimental-mmap)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/ctime.c.
53
54
55
56
57
58
59



60
61
62
63
64
65
66
#endif
#ifdef SQLITE_DEBUG
  "DEBUG",
#endif
#ifdef SQLITE_DEFAULT_LOCKING_MODE
  "DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE),
#endif



#ifdef SQLITE_DISABLE_DIRSYNC
  "DISABLE_DIRSYNC",
#endif
#ifdef SQLITE_DISABLE_LFS
  "DISABLE_LFS",
#endif
#ifdef SQLITE_ENABLE_ATOMIC_WRITE







>
>
>







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#endif
#ifdef SQLITE_DEBUG
  "DEBUG",
#endif
#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
#ifdef SQLITE_DISABLE_LFS
  "DISABLE_LFS",
#endif
#ifdef SQLITE_ENABLE_ATOMIC_WRITE
Changes to src/os_unix.c.
3706
3707
3708
3709
3710
3711
3712
3713


3714
3715
3716
3717
3718
3719
3720
      if( zTFile ){
        unixGetTempname(pFile->pVfs->mxPathname, zTFile);
        *(char**)pArg = zTFile;
      }
      return SQLITE_OK;
    }
    case SQLITE_FCNTL_MMAP_LIMIT: {
      pFile->mmapLimit = *(i64*)pArg;


      return SQLITE_OK;
    }
#ifdef SQLITE_DEBUG
    /* The pager calls this method to signal that it has done
    ** a rollback and that the database is therefore unchanged and
    ** it hence it is OK for the transaction change counter to be
    ** unchanged.







|
>
>







3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
      if( zTFile ){
        unixGetTempname(pFile->pVfs->mxPathname, zTFile);
        *(char**)pArg = zTFile;
      }
      return SQLITE_OK;
    }
    case SQLITE_FCNTL_MMAP_LIMIT: {
      i64 newLimit = *(i64*)pArg;
      *(i64*)pArg = pFile->mmapLimit;
      if( newLimit>=0 ) pFile->mmapLimit = newLimit;
      return SQLITE_OK;
    }
#ifdef SQLITE_DEBUG
    /* The pager calls this method to signal that it has done
    ** a rollback and that the database is therefore unchanged and
    ** it hence it is OK for the transaction change counter to be
    ** unchanged.
Changes to src/os_win.c.
2833
2834
2835
2836
2837
2838
2839
2840


2841
2842
2843
2844
2845
2846
2847
      if( zTFile ){
        getTempname(pFile->pVfs->mxPathname, zTFile);
        *(char**)pArg = zTFile;
      }
      return SQLITE_OK;
    }
    case SQLITE_FCNTL_MMAP_LIMIT: {
      pFile->mmapLimit = *(i64*)pArg;


      return SQLITE_OK;
    }
  }
  return SQLITE_NOTFOUND;
}

/*







|
>
>







2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
      if( zTFile ){
        getTempname(pFile->pVfs->mxPathname, zTFile);
        *(char**)pArg = zTFile;
      }
      return SQLITE_OK;
    }
    case SQLITE_FCNTL_MMAP_LIMIT: {
      i64 newLimit = *(i64*)pArg;
      *(i64*) = pFile->mmapLimit;
      if( newLimit>=0 ) pFile->mmapLimit = newLimit;
      return SQLITE_OK;
    }
  }
  return SQLITE_NOTFOUND;
}

/*
Changes to src/pager.c.
3354
3355
3356
3357
3358
3359
3360

3361

3362
3363
3364
3365
3366
3367
3368
3369
3370

/*
** 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->mxMmap>0;

    sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_MMAP_LIMIT,
                             (void*)&pPager->mxMmap);
  }
}

/*
** Change the maximum size of any memory mapping made of the database file.
*/
void sqlite3PagerSetMmapLimit(Pager *pPager, sqlite3_int64 mxMmap){







>

>
|
<







3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364

3365
3366
3367
3368
3369
3370
3371

/*
** 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) ){
    sqlite3_int64 mx;
    pPager->bUseFetch = (fd->pMethods->iVersion>=3) && pPager->mxMmap>0;
    mx = pPager->mxMmap;
    sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_MMAP_LIMIT, &mx);

  }
}

/*
** Change the maximum size of any memory mapping made of the database file.
*/
void sqlite3PagerSetMmapLimit(Pager *pPager, sqlite3_int64 mxMmap){
Changes to src/pragma.c.
755
756
757
758
759
760
761

762
763
764
765
766
767
768
769
770
771
772
773
774




775
776
777
778
779
780
781
  ** 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 ){

    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;
      for(ii=db->nDb-1; ii>=0; ii--){
        if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
          sqlite3BtreeSetMmapLimit(db->aDb[ii].pBt, size);
        }
      }
    }




  }else

  /*
  **   PRAGMA temp_store
  **   PRAGMA temp_store = "default"|"memory"|"file"
  **
  ** Return or set the local value of the temp_store flag.  Changing







>


<

|
|
|


|



>
>
>
>







755
756
757
758
759
760
761
762
763
764

765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
  ** 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;
    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;
      for(ii=db->nDb-1; ii>=0; ii--){
        if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
          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

  /*
  **   PRAGMA temp_store
  **   PRAGMA temp_store = "default"|"memory"|"file"
  **
  ** Return or set the local value of the temp_store flag.  Changing
Changes to src/sqlite.h.in.
884
885
886
887
888
889
890
891


892
893
894
895
896
897
898
** temporary filenames for TEMP tables and other internal uses.  The
** argument should be a char** which will be filled with the filename
** 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 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>
*/
#define SQLITE_FCNTL_LOCKSTATE               1
#define SQLITE_GET_LOCKPROXYFILE             2
#define SQLITE_SET_LOCKPROXYFILE             3
#define SQLITE_LAST_ERRNO                    4







|
>
>







884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
** temporary filenames for TEMP tables and other internal uses.  The
** argument should be a char** which will be filled with the filename
** 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 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.  The
** pointer is overwritten with the old value.  The limit is not changed if
** the original value pointed to is negative.
**
** </ul>
*/
#define SQLITE_FCNTL_LOCKSTATE               1
#define SQLITE_GET_LOCKPROXYFILE             2
#define SQLITE_SET_LOCKPROXYFILE             3
#define SQLITE_LAST_ERRNO                    4
Changes to src/sqliteLimit.h.
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# if defined(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(TARGET_OS_IPHONE)) \
  || defined(__sun) \
  || defined(__DragonFly__) \
  || defined(__FreeBSD__) \
  || defined(__NetBSD__) \
  || defined(__OpenBSD__)
#   define SQLITE_DEFAULT_MMAP_LIMIT (256*1024*1024)
# else
#   define SQLITE_DEFAULT_MMAP_LIMIT 0
# endif
#endif







|
<
<
|
<
<
|




215
216
217
218
219
220
221
222


223


224
225
226
227
228
# if defined(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
Changes to test/mmap1.test.
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  INSERT INTO t1 VALUES(rblob(500), rblob(500));
  INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; --    2
  INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; --    4
  INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; --    8
  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}

do_execsql_test 2.2 {
  PRAGMA auto_vacuum;
  SELECT count(*) FROM t1;
} {1 32}

do_test 2.3 {







|







104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  INSERT INTO t1 VALUES(rblob(500), rblob(500));
  INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; --    2
  INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; --    4
  INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; --    8
  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;
} {67108864 wal 0 103 103}

do_execsql_test 2.2 {
  PRAGMA auto_vacuum;
  SELECT count(*) FROM t1;
} {1 32}

do_test 2.3 {