/ Check-in [ea1404a1]
Login

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

Overview
Comment: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.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:ea1404a10abd7f68e1f8e0708c8a3199d1f79665
User & Date: drh 2013-04-15 17:03:42
Context
2013-04-15
20:08
Expand scope of the SQLITE_MAX_MMAP_SIZE define for the Win32 VFS. check-in: f4b8faab user: mistachkin tags: trunk
17:03
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. check-in: ea1404a1 user: drh tags: trunk
13:10
Fix a formatting typo in a comment. No changes to code. check-in: 34124249 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to mptest/config01.test.

     1      1   /*
     2      2   ** Configure five tasks in different ways, then run tests.
     3      3   */
     4      4   --if vfsname() GLOB 'unix'
     5      5   PRAGMA page_size=8192;
     6      6   --task 1
     7      7     PRAGMA journal_mode=PERSIST;
     8         -  PRAGMA mmap_limit=0;
            8  +  PRAGMA mmap_size=0;
     9      9   --end
    10     10   --task 2
    11     11     PRAGMA journal_mode=TRUNCATE;
    12         -  PRAGMA mmap_limit=28672;
           12  +  PRAGMA mmap_size=28672;
    13     13   --end
    14     14   --task 3
    15     15     PRAGMA journal_mode=MEMORY;
    16     16   --end
    17     17   --task 4
    18     18     PRAGMA journal_mode=OFF;
    19     19   --end
           20  +--task 4
           21  +  PRAGMA mmap_size(268435456);
           22  +--end
    20     23   --source multiwrite01.test
    21     24   --wait all
    22     25   PRAGMA page_size=16384;
    23     26   VACUUM;
    24     27   CREATE TABLE pgsz(taskid, sz INTEGER);
    25     28   --task 1
    26     29     INSERT INTO pgsz VALUES(1, eval('PRAGMA page_size'));

Changes to mptest/config02.test.

     1      1   /*
     2      2   ** Configure five tasks in different ways, then run tests.
     3      3   */
     4      4   PRAGMA page_size=512;
     5      5   --task 1
     6         -  PRAGMA mmap_limit=0;
            6  +  PRAGMA mmap_size=0;
     7      7   --end
     8      8   --task 2
     9         -  PRAGMA mmap_limit=28672;
            9  +  PRAGMA mmap_size=28672;
    10     10   --end
    11     11   --task 3
    12         -  PRAGMA mmap_limit=8192;
           12  +  PRAGMA mmap_size=8192;
    13     13   --end
    14     14   --task 4
    15         -  PRAGMA mmap_limit=65536;
           15  +  PRAGMA mmap_size=65536;
           16  +--end
           17  +--task 5
           18  +  PRAGMA mmap_size=268435456;
    16     19   --end
    17     20   --source multiwrite01.test
    18     21   --source crash02.subtest
    19     22   PRAGMA page_size=1024;
    20     23   VACUUM;
    21     24   CREATE TABLE pgsz(taskid, sz INTEGER);
    22     25   --task 1

Changes to src/btree.c.

  1872   1872       if( pBt==0 ){
  1873   1873         rc = SQLITE_NOMEM;
  1874   1874         goto btree_open_out;
  1875   1875       }
  1876   1876       rc = sqlite3PagerOpen(pVfs, &pBt->pPager, zFilename,
  1877   1877                             EXTRA_SIZE, flags, vfsFlags, pageReinit);
  1878   1878       if( rc==SQLITE_OK ){
  1879         -      sqlite3PagerSetMmapLimit(pBt->pPager, db->mxMmap);
         1879  +      sqlite3PagerSetMmapLimit(pBt->pPager, db->szMmap);
  1880   1880         rc = sqlite3PagerReadFileheader(pBt->pPager,sizeof(zDbHeader),zDbHeader);
  1881   1881       }
  1882   1882       if( rc!=SQLITE_OK ){
  1883   1883         goto btree_open_out;
  1884   1884       }
  1885   1885       pBt->openFlags = (u8)flags;
  1886   1886       pBt->db = db;
................................................................................
  2143   2143     return SQLITE_OK;
  2144   2144   }
  2145   2145   
  2146   2146   /*
  2147   2147   ** Change the limit on the amount of the database file that may be
  2148   2148   ** memory mapped.
  2149   2149   */
  2150         -int sqlite3BtreeSetMmapLimit(Btree *p, sqlite3_int64 mxMmap){
         2150  +int sqlite3BtreeSetMmapLimit(Btree *p, sqlite3_int64 szMmap){
  2151   2151     BtShared *pBt = p->pBt;
  2152   2152     assert( sqlite3_mutex_held(p->db->mutex) );
  2153   2153     sqlite3BtreeEnter(p);
  2154         -  sqlite3PagerSetMmapLimit(pBt->pPager, mxMmap);
         2154  +  sqlite3PagerSetMmapLimit(pBt->pPager, szMmap);
  2155   2155     sqlite3BtreeLeave(p);
  2156   2156     return SQLITE_OK;
  2157   2157   }
  2158   2158   
  2159   2159   /*
  2160   2160   ** Change the way data is synced to disk in order to increase or decrease
  2161   2161   ** how well the database resists damage due to OS crashes and power

Changes to src/ctime.c.

    53     53   #endif
    54     54   #ifdef SQLITE_DEBUG
    55     55     "DEBUG",
    56     56   #endif
    57     57   #ifdef SQLITE_DEFAULT_LOCKING_MODE
    58     58     "DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE),
    59     59   #endif
    60         -#ifdef SQLITE_DEFAULT_MMAP_LIMIT
    61         -  "DEFAULT_MMAP_LIMIT=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_LIMIT),
           60  +#ifdef SQLITE_DEFAULT_MMAP_SIZE
           61  +  "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE),
    62     62   #endif
    63     63   #ifdef SQLITE_DISABLE_DIRSYNC
    64     64     "DISABLE_DIRSYNC",
    65     65   #endif
    66     66   #ifdef SQLITE_DISABLE_LFS
    67     67     "DISABLE_LFS",
    68     68   #endif
    69         -#ifdef SQLITE_DISABLE_MMAP
    70         -  "DISABLE_MMAP",
    71         -#endif
    72     69   #ifdef SQLITE_ENABLE_ATOMIC_WRITE
    73     70     "ENABLE_ATOMIC_WRITE",
    74     71   #endif
    75     72   #ifdef SQLITE_ENABLE_CEROD
    76     73     "ENABLE_CEROD",
    77     74   #endif
    78     75   #ifdef SQLITE_ENABLE_COLUMN_METADATA
................................................................................
   149    146   #endif
   150    147   #ifdef SQLITE_INT64_TYPE
   151    148     "INT64_TYPE",
   152    149   #endif
   153    150   #ifdef SQLITE_LOCK_TRACE
   154    151     "LOCK_TRACE",
   155    152   #endif
          153  +#ifdef SQLITE_MAX_MMAP_SIZE
          154  +  "MAX_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE),
          155  +#endif
   156    156   #ifdef SQLITE_MAX_SCHEMA_RETRY
   157    157     "MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY),
   158    158   #endif
   159    159   #ifdef SQLITE_MEMDEBUG
   160    160     "MEMDEBUG",
   161    161   #endif
   162    162   #ifdef SQLITE_MIXED_ENDIAN_64BIT_FLOAT

Changes to src/global.c.

   152    152      500,                       /* nLookaside */
   153    153      {0,0,0,0,0,0,0,0},         /* m */
   154    154      {0,0,0,0,0,0,0,0,0},       /* mutex */
   155    155      {0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */
   156    156      (void*)0,                  /* pHeap */
   157    157      0,                         /* nHeap */
   158    158      0, 0,                      /* mnHeap, mxHeap */
   159         -   SQLITE_DEFAULT_MMAP_LIMIT, /* mxMmap */                       
          159  +   SQLITE_DEFAULT_MMAP_SIZE,  /* szMmap */
          160  +   SQLITE_MAX_MMAP_SIZE,      /* mxMmap */
   160    161      (void*)0,                  /* pScratch */
   161    162      0,                         /* szScratch */
   162    163      0,                         /* nScratch */
   163    164      (void*)0,                  /* pPage */
   164    165      0,                         /* szPage */
   165    166      0,                         /* nPage */
   166    167      0,                         /* mxParserStack */

Changes to src/main.c.

   492    492         typedef void(*SQLLOGFUNC_t)(void*, sqlite3*, const char*, int);
   493    493         sqlite3GlobalConfig.xSqllog = va_arg(ap, SQLLOGFUNC_t);
   494    494         sqlite3GlobalConfig.pSqllogArg = va_arg(ap, void *);
   495    495         break;
   496    496       }
   497    497   #endif
   498    498   
   499         -    case SQLITE_CONFIG_MMAP_LIMIT: {
          499  +    case SQLITE_CONFIG_MMAP_SIZE: {
          500  +      sqlite3_int64 szMmap = va_arg(ap, sqlite3_int64);
   500    501         sqlite3_int64 mxMmap = va_arg(ap, sqlite3_int64);
   501         -      if( mxMmap<0 ) mxMmap = SQLITE_DEFAULT_MMAP_LIMIT;
          502  +      if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ){
          503  +        mxMmap = SQLITE_MAX_MMAP_SIZE;
          504  +      }
   502    505         sqlite3GlobalConfig.mxMmap = mxMmap;
          506  +      if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
          507  +      if( szMmap>mxMmap) szMmap = mxMmap;
          508  +      sqlite3GlobalConfig.szMmap = szMmap;
   503    509         break;
   504    510       }
   505    511   
   506    512       default: {
   507    513         rc = SQLITE_ERROR;
   508    514         break;
   509    515       }
................................................................................
  2319   2325     db->magic = SQLITE_MAGIC_BUSY;
  2320   2326     db->aDb = db->aDbStatic;
  2321   2327   
  2322   2328     assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
  2323   2329     memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
  2324   2330     db->autoCommit = 1;
  2325   2331     db->nextAutovac = -1;
  2326         -  db->mxMmap = sqlite3GlobalConfig.mxMmap;
         2332  +  db->szMmap = sqlite3GlobalConfig.szMmap;
  2327   2333     db->nextPagesize = 0;
  2328   2334     db->flags |= SQLITE_ShortColNames | SQLITE_AutoIndex | SQLITE_EnableTrigger
  2329   2335   #if SQLITE_DEFAULT_FILE_FORMAT<4
  2330   2336                    | SQLITE_LegacyFileFmt
  2331   2337   #endif
  2332   2338   #ifdef SQLITE_ENABLE_LOAD_EXTENSION
  2333   2339                    | SQLITE_LoadExtension

Changes to src/os.c.

   137    137     int bExtend,                    /* True to extend file if necessary */
   138    138     void volatile **pp              /* OUT: Pointer to mapping */
   139    139   ){
   140    140     DO_OS_MALLOC_TEST(id);
   141    141     return id->pMethods->xShmMap(id, iPage, pgsz, bExtend, pp);
   142    142   }
   143    143   
   144         -#if !defined(SQLITE_DISABLE_MMAP)
          144  +#if SQLITE_MAX_MMAP_SIZE>0
   145    145   /* The real implementation of xFetch and xUnfetch */
   146    146   int sqlite3OsFetch(sqlite3_file *id, i64 iOff, int iAmt, void **pp){
   147    147     DO_OS_MALLOC_TEST(id);
   148    148     return id->pMethods->xFetch(id, iOff, iAmt, pp);
   149    149   }
   150    150   int sqlite3OsUnfetch(sqlite3_file *id, i64 iOff, void *p){
   151    151     return id->pMethods->xUnfetch(id, iOff, p);

Changes to src/os_unix.c.

   223    223     void *lockingContext;               /* Locking style specific state */
   224    224     UnixUnusedFd *pUnused;              /* Pre-allocated UnixUnusedFd */
   225    225     const char *zPath;                  /* Name of the file */
   226    226     unixShm *pShm;                      /* Shared memory segment information */
   227    227     int szChunk;                        /* Configured by FCNTL_CHUNK_SIZE */
   228    228     int nFetchOut;                      /* Number of outstanding xFetch refs */
   229    229     sqlite3_int64 mmapSize;             /* Usable size of mapping at pMapRegion */
   230         -  sqlite3_int64 mmapOrigsize;         /* Actual size of mapping at pMapRegion */
   231         -  sqlite3_int64 mmapLimit;            /* Configured FCNTL_MMAP_LIMIT value */
          230  +  sqlite3_int64 mmapSizeActual;       /* Actual size of mapping at pMapRegion */
          231  +  sqlite3_int64 mmapSizeMax;          /* Configured FCNTL_MMAP_SIZE value */
   232    232     void *pMapRegion;                   /* Memory mapped region */
   233    233   #ifdef __QNXNTO__
   234    234     int sectorSize;                     /* Device sector size */
   235    235     int deviceCharacteristics;          /* Precomputed device characteristics */
   236    236   #endif
   237    237   #if SQLITE_ENABLE_LOCKING_STYLE
   238    238     int openFlags;                      /* The flags specified at open() */
................................................................................
  3158   3158   #if 0
  3159   3159     assert( pFile->pUnused==0
  3160   3160          || offset>=PENDING_BYTE+512
  3161   3161          || offset+amt<=PENDING_BYTE 
  3162   3162     );
  3163   3163   #endif
  3164   3164   
  3165         -#if !defined(SQLITE_DISABLE_MMAP)
         3165  +#if SQLITE_MAX_MMAP_SIZE>0
  3166   3166     /* Deal with as much of this read request as possible by transfering
  3167   3167     ** data from the memory mapping using memcpy().  */
  3168   3168     if( offset<pFile->mmapSize ){
  3169   3169       if( offset+amt <= pFile->mmapSize ){
  3170   3170         memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt);
  3171   3171         return SQLITE_OK;
  3172   3172       }else{
................................................................................
  3279   3279         if( rc!=4 || memcmp(oldCntr, &((char*)pBuf)[24-offset], 4)!=0 ){
  3280   3280           pFile->transCntrChng = 1;  /* The transaction counter has changed */
  3281   3281         }
  3282   3282       }
  3283   3283     }
  3284   3284   #endif
  3285   3285   
  3286         -#if !defined(SQLITE_DISABLE_MMAP)
         3286  +#if SQLITE_MAX_MMAP_SIZE>0
  3287   3287     /* Deal with as much of this write request as possible by transfering
  3288   3288     ** data from the memory mapping using memcpy().  */
  3289   3289     if( offset<pFile->mmapSize ){
  3290   3290       if( offset+amt <= pFile->mmapSize ){
  3291   3291         memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt);
  3292   3292         return SQLITE_OK;
  3293   3293       }else{
................................................................................
  3674   3674           if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
  3675   3675           iWrite += nBlk;
  3676   3676         }
  3677   3677   #endif
  3678   3678       }
  3679   3679     }
  3680   3680   
  3681         -  if( pFile->mmapLimit>0 && nByte>pFile->mmapSize ){
         3681  +  if( pFile->mmapSizeMax>0 && nByte>pFile->mmapSize ){
  3682   3682       int rc;
  3683   3683       if( pFile->szChunk<=0 ){
  3684   3684         if( robust_ftruncate(pFile->h, nByte) ){
  3685   3685           pFile->lastErrno = errno;
  3686   3686           return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
  3687   3687         }
  3688   3688       }
................................................................................
  3754   3754         char *zTFile = sqlite3_malloc( pFile->pVfs->mxPathname );
  3755   3755         if( zTFile ){
  3756   3756           unixGetTempname(pFile->pVfs->mxPathname, zTFile);
  3757   3757           *(char**)pArg = zTFile;
  3758   3758         }
  3759   3759         return SQLITE_OK;
  3760   3760       }
  3761         -    case SQLITE_FCNTL_MMAP_LIMIT: {
         3761  +    case SQLITE_FCNTL_MMAP_SIZE: {
  3762   3762         i64 newLimit = *(i64*)pArg;
  3763         -      *(i64*)pArg = pFile->mmapLimit;
         3763  +      if( newLimit>sqlite3GlobalConfig.mxMmap ){
         3764  +        newLimit = sqlite3GlobalConfig.mxMmap;
         3765  +      }
         3766  +      *(i64*)pArg = pFile->mmapSizeMax;
  3764   3767         if( newLimit>=0 ){
  3765         -        pFile->mmapLimit = newLimit;
         3768  +        pFile->mmapSizeMax = newLimit;
  3766   3769           if( newLimit<pFile->mmapSize ) pFile->mmapSize = newLimit;
  3767   3770         }
  3768   3771         return SQLITE_OK;
  3769   3772       }
  3770   3773   #ifdef SQLITE_DEBUG
  3771   3774       /* The pager calls this method to signal that it has done
  3772   3775       ** a rollback and that the database is therefore unchanged and
................................................................................
  4570   4573   #endif /* #ifndef SQLITE_OMIT_WAL */
  4571   4574   
  4572   4575   /*
  4573   4576   ** If it is currently memory mapped, unmap file pFd.
  4574   4577   */
  4575   4578   static void unixUnmapfile(unixFile *pFd){
  4576   4579     assert( pFd->nFetchOut==0 );
  4577         -#ifndef SQLITE_DISABLE_MMAP
         4580  +#if SQLITE_MAX_MMAP_SIZE>0
  4578   4581     if( pFd->pMapRegion ){
  4579         -    osMunmap(pFd->pMapRegion, pFd->mmapOrigsize);
         4582  +    osMunmap(pFd->pMapRegion, pFd->mmapSizeActual);
  4580   4583       pFd->pMapRegion = 0;
  4581   4584       pFd->mmapSize = 0;
  4582         -    pFd->mmapOrigsize = 0;
         4585  +    pFd->mmapSizeActual = 0;
  4583   4586     }
  4584   4587   #endif
  4585   4588   }
  4586   4589   
  4587         -#ifndef SQLITE_DISABLE_MMAP
         4590  +#if SQLITE_MAX_MMAP_SIZE>0
  4588   4591   /*
  4589   4592   ** Return the system page size.
  4590   4593   */
  4591   4594   static int unixGetPagesize(void){
  4592   4595   #if HAVE_MREMAP
  4593   4596     return 512;
  4594   4597   #elif defined(_BSD_SOURCE)
  4595   4598     return getpagesize();
  4596   4599   #else
  4597   4600     return (int)sysconf(_SC_PAGESIZE);
  4598   4601   #endif
  4599   4602   }
  4600         -#endif /* SQLITE_DISABLE_MMAP */
         4603  +#endif /* SQLITE_MAX_MMAP_SIZE>0 */
  4601   4604   
  4602         -#ifndef SQLITE_DISABLE_MMAP
         4605  +#if SQLITE_MAX_MMAP_SIZE>0
  4603   4606   /*
  4604   4607   ** Attempt to set the size of the memory mapping maintained by file 
  4605   4608   ** descriptor pFd to nNew bytes. Any existing mapping is discarded.
  4606   4609   **
  4607   4610   ** If successful, this function sets the following variables:
  4608   4611   **
  4609   4612   **       unixFile.pMapRegion
  4610   4613   **       unixFile.mmapSize
  4611         -**       unixFile.mmapOrigsize
         4614  +**       unixFile.mmapSizeActual
  4612   4615   **
  4613   4616   ** If unsuccessful, an error message is logged via sqlite3_log() and
  4614   4617   ** the three variables above are zeroed. In this case SQLite should
  4615   4618   ** continue accessing the database using the xRead() and xWrite()
  4616   4619   ** methods.
  4617   4620   */
  4618   4621   static void unixRemapfile(
  4619   4622     unixFile *pFd,                  /* File descriptor object */
  4620   4623     i64 nNew                        /* Required mapping size */
  4621   4624   ){
  4622   4625     const char *zErr = "mmap";
  4623   4626     int h = pFd->h;                      /* File descriptor open on db file */
  4624   4627     u8 *pOrig = (u8 *)pFd->pMapRegion;   /* Pointer to current file mapping */
  4625         -  i64 nOrig = pFd->mmapOrigsize;       /* Size of pOrig region in bytes */
         4628  +  i64 nOrig = pFd->mmapSizeActual;     /* Size of pOrig region in bytes */
  4626   4629     u8 *pNew = 0;                        /* Location of new mapping */
  4627   4630     int flags = PROT_READ;               /* Flags to pass to mmap() */
  4628   4631   
  4629   4632     assert( pFd->nFetchOut==0 );
  4630   4633     assert( nNew>pFd->mmapSize );
  4631         -  assert( nNew<=pFd->mmapLimit );
         4634  +  assert( nNew<=pFd->mmapSizeMax );
  4632   4635     assert( nNew>0 );
  4633         -  assert( pFd->mmapOrigsize>=pFd->mmapSize );
         4636  +  assert( pFd->mmapSizeActual>=pFd->mmapSize );
  4634   4637     assert( MAP_FAILED!=0 );
  4635   4638   
  4636   4639     if( (pFd->ctrlFlags & UNIXFILE_RDONLY)==0 ) flags |= PROT_WRITE;
  4637   4640   
  4638   4641     if( pOrig ){
  4639   4642       const int szSyspage = unixGetPagesize();
  4640   4643       i64 nReuse = (pFd->mmapSize & ~(szSyspage-1));
................................................................................
  4675   4678       pNew = 0;
  4676   4679       nNew = 0;
  4677   4680       unixLogError(SQLITE_OK, zErr, pFd->zPath);
  4678   4681   
  4679   4682       /* If the mmap() above failed, assume that all subsequent mmap() calls
  4680   4683       ** will probably fail too. Fall back to using xRead/xWrite exclusively
  4681   4684       ** in this case.  */
  4682         -    pFd->mmapLimit = 0;
         4685  +    pFd->mmapSizeMax = 0;
  4683   4686     }
  4684   4687     pFd->pMapRegion = (void *)pNew;
  4685         -  pFd->mmapSize = pFd->mmapOrigsize = nNew;
         4688  +  pFd->mmapSize = pFd->mmapSizeActual = nNew;
  4686   4689   }
  4687   4690   #endif
  4688   4691   
  4689   4692   /*
  4690   4693   ** Memory map or remap the file opened by file-descriptor pFd (if the file
  4691   4694   ** is already mapped, the existing mapping is replaced by the new). Or, if 
  4692   4695   ** there already exists a mapping for this file, and there are still 
................................................................................
  4699   4702   ** using SQLITE_FCNTL_MMAP_LIMIT, whichever is smaller.
  4700   4703   **
  4701   4704   ** SQLITE_OK is returned if no error occurs (even if the mapping is not
  4702   4705   ** recreated as a result of outstanding references) or an SQLite error
  4703   4706   ** code otherwise.
  4704   4707   */
  4705   4708   static int unixMapfile(unixFile *pFd, i64 nByte){
  4706         -#ifndef SQLITE_DISABLE_MMAP
         4709  +#if SQLITE_MAX_MMAP_SIZE>0
  4707   4710     i64 nMap = nByte;
  4708   4711     int rc;
  4709   4712   
  4710   4713     assert( nMap>=0 || pFd->nFetchOut==0 );
  4711   4714     if( pFd->nFetchOut>0 ) return SQLITE_OK;
  4712   4715   
  4713   4716     if( nMap<0 ){
................................................................................
  4714   4717       struct stat statbuf;          /* Low-level file information */
  4715   4718       rc = osFstat(pFd->h, &statbuf);
  4716   4719       if( rc!=SQLITE_OK ){
  4717   4720         return SQLITE_IOERR_FSTAT;
  4718   4721       }
  4719   4722       nMap = statbuf.st_size;
  4720   4723     }
  4721         -  if( nMap>pFd->mmapLimit ){
  4722         -    nMap = pFd->mmapLimit;
         4724  +  if( nMap>pFd->mmapSizeMax ){
         4725  +    nMap = pFd->mmapSizeMax;
  4723   4726     }
  4724   4727   
  4725   4728     if( nMap!=pFd->mmapSize ){
  4726   4729       if( nMap>0 ){
  4727   4730         unixRemapfile(pFd, nMap);
  4728   4731       }else{
  4729   4732         unixUnmapfile(pFd);
................................................................................
  4743   4746   ** Finally, if an error does occur, return an SQLite error code. The final
  4744   4747   ** value of *pp is undefined in this case.
  4745   4748   **
  4746   4749   ** If this function does return a pointer, the caller must eventually 
  4747   4750   ** release the reference by calling unixUnfetch().
  4748   4751   */
  4749   4752   static int unixFetch(sqlite3_file *fd, i64 iOff, int nAmt, void **pp){
  4750         -#ifndef SQLITE_DISABLE_MMAP
         4753  +#if SQLITE_MAX_MMAP_SIZE>0
  4751   4754     unixFile *pFd = (unixFile *)fd;   /* The underlying database file */
  4752   4755   #endif
  4753   4756     *pp = 0;
  4754   4757   
  4755         -#ifndef SQLITE_DISABLE_MMAP
  4756         -  if( pFd->mmapLimit>0 ){
         4758  +#if SQLITE_MAX_MMAP_SIZE>0
         4759  +  if( pFd->mmapSizeMax>0 ){
  4757   4760       if( pFd->pMapRegion==0 ){
  4758   4761         int rc = unixMapfile(pFd, -1);
  4759   4762         if( rc!=SQLITE_OK ) return rc;
  4760   4763       }
  4761   4764       if( pFd->mmapSize >= iOff+nAmt ){
  4762   4765         *pp = &((u8 *)pFd->pMapRegion)[iOff];
  4763   4766         pFd->nFetchOut++;
................................................................................
  5122   5125     assert( zFilename!=0 || (ctrlFlags & UNIXFILE_NOLOCK)!=0 );
  5123   5126   
  5124   5127     OSTRACE(("OPEN    %-3d %s\n", h, zFilename));
  5125   5128     pNew->h = h;
  5126   5129     pNew->pVfs = pVfs;
  5127   5130     pNew->zPath = zFilename;
  5128   5131     pNew->ctrlFlags = (u8)ctrlFlags;
  5129         -  pNew->mmapLimit = sqlite3GlobalConfig.mxMmap;
         5132  +  pNew->mmapSizeMax = sqlite3GlobalConfig.mxMmap;
  5130   5133     if( sqlite3_uri_boolean(((ctrlFlags & UNIXFILE_URI) ? zFilename : 0),
  5131   5134                              "psow", SQLITE_POWERSAFE_OVERWRITE) ){
  5132   5135       pNew->ctrlFlags |= UNIXFILE_PSOW;
  5133   5136     }
  5134   5137     if( strcmp(pVfs->zName,"unix-excl")==0 ){
  5135   5138       pNew->ctrlFlags |= UNIXFILE_EXCL;
  5136   5139     }

Changes to src/os_win.c.

   146    146   #if SQLITE_OS_WINCE
   147    147     LPWSTR zDeleteOnClose;  /* Name of file to delete when closing */
   148    148     HANDLE hMutex;          /* Mutex used to control access to shared lock */  
   149    149     HANDLE hShared;         /* Shared memory segment used for locking */
   150    150     winceLock local;        /* Locks obtained by this instance of winFile */
   151    151     winceLock *shared;      /* Global shared lock memory for the file  */
   152    152   #endif
   153         -  int nFetchOut;               /* Number of outstanding xFetch references */
   154         -  HANDLE hMap;                 /* Handle for accessing memory mapping */
   155         -  void *pMapRegion;            /* Area memory mapped */
   156         -  sqlite3_int64 mmapSize;      /* Usable size of mapped region */
   157         -  sqlite3_int64 mmapOrigsize;  /* Actual size of mapped region */
   158         -  sqlite3_int64 mmapLimit;     /* Configured FCNTL_MMAP_LIMIT value */
          153  +  int nFetchOut;                /* Number of outstanding xFetch references */
          154  +  HANDLE hMap;                  /* Handle for accessing memory mapping */
          155  +  void *pMapRegion;             /* Area memory mapped */
          156  +  sqlite3_int64 mmapSize;       /* Usable size of mapped region */
          157  +  sqlite3_int64 mmapSizeActual; /* Actual size of mapped region */
          158  +  sqlite3_int64 mmapSizeMax;    /* Configured FCNTL_MMAP_SIZE value */
   159    159   };
   160    160   
   161    161   /*
   162    162   ** Allowed values for winFile.ctrlFlags
   163    163   */
   164    164   #define WINFILE_RDONLY          0x02   /* Connection is read only */
   165    165   #define WINFILE_PERSIST_WAL     0x04   /* Persistent WAL mode */
................................................................................
  2144   2144     int nRetry = 0;                 /* Number of retrys */
  2145   2145   
  2146   2146     assert( id!=0 );
  2147   2147     assert( amt>0 );
  2148   2148     SimulateIOError(return SQLITE_IOERR_READ);
  2149   2149     OSTRACE(("READ %d lock=%d\n", pFile->h, pFile->locktype));
  2150   2150   
  2151         -#if !defined(SQLITE_DISABLE_MMAP)
         2151  +#if SQLITE_MAX_MMAP_SIZE>0
  2152   2152     /* Deal with as much of this read request as possible by transfering
  2153   2153     ** data from the memory mapping using memcpy().  */
  2154   2154     if( offset<pFile->mmapSize ){
  2155   2155       if( offset+amt <= pFile->mmapSize ){
  2156   2156         memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt);
  2157   2157         return SQLITE_OK;
  2158   2158       }else{
................................................................................
  2210   2210     assert( amt>0 );
  2211   2211     assert( pFile );
  2212   2212     SimulateIOError(return SQLITE_IOERR_WRITE);
  2213   2213     SimulateDiskfullError(return SQLITE_FULL);
  2214   2214   
  2215   2215     OSTRACE(("WRITE %d lock=%d\n", pFile->h, pFile->locktype));
  2216   2216   
  2217         -#if !defined(SQLITE_DISABLE_MMAP)
         2217  +#if SQLITE_MAX_MMAP_SIZE>0
  2218   2218     /* Deal with as much of this write request as possible by transfering
  2219   2219     ** data from the memory mapping using memcpy().  */
  2220   2220     if( offset<pFile->mmapSize ){
  2221   2221       if( offset+amt <= pFile->mmapSize ){
  2222   2222         memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt);
  2223   2223         return SQLITE_OK;
  2224   2224       }else{
................................................................................
  2321   2321     }else if( 0==osSetEndOfFile(pFile->h) &&
  2322   2322               ((lastErrno = osGetLastError())!=ERROR_USER_MAPPED_FILE) ){
  2323   2323       pFile->lastErrno = lastErrno;
  2324   2324       rc = winLogError(SQLITE_IOERR_TRUNCATE, pFile->lastErrno,
  2325   2325                        "winTruncate2", pFile->zPath);
  2326   2326     }
  2327   2327   
  2328         -#if !defined(SQLITE_DISABLE_MMAP)
         2328  +#if SQLITE_MAX_MMAP_SIZE>0
  2329   2329     /* If the file was truncated to a size smaller than the currently
  2330   2330     ** mapped region, reduce the effective mapping size as well. SQLite will
  2331   2331     ** use read() and write() to access data beyond this point from now on.
  2332   2332     */
  2333   2333     if( pFile->pMapRegion && nByte<pFile->mmapSize ){
  2334   2334       pFile->mmapSize = nByte;
  2335   2335     }
................................................................................
  2838   2838         char *zTFile = sqlite3MallocZero( pFile->pVfs->mxPathname );
  2839   2839         if( zTFile ){
  2840   2840           getTempname(pFile->pVfs->mxPathname, zTFile);
  2841   2841           *(char**)pArg = zTFile;
  2842   2842         }
  2843   2843         return SQLITE_OK;
  2844   2844       }
  2845         -    case SQLITE_FCNTL_MMAP_LIMIT: {
         2845  +    case SQLITE_FCNTL_MMAP_SIZE: {
  2846   2846         i64 newLimit = *(i64*)pArg;
  2847         -      *(i64*)pArg = pFile->mmapLimit;
  2848         -      if( newLimit>=0 ) pFile->mmapLimit = newLimit;
         2847  +      if( newLimit>sqlite3GlobalConfig.mxMmap ){
         2848  +        newLimit = sqlite3GlobalConfig.mxMmap;
         2849  +      }
         2850  +      *(i64*)pArg = pFile->mmapSizeMax;
         2851  +      if( newLimit>=0 ) pFile->mmapSizeMax = newLimit;
  2849   2852         return SQLITE_OK;
  2850   2853       }
  2851   2854     }
  2852   2855     return SQLITE_NOTFOUND;
  2853   2856   }
  2854   2857   
  2855   2858   /*
................................................................................
  3519   3522   #endif /* #ifndef SQLITE_OMIT_WAL */
  3520   3523   
  3521   3524   /*
  3522   3525   ** Cleans up the mapped region of the specified file, if any.
  3523   3526   */
  3524   3527   static int winUnmapfile(winFile *pFile){
  3525   3528     assert( pFile!=0 );
  3526         -#if !defined(SQLITE_DISABLE_MMAP)
         3529  +#if SQLITE_MAX_MMAP_SIZE>0
  3527   3530     if( pFile->pMapRegion ){
  3528   3531       if( !osUnmapViewOfFile(pFile->pMapRegion) ){
  3529   3532         pFile->lastErrno = osGetLastError();
  3530   3533         return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
  3531   3534                            "winUnmap1", pFile->zPath);
  3532   3535       }
  3533   3536       pFile->pMapRegion = 0;
  3534   3537       pFile->mmapSize = 0;
  3535         -    pFile->mmapOrigsize = 0;
         3538  +    pFile->mmapSizeActual = 0;
  3536   3539     }
  3537   3540     if( pFile->hMap!=NULL ){
  3538   3541       if( !osCloseHandle(pFile->hMap) ){
  3539   3542         pFile->lastErrno = osGetLastError();
  3540   3543         return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
  3541   3544                            "winUnmap2", pFile->zPath);
  3542   3545       }
  3543   3546       pFile->hMap = NULL;
  3544   3547     }
  3545   3548   #endif
  3546   3549     return SQLITE_OK;
  3547   3550   }
  3548   3551   
  3549         -#if !defined(SQLITE_DISABLE_MMAP)
         3552  +#if SQLITE_MAX_MMAP_SIZE>0
  3550   3553   /*
  3551   3554   ** Memory map or remap the file opened by file-descriptor pFd (if the file
  3552   3555   ** is already mapped, the existing mapping is replaced by the new). Or, if 
  3553   3556   ** there already exists a mapping for this file, and there are still 
  3554   3557   ** outstanding xFetch() references to it, this function is a no-op.
  3555   3558   **
  3556   3559   ** If parameter nByte is non-negative, then it is the requested size of 
  3557   3560   ** the mapping to create. Otherwise, if nByte is less than zero, then the 
  3558   3561   ** requested size is the size of the file on disk. The actual size of the
  3559   3562   ** created mapping is either the requested size or the value configured 
  3560         -** using SQLITE_FCNTL_MMAP_LIMIT, whichever is smaller.
         3563  +** using SQLITE_FCNTL_MMAP_SIZE, whichever is smaller.
  3561   3564   **
  3562   3565   ** SQLITE_OK is returned if no error occurs (even if the mapping is not
  3563   3566   ** recreated as a result of outstanding references) or an SQLite error
  3564   3567   ** code otherwise.
  3565   3568   */
  3566   3569   static int winMapfile(winFile *pFd, sqlite3_int64 nByte){
  3567   3570     sqlite3_int64 nMap = nByte;
................................................................................
  3572   3575   
  3573   3576     if( nMap<0 ){
  3574   3577       rc = winFileSize((sqlite3_file*)pFd, &nMap);
  3575   3578       if( rc ){
  3576   3579         return SQLITE_IOERR_FSTAT;
  3577   3580       }
  3578   3581     }
  3579         -  if( nMap>pFd->mmapLimit ){
  3580         -    nMap = pFd->mmapLimit;
         3582  +  if( nMap>pFd->mmapSizeMax ){
         3583  +    nMap = pFd->mmapSizeMax;
  3581   3584     }
  3582   3585     nMap &= ~(sqlite3_int64)(winSysInfo.dwPageSize - 1);
  3583   3586    
  3584   3587     if( nMap==0 && pFd->mmapSize>0 ){
  3585   3588       winUnmapfile(pFd);
  3586   3589     }
  3587   3590     if( nMap!=pFd->mmapSize ){
................................................................................
  3625   3628         pFd->lastErrno = osGetLastError();
  3626   3629         winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno,
  3627   3630                     "winMapfile", pFd->zPath);
  3628   3631         return SQLITE_OK;
  3629   3632       }
  3630   3633       pFd->pMapRegion = pNew;
  3631   3634       pFd->mmapSize = nMap;
  3632         -    pFd->mmapOrigsize = nMap;
         3635  +    pFd->mmapSizeActual = nMap;
  3633   3636     }
  3634   3637   
  3635   3638     return SQLITE_OK;
  3636   3639   }
  3637         -#endif /* !defined(SQLITE_DISABLE_MMAP) */
         3640  +#endif /* SQLITE_MAX_MMAP_SIZE>0 */
  3638   3641   
  3639   3642   /*
  3640   3643   ** If possible, return a pointer to a mapping of file fd starting at offset
  3641   3644   ** iOff. The mapping must be valid for at least nAmt bytes.
  3642   3645   **
  3643   3646   ** If such a pointer can be obtained, store it in *pp and return SQLITE_OK.
  3644   3647   ** Or, if one cannot but no error occurs, set *pp to 0 and return SQLITE_OK.
................................................................................
  3648   3651   ** If this function does return a pointer, the caller must eventually 
  3649   3652   ** release the reference by calling unixUnfetch().
  3650   3653   */
  3651   3654   static int winFetch(sqlite3_file *fd, i64 iOff, int nAmt, void **pp){
  3652   3655     winFile *pFd = (winFile*)fd;   /* The underlying database file */
  3653   3656     *pp = 0;
  3654   3657   
  3655         -#if !defined(SQLITE_DISABLE_MMAP)
  3656         -  if( pFd->mmapLimit>0 ){
         3658  +#if SQLITE_MAX_MMAP_SIZE>0
         3659  +  if( pFd->mmapSizeMax>0 ){
  3657   3660       if( pFd->pMapRegion==0 ){
  3658   3661         int rc = winMapfile(pFd, -1);
  3659   3662         if( rc!=SQLITE_OK ) return rc;
  3660   3663       }
  3661   3664       if( pFd->mmapSize >= iOff+nAmt ){
  3662   3665         *pp = &((u8 *)pFd->pMapRegion)[iOff];
  3663   3666         pFd->nFetchOut++;
................................................................................
  4125   4128       pFile->ctrlFlags |= WINFILE_PSOW;
  4126   4129     }
  4127   4130     pFile->lastErrno = NO_ERROR;
  4128   4131     pFile->zPath = zName;
  4129   4132     pFile->hMap = NULL;
  4130   4133     pFile->pMapRegion = 0;
  4131   4134     pFile->mmapSize = 0;
  4132         -  pFile->mmapOrigsize = 0;
  4133         -  pFile->mmapLimit = sqlite3GlobalConfig.mxMmap;
         4135  +  pFile->mmapSizeActual = 0;
         4136  +  pFile->mmapSizeMax = sqlite3GlobalConfig.mxMmap;
  4134   4137   
  4135   4138     OpenCounter(+1);
  4136   4139     return rc;
  4137   4140   }
  4138   4141   
  4139   4142   /*
  4140   4143   ** Delete the named file.

Changes to src/pager.c.

   654    654     sqlite3_backup *pBackup;    /* Pointer to list of ongoing backup processes */
   655    655     PagerSavepoint *aSavepoint; /* Array of active savepoints */
   656    656     int nSavepoint;             /* Number of elements in aSavepoint[] */
   657    657     char dbFileVers[16];        /* Changes whenever database file changes */
   658    658   
   659    659     u8 bUseFetch;               /* True to use xFetch() */
   660    660     int nMmapOut;               /* Number of mmap pages currently outstanding */
   661         -  sqlite3_int64 mxMmap;       /* Desired maximum mmap size */
          661  +  sqlite3_int64 szMmap;       /* Desired maximum mmap size */
   662    662     PgHdr *pMmapFreelist;       /* List of free mmap page headers (pDirty) */
   663    663     /*
   664    664     ** End of the routinely-changing class members
   665    665     ***************************************************************************/
   666    666   
   667    667     u16 nExtra;                 /* Add this many bytes to each in-memory page */
   668    668     i16 nReserve;               /* Number of unused bytes at end of each page */
................................................................................
   770    770   # define MEMDB pPager->memDb
   771    771   #endif
   772    772   
   773    773   /*
   774    774   ** The macro USEFETCH is true if we are allowed to use the xFetch and xUnfetch
   775    775   ** interfaces to access the database using memory-mapped I/O.
   776    776   */
   777         -#ifdef SQLITE_DISABLE_MMAP
   778         -# define USEFETCH(x) 0
          777  +#if SQLITE_MAX_MMAP_SIZE>0
          778  +# define USEFETCH(x) ((x)->bUseFetch)
   779    779   #else
   780         -# define USEFETCH(x) ((x)->bUseFetch)
          780  +# define USEFETCH(x) 0
   781    781   #endif
   782    782   
   783    783   /*
   784    784   ** The maximum legal page number is (2^31 - 1).
   785    785   */
   786    786   #define PAGER_MAX_PGNO 2147483647
   787    787   
................................................................................
  3366   3366   ** Change the maximum number of in-memory pages that are allowed.
  3367   3367   */
  3368   3368   void sqlite3PagerSetCachesize(Pager *pPager, int mxPage){
  3369   3369     sqlite3PcacheSetCachesize(pPager->pPCache, mxPage);
  3370   3370   }
  3371   3371   
  3372   3372   /*
  3373         -** Invoke SQLITE_FCNTL_MMAP_LIMIT based on the current value of mxMmap.
         3373  +** Invoke SQLITE_FCNTL_MMAP_SIZE based on the current value of szMmap.
  3374   3374   */
  3375   3375   static void pagerFixMaplimit(Pager *pPager){
  3376         -#if !defined(SQLITE_DISABLE_MMAP)
         3376  +#if SQLITE_MAX_MMAP_SIZE>0
  3377   3377     sqlite3_file *fd = pPager->fd;
  3378   3378     if( isOpen(fd) ){
  3379         -    sqlite3_int64 mx;
  3380         -    pPager->bUseFetch = (fd->pMethods->iVersion>=3) && pPager->mxMmap>0;
  3381         -    mx = pPager->mxMmap;
  3382         -    sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_MMAP_LIMIT, &mx);
         3379  +    sqlite3_int64 sz;
         3380  +    pPager->bUseFetch = (fd->pMethods->iVersion>=3) && pPager->szMmap>0;
         3381  +    sz = pPager->szMmap;
         3382  +    sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_MMAP_SIZE, &sz);
  3383   3383     }
  3384   3384   #endif
  3385   3385   }
  3386   3386   
  3387   3387   /*
  3388   3388   ** Change the maximum size of any memory mapping made of the database file.
  3389   3389   */
  3390         -void sqlite3PagerSetMmapLimit(Pager *pPager, sqlite3_int64 mxMmap){
  3391         -  pPager->mxMmap = mxMmap;
         3390  +void sqlite3PagerSetMmapLimit(Pager *pPager, sqlite3_int64 szMmap){
         3391  +  pPager->szMmap = szMmap;
  3392   3392     pagerFixMaplimit(pPager);
  3393   3393   }
  3394   3394   
  3395   3395   /*
  3396   3396   ** Free as much memory as possible from the pager.
  3397   3397   */
  3398   3398   void sqlite3PagerShrink(Pager *pPager){
................................................................................
  4762   4762     }else if( memDb ){
  4763   4763       pPager->journalMode = PAGER_JOURNALMODE_MEMORY;
  4764   4764     }
  4765   4765     /* pPager->xBusyHandler = 0; */
  4766   4766     /* pPager->pBusyHandlerArg = 0; */
  4767   4767     pPager->xReiniter = xReinit;
  4768   4768     /* memset(pPager->aHash, 0, sizeof(pPager->aHash)); */
  4769         -  /* pPager->mxMmap = SQLITE_DEFAULT_MMAP_LIMIT // will be set by btree.c */
         4769  +  /* pPager->szMmap = SQLITE_DEFAULT_MMAP_SIZE // will be set by btree.c */
  4770   4770   
  4771   4771     *ppPager = pPager;
  4772   4772     return SQLITE_OK;
  4773   4773   }
  4774   4774   
  4775   4775   
  4776   4776   

Changes to src/pragma.c.

   742    742         int size = sqlite3Atoi(zRight);
   743    743         pDb->pSchema->cache_size = size;
   744    744         sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
   745    745       }
   746    746     }else
   747    747   
   748    748     /*
   749         -  **  PRAGMA [database.]mmap_limit(N)
          749  +  **  PRAGMA [database.]mmap_size(N)
   750    750     **
   751    751     ** Used to set mapping size limit. The mapping size limit is
   752    752     ** used to limit the aggregate size of all memory mapped regions of the
   753    753     ** database file. If this parameter is set to zero, then memory mapping
   754    754     ** is not used at all.  If N is negative, then the default memory map
   755         -  ** limit determined by sqlite3_config(SQLITE_CONFIG_MMAP_LIMIT) is set.
          755  +  ** limit determined by sqlite3_config(SQLITE_CONFIG_MMAP_SIZE) is set.
   756    756     ** The parameter N is measured in bytes.
   757    757     **
   758    758     ** This value is advisory.  The underlying VFS is free to memory map
   759    759     ** as little or as much as it wants.  Except, if N is set to 0 then the
   760    760     ** upper layers will never invoke the xFetch interfaces to the VFS.
   761    761     */
   762         -  if( sqlite3StrICmp(zLeft,"mmap_limit")==0 ){
   763         -    sqlite3_int64 mx;
          762  +  if( sqlite3StrICmp(zLeft,"mmap_size")==0 ){
          763  +    sqlite3_int64 sz;
   764    764       assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
   765    765       if( zRight ){
   766    766         int ii;
   767         -      sqlite3Atoi64(zRight, &mx, 1000, SQLITE_UTF8);
   768         -      if( mx<0 ) mx = sqlite3GlobalConfig.mxMmap;
   769         -      if( pId2->n==0 ) db->mxMmap = mx;
          767  +      sqlite3Atoi64(zRight, &sz, 1000, SQLITE_UTF8);
          768  +      if( sz<0 ) sz = sqlite3GlobalConfig.szMmap;
          769  +      if( pId2->n==0 ) db->szMmap = sz;
   770    770         for(ii=db->nDb-1; ii>=0; ii--){
   771    771           if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
   772         -          sqlite3BtreeSetMmapLimit(db->aDb[ii].pBt, mx);
          772  +          sqlite3BtreeSetMmapLimit(db->aDb[ii].pBt, sz);
   773    773           }
   774    774         }
   775    775       }
   776         -    mx = -1;
   777         -    if( sqlite3_file_control(db,zDb,SQLITE_FCNTL_MMAP_LIMIT,&mx)==SQLITE_OK ){
   778         -#if defined(SQLITE_DISABLE_MMAP)
   779         -      mx = 0;
          776  +    sz = -1;
          777  +    if( sqlite3_file_control(db,zDb,SQLITE_FCNTL_MMAP_SIZE,&sz)==SQLITE_OK ){
          778  +#if SQLITE_MAX_MMAP_SIZE==0
          779  +      sz = 0;
   780    780   #endif
   781         -      returnSingleInt(pParse, "mmap_limit", mx);
          781  +      returnSingleInt(pParse, "mmap_size", sz);
   782    782       }
   783    783     }else
   784    784   
   785    785     /*
   786    786     **   PRAGMA temp_store
   787    787     **   PRAGMA temp_store = "default"|"memory"|"file"
   788    788     **

Changes to src/shell.c.

  3056   3056   #endif
  3057   3057   #ifdef SQLITE_ENABLE_MULTIPLEX
  3058   3058       }else if( strcmp(z,"-multiplex")==0 ){
  3059   3059         extern int sqlite3_multiple_initialize(const char*,int);
  3060   3060         sqlite3_multiplex_initialize(0, 1);
  3061   3061   #endif
  3062   3062       }else if( strcmp(z,"-mmap")==0 ){
  3063         -      sqlite3_config(SQLITE_CONFIG_MMAP_LIMIT, integerValue(cmdline_option_value(argc,argv,++i)));
         3063  +      sqlite3_int64 sz = integerValue(cmdline_option_value(argc,argv,++i));
         3064  +      sqlite3_config(SQLITE_CONFIG_MMAP_SIZE, sz, sz);
  3064   3065       }else if( strcmp(z,"-vfs")==0 ){
  3065   3066         sqlite3_vfs *pVfs = sqlite3_vfs_find(cmdline_option_value(argc,argv,++i));
  3066   3067         if( pVfs ){
  3067   3068           sqlite3_vfs_register(pVfs, 1);
  3068   3069         }else{
  3069   3070           fprintf(stderr, "no such VFS: \"%s\"\n", argv[i]);
  3070   3071           exit(1);

Changes to src/sqlite.h.in.

   888    888   ** to have SQLite generate a
   889    889   ** temporary filename using the same algorithm that is followed to generate
   890    890   ** temporary filenames for TEMP tables and other internal uses.  The
   891    891   ** argument should be a char** which will be filled with the filename
   892    892   ** written into memory obtained from [sqlite3_malloc()].  The caller should
   893    893   ** invoke [sqlite3_free()] on the result to avoid a memory leak.
   894    894   **
   895         -** <li>[[SQLITE_FCNTL_MMAP_LIMIT]]
   896         -** The [SQLITE_FCNTL_MMAP_LIMIT] file control is used to query or set the
          895  +** <li>[[SQLITE_FCNTL_MMAP_SIZE]]
          896  +** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the
   897    897   ** maximum number of bytes that will be used for memory-mapped I/O.
   898    898   ** The argument is a pointer to a value of type sqlite3_int64 that
   899    899   ** is an advisory maximum number of bytes in the file to memory map.  The
   900    900   ** pointer is overwritten with the old value.  The limit is not changed if
   901         -** the originally pointed to is negative, and so the current limit can be
   902         -** queried by passing in a pointer to a negative number.  This file-control
   903         -** is used internally to implement [PRAGMA mmap_limit].
          901  +** the value originally pointed to is negative, and so the current limit 
          902  +** can be queried by passing in a pointer to a negative number.  This
          903  +** file-control is used internally to implement [PRAGMA mmap_size].
   904    904   **
   905    905   ** </ul>
   906    906   */
   907    907   #define SQLITE_FCNTL_LOCKSTATE               1
   908    908   #define SQLITE_GET_LOCKPROXYFILE             2
   909    909   #define SQLITE_SET_LOCKPROXYFILE             3
   910    910   #define SQLITE_LAST_ERRNO                    4
................................................................................
   916    916   #define SQLITE_FCNTL_PERSIST_WAL            10
   917    917   #define SQLITE_FCNTL_OVERWRITE              11
   918    918   #define SQLITE_FCNTL_VFSNAME                12
   919    919   #define SQLITE_FCNTL_POWERSAFE_OVERWRITE    13
   920    920   #define SQLITE_FCNTL_PRAGMA                 14
   921    921   #define SQLITE_FCNTL_BUSYHANDLER            15
   922    922   #define SQLITE_FCNTL_TEMPFILENAME           16
   923         -#define SQLITE_FCNTL_MMAP_LIMIT             18
          923  +#define SQLITE_FCNTL_MMAP_SIZE              18
   924    924   
   925    925   /*
   926    926   ** CAPI3REF: Mutex Handle
   927    927   **
   928    928   ** The mutex module within SQLite defines [sqlite3_mutex] to be an
   929    929   ** abstract type for a mutex object.  The SQLite core never looks
   930    930   ** at the internal representation of an [sqlite3_mutex].  It only
................................................................................
  1646   1646   ** passed as the second argument has just been opened. The third argument
  1647   1647   ** points to a buffer containing the name of the main database file. If the
  1648   1648   ** fourth parameter is 1, then the SQL statement that the third parameter
  1649   1649   ** points to has just been executed. Or, if the fourth parameter is 2, then
  1650   1650   ** the connection being passed as the second parameter is being closed. The
  1651   1651   ** third parameter is passed NULL In this case.
  1652   1652   **
  1653         -** [[SQLITE_CONFIG_MMAP_LIMIT]]
  1654         -** <dt>SQLITE_CONFIG_MMAP_LIMIT
  1655         -** <dd>The sole argument should be a 64-bit integer (an sqlite3_int64) that
  1656         -** is the default maximum number of bytes of process address space that
  1657         -** should be used for accessing each database file using memory mapping.
         1653  +** [[SQLITE_CONFIG_MMAP_SIZE]]
         1654  +** <dt>SQLITE_CONFIG_MMAP_SIZE
         1655  +** <dd>SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values
         1656  +** that are the default mmap size limit (the default setting for
         1657  +** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
  1658   1658   ** The default setting can be overridden by each database connection using
  1659         -** either the [PRAGMA mmap_limit] command, or by using the
  1660         -** [SQLITE_FCNTL_MMAP_LIMIT] file control.  The value set here overrides the
  1661         -** compile-time default that is set using [SQLITE_DEFAULT_MMAP_LIMIT].
  1662         -** If the argument to this option is negative, then
  1663         -** the memory map limit is set to the compile-time default.
         1659  +** either the [PRAGMA mmap_size] command, or by using the
         1660  +** [SQLITE_FCNTL_MMAP_SIZE] file control.  The maximum allowed mmap size
         1661  +** cannot be changed at run-time.  Nor may the maximum allowed mmap size
         1662  +** exceed the compile-time maximum mmap size set by the
         1663  +** [SQLITE_MAX_MMAP_SIZE] compile-time option.  
         1664  +** If either argument to this option is negative, then that argument is
         1665  +** changed to its compile-time default.
  1664   1666   ** </dl>
  1665   1667   */
  1666   1668   #define SQLITE_CONFIG_SINGLETHREAD  1  /* nil */
  1667   1669   #define SQLITE_CONFIG_MULTITHREAD   2  /* nil */
  1668   1670   #define SQLITE_CONFIG_SERIALIZED    3  /* nil */
  1669   1671   #define SQLITE_CONFIG_MALLOC        4  /* sqlite3_mem_methods* */
  1670   1672   #define SQLITE_CONFIG_GETMALLOC     5  /* sqlite3_mem_methods* */
................................................................................
  1680   1682   #define SQLITE_CONFIG_GETPCACHE    15  /* no-op */
  1681   1683   #define SQLITE_CONFIG_LOG          16  /* xFunc, void* */
  1682   1684   #define SQLITE_CONFIG_URI          17  /* int */
  1683   1685   #define SQLITE_CONFIG_PCACHE2      18  /* sqlite3_pcache_methods2* */
  1684   1686   #define SQLITE_CONFIG_GETPCACHE2   19  /* sqlite3_pcache_methods2* */
  1685   1687   #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20  /* int */
  1686   1688   #define SQLITE_CONFIG_SQLLOG       21  /* xSqllog, void* */
  1687         -#define SQLITE_CONFIG_MMAP_LIMIT   22  /* sqlite3_int64 */
         1689  +#define SQLITE_CONFIG_MMAP_SIZE    22  /* sqlite3_int64, sqlite3_int64 */
  1688   1690   
  1689   1691   /*
  1690   1692   ** CAPI3REF: Database Connection Configuration Options
  1691   1693   **
  1692   1694   ** These constants are the available integer configuration options that
  1693   1695   ** can be passed as the second argument to the [sqlite3_db_config()] interface.
  1694   1696   **

Changes to src/sqliteInt.h.

   536    536   #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
   537    537   # define EIGHT_BYTE_ALIGNMENT(X)   ((((char*)(X) - (char*)0)&3)==0)
   538    538   #else
   539    539   # define EIGHT_BYTE_ALIGNMENT(X)   ((((char*)(X) - (char*)0)&7)==0)
   540    540   #endif
   541    541   
   542    542   /*
   543         -** Disable MMAP on platforms where it is not supported
          543  +** Disable MMAP on platforms where it is known to not work
   544    544   */
   545    545   #if defined(__OpenBSD__) || defined(__QNXNTO__)
   546         -# undef SQLITE_DISABLE_MMAP
   547         -# define SQLITE_DISABLE_MMAP 1
          546  +# undef SQLITE_MAX_MMAP_SIZE
          547  +# define SQLITE_MAX_MMAP_SIZE 0
   548    548   #endif
   549    549   
          550  +/*
          551  +** Default maximum size of memory used by memory-mapped I/O in the VFS
          552  +*/
          553  +#ifdef __APPLE__
          554  +# include <TargetConditionals.h>
          555  +# if TARGET_OS_IPHONE
          556  +#   undef SQLITE_MAX_MMAP_SIZE
          557  +#   define SQLITE_MAX_MMAP_SIZE 0
          558  +# endif
          559  +#endif
          560  +#ifndef SQLITE_MAX_MMAP_SIZE
          561  +# if defined(__linux__) \
          562  +  || defined(_WIN32) \
          563  +  || (defined(__APPLE__) && defined(__MACH__)) \
          564  +  || defined(__sun)
          565  +#   define SQLITE_MAX_MMAP_SIZE 2147483648
          566  +# else
          567  +#   define SQLITE_MAX_MMAP_SIZE 0
          568  +# endif
          569  +#endif
          570  +
          571  +/*
          572  +** The default MMAP_SIZE is zero on all platforms.  Or, even if a larger
          573  +** default MMAP_SIZE is specified at compile-time, make sure that it does
          574  +** not exceed the maximum mmap size.
          575  +*/
          576  +#ifndef SQLITE_DEFAULT_MMAP_SIZE
          577  +# define SQLITE_DEFAULT_MMAP_SIZE 0
          578  +#endif
          579  +#if SQLITE_DEFAULT_MMAP_SIZE>SQLITE_MAX_MMAP_SIZE
          580  +# undef SQLITE_DEFAULT_MMAP_SIZE
          581  +# define SQLITE_DEFAULT_MMAP_SIZE SQLITE_MAX_MMAP_SIZE
          582  +#endif
   550    583   
   551    584   /*
   552    585   ** An instance of the following structure is used to store the busy-handler
   553    586   ** callback for a given sqlite handle. 
   554    587   **
   555    588   ** The sqlite.busyHandler member of the sqlite struct contains the busy
   556    589   ** callback for the database handle. Each pager opened via the sqlite
................................................................................
   838    871     struct Vdbe *pVdbe;           /* List of active virtual machines */
   839    872     CollSeq *pDfltColl;           /* The default collating sequence (BINARY) */
   840    873     sqlite3_mutex *mutex;         /* Connection mutex */
   841    874     Db *aDb;                      /* All backends */
   842    875     int nDb;                      /* Number of backends currently in use */
   843    876     int flags;                    /* Miscellaneous flags. See below */
   844    877     i64 lastRowid;                /* ROWID of most recent insert (see above) */
   845         -  i64 mxMmap;                   /* Default mmap_limit setting */
          878  +  i64 szMmap;                   /* Default mmap_size setting */
   846    879     unsigned int openFlags;       /* Flags passed to sqlite3_vfs.xOpen() */
   847    880     int errCode;                  /* Most recent error code (SQLITE_*) */
   848    881     int errMask;                  /* & result codes with this before returning */
   849    882     u16 dbOptFlags;               /* Flags to enable/disable optimizations */
   850    883     u8 autoCommit;                /* The auto-commit flag. */
   851    884     u8 temp_store;                /* 1: file 2: memory 0: default */
   852    885     u8 mallocFailed;              /* True if we have seen a malloc failure */
................................................................................
  2512   2545     int nLookaside;                   /* Default lookaside buffer count */
  2513   2546     sqlite3_mem_methods m;            /* Low-level memory allocation interface */
  2514   2547     sqlite3_mutex_methods mutex;      /* Low-level mutex interface */
  2515   2548     sqlite3_pcache_methods2 pcache2;  /* Low-level page-cache interface */
  2516   2549     void *pHeap;                      /* Heap storage space */
  2517   2550     int nHeap;                        /* Size of pHeap[] */
  2518   2551     int mnReq, mxReq;                 /* Min and max heap requests sizes */
  2519         -  sqlite3_int64 mxMmap;             /* Maximum mmap() space per open file */
         2552  +  sqlite3_int64 szMmap;             /* mmap() space per open file */
         2553  +  sqlite3_int64 mxMmap;             /* Maximum value for szMmap */
  2520   2554     void *pScratch;                   /* Scratch memory */
  2521   2555     int szScratch;                    /* Size of each scratch buffer */
  2522   2556     int nScratch;                     /* Number of scratch buffers */
  2523   2557     void *pPage;                      /* Page cache memory */
  2524   2558     int szPage;                       /* Size of each page in pPage[] */
  2525   2559     int nPage;                        /* Number of pages in pPage[] */
  2526   2560     int mxParserStack;                /* maximum depth of the parser stack */

Changes to src/sqliteLimit.h.

   202    202   ** A value of 1 means that a trigger program will not be able to itself
   203    203   ** fire any triggers. A value of 0 means that no trigger programs at all 
   204    204   ** may be executed.
   205    205   */
   206    206   #ifndef SQLITE_MAX_TRIGGER_DEPTH
   207    207   # define SQLITE_MAX_TRIGGER_DEPTH 1000
   208    208   #endif
   209         -
   210         -/*
   211         -** Default maximum size of memory used by xFetch in the VFS.
   212         -*/
   213         -#ifdef SQLITE_DISABLE_MMAP
   214         -# undef SQLITE_DEFAULT_MMAP_LIMIT
   215         -# define SQLITE_DEFAULT_MMAP_LIMIT 0
   216         -#endif
   217         -#ifdef __APPLE__
   218         -# include <TargetConditionals.h>
   219         -# if TARGET_OS_IPHONE
   220         -#   define SQLITE_DEFAULT_MMAP_LIMIT 0
   221         -# endif
   222         -#endif
   223         -#ifndef SQLITE_DEFAULT_MMAP_LIMIT
   224         -# if defined(__linux__) \
   225         -  || defined(_WIN32) \
   226         -  || (defined(__APPLE__) && defined(__MACH__)) \
   227         -  || defined(__sun)
   228         -#   define SQLITE_DEFAULT_MMAP_LIMIT 268435456 /* = 256*1024*1024 */
   229         -# else
   230         -#   define SQLITE_DEFAULT_MMAP_LIMIT 0
   231         -# endif
   232         -#endif

Changes to src/test_config.c.

    83     83   
    84     84   #ifdef SQLITE_DISABLE_LFS
    85     85     Tcl_SetVar2(interp, "sqlite_options", "lfs", "0", TCL_GLOBAL_ONLY);
    86     86   #else
    87     87     Tcl_SetVar2(interp, "sqlite_options", "lfs", "1", TCL_GLOBAL_ONLY);
    88     88   #endif
    89     89   
    90         -#ifdef SQLITE_DISABLE_MMAP
    91         -  Tcl_SetVar2(interp, "sqlite_options", "mmap", "0", TCL_GLOBAL_ONLY);
    92         -#else
           90  +#if SQLITE_MAX_MMAP_SIZE>0
    93     91     Tcl_SetVar2(interp, "sqlite_options", "mmap", "1", TCL_GLOBAL_ONLY);
           92  +#else
           93  +  Tcl_SetVar2(interp, "sqlite_options", "mmap", "0", TCL_GLOBAL_ONLY);
    94     94   #endif
    95     95   
    96     96   #if 1 /* def SQLITE_MEMDEBUG */
    97     97     Tcl_SetVar2(interp, "sqlite_options", "memdebug", "1", TCL_GLOBAL_ONLY);
    98     98   #else
    99     99     Tcl_SetVar2(interp, "sqlite_options", "memdebug", "0", TCL_GLOBAL_ONLY);
   100    100   #endif

Changes to test/dbstatus2.test.

    36     36   proc db_write {db {reset 0}} {
    37     37     sqlite3_db_status $db CACHE_WRITE $reset
    38     38   }
    39     39   
    40     40   do_test 1.1 {
    41     41     db close
    42     42     sqlite3 db test.db
    43         -  execsql { PRAGMA mmap_limit = 0 }
           43  +  execsql { PRAGMA mmap_size = 0 }
    44     44     expr {[file size test.db] / 1024}
    45     45   } 6
    46     46   
    47     47   do_test 1.2 {
    48     48     execsql { SELECT b FROM t1 WHERE a=2 }
    49     49     db_hit_miss db
    50     50   } {{0 2 0} {0 4 0}}

Changes to test/exclusive2.test.

    24     24     finish_test
    25     25     return
    26     26   }
    27     27   
    28     28   # Tests in this file verify that locking_mode=exclusive causes SQLite to
    29     29   # use cached pages even if the database is changed on disk. This doesn't
    30     30   # work with mmap.
    31         -if {[permutation]!="nommap"} {
           31  +if {[permutation]=="mmap"} {
    32     32     finish_test
    33     33     return
    34     34   }
    35     35   
    36     36   # This module does not work right if the cache spills at unexpected
    37     37   # moments.  So disable the soft-heap-limit.
    38     38   #

Changes to test/func.test.

  1269   1269   } {1}
  1270   1270   do_test func-29.3 {
  1271   1271     db close
  1272   1272     sqlite3 db test.db
  1273   1273     sqlite3_db_status db CACHE_MISS 1
  1274   1274     db eval {SELECT typeof(+x) FROM t29 ORDER BY id}
  1275   1275   } {integer null real blob text}
  1276         -if {[permutation] == "nommap"} {
         1276  +if {[permutation] != "mmap"} {
  1277   1277     do_test func-29.4 {
  1278   1278       set x [lindex [sqlite3_db_status db CACHE_MISS 1] 1]
  1279   1279       if {$x>100} {set x many}
  1280   1280       set x
  1281   1281     } {many}
  1282   1282   }
  1283   1283   do_test func-29.5 {

Changes to test/incrblob.test.

   119    119       }
   120    120     }
   121    121   
   122    122     db close
   123    123     forcedelete test.db test.db-journal
   124    124   
   125    125     sqlite3 db test.db
   126         -  execsql "PRAGMA mmap_limit = 0"
          126  +  execsql "PRAGMA mmap_size = 0"
   127    127     execsql "PRAGMA auto_vacuum = $AutoVacuumMode"
   128    128   
   129    129     do_test incrblob-2.$AutoVacuumMode.1 {
   130    130       set ::str [string repeat abcdefghij 2900]
   131    131       execsql {
   132    132         BEGIN;
   133    133         CREATE TABLE blobs(k PRIMARY KEY, v BLOB, i INTEGER);
................................................................................
   146    146       } $AutoVacuumMode
   147    147     }
   148    148   
   149    149     do_test incrblob-2.$AutoVacuumMode.3 {
   150    150       # Open and close the db to make sure the page cache is empty.
   151    151       db close
   152    152       sqlite3 db test.db
   153         -    execsql "PRAGMA mmap_limit = 0"
          153  +    execsql "PRAGMA mmap_size = 0"
   154    154     
   155    155       # Read the last 20 bytes of the blob via a blob handle.
   156    156       set ::blob [db incrblob blobs v 1]
   157    157       seek $::blob -20 end
   158    158       set ::fragment [read $::blob]
   159    159       close $::blob
   160    160     
................................................................................
   169    169       string range [db one {SELECT v FROM blobs}] end-19 end
   170    170     } $::fragment
   171    171   
   172    172     do_test incrblob-2.$AutoVacuumMode.5 {
   173    173       # Open and close the db to make sure the page cache is empty.
   174    174       db close
   175    175       sqlite3 db test.db
   176         -    execsql "PRAGMA mmap_limit = 0"
          176  +    execsql "PRAGMA mmap_size = 0"
   177    177     
   178    178       # Write the second-to-last 20 bytes of the blob via a blob handle.
   179    179       #
   180    180       set ::blob [db incrblob blobs v 1]
   181    181       seek $::blob -40 end
   182    182       puts -nonewline $::blob "1234567890abcdefghij"
   183    183       flush $::blob
................................................................................
   199    199       string range [db one {SELECT v FROM blobs}] end-39 end-20
   200    200     } "1234567890abcdefghij"
   201    201   
   202    202     do_test incrblob-2.$AutoVacuumMode.8 {
   203    203       # Open and close the db to make sure the page cache is empty.
   204    204       db close
   205    205       sqlite3 db test.db
   206         -    execsql { PRAGMA mmap_limit = 0 }
          206  +    execsql { PRAGMA mmap_size = 0 }
   207    207   
   208    208       execsql { SELECT i FROM blobs } 
   209    209     } {45}
   210    210   
   211    211     do_test incrblob-2.$AutoVacuumMode.9 {
   212    212       nRead db
   213    213     } [expr $AutoVacuumMode ? 4 : 30]

Changes to test/mmap1.test.

    36     36         set str [format %.8x [expr [set ::rcnt] ^ 0xbdf20da3]] 
    37     37         string range [string repeat [set str] [expr [set n]/4]] 1 [set n]
    38     38       }
    39     39       $dbname func rblob rblob
    40     40     }]
    41     41   }
    42     42   
    43         -foreach {t mmap_limit nRead c2init} {
    44         -  1.1 { PRAGMA mmap_limit = 67108864 }   4 {PRAGMA mmap_limit = 0}
    45         -  1.2 { PRAGMA mmap_limit =    53248 } 150 {PRAGMA mmap_limit = 0}
    46         -  1.3 { PRAGMA mmap_limit =        0 } 344 {PRAGMA mmap_limit = 0}
    47         -  1.4 { PRAGMA mmap_limit = 67108864 }   4 {PRAGMA mmap_limit = 67108864 }
    48         -  1.5 { PRAGMA mmap_limit =    53248 } 150 {PRAGMA mmap_limit = 67108864 }
    49         -  1.6 { PRAGMA mmap_limit =        0 } 344 {PRAGMA mmap_limit = 67108864 }
           43  +foreach {t mmap_size nRead c2init} {
           44  +  1.1 { PRAGMA mmap_size = 67108864 }   4 {PRAGMA mmap_size = 0}
           45  +  1.2 { PRAGMA mmap_size =    53248 } 150 {PRAGMA mmap_size = 0}
           46  +  1.3 { PRAGMA mmap_size =        0 } 344 {PRAGMA mmap_size = 0}
           47  +  1.4 { PRAGMA mmap_size = 67108864 }   4 {PRAGMA mmap_size = 67108864 }
           48  +  1.5 { PRAGMA mmap_size =    53248 } 150 {PRAGMA mmap_size = 67108864 }
           49  +  1.6 { PRAGMA mmap_size =        0 } 344 {PRAGMA mmap_size = 67108864 }
    50     50   } {
    51     51     do_multiclient_test tn {
    52     52       sql1 {PRAGMA page_size=1024}
    53         -    sql1 $mmap_limit
           53  +    sql1 $mmap_size
    54     54       sql2 $c2init
    55     55   
    56     56       code2 [register_rblob_code db2 0]
    57     57   
    58     58       sql2 {
    59     59         PRAGMA page_size=1024;
    60     60         PRAGMA auto_vacuum = 1;
................................................................................
    85     85       # Have connection 2 grow the file again. Check connection 1 is still ok.
    86     86       sql2 { INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1 }
    87     87       do_test $t.$tn.4 {
    88     88         sql1 "SELECT count(*) FROM t1; PRAGMA integrity_check ; PRAGMA page_count"
    89     89       } {64 ok 149}
    90     90   
    91     91       # Check that the number of pages read by connection 1 indicates that the
    92         -    # "PRAGMA mmap_limit" command worked.
           92  +    # "PRAGMA mmap_size" command worked.
    93     93       do_test $t.$tn.5 { nRead db } $nRead
    94     94     }
    95     95   }
    96     96   
    97     97   set ::rcnt 0
    98     98   proc rblob {n} {
    99     99     set ::rcnt [expr (($::rcnt << 3) + $::rcnt + 456) & 0xFFFFFFFF]
................................................................................
   102    102   }
   103    103   
   104    104   reset_db
   105    105   db func rblob rblob
   106    106   
   107    107   do_execsql_test 2.1 {
   108    108     PRAGMA auto_vacuum = 1;
   109         -  PRAGMA mmap_limit = 67108864;
          109  +  PRAGMA mmap_size = 67108864;
   110    110     PRAGMA journal_mode = wal;
   111    111     CREATE TABLE t1(a, b, UNIQUE(a, b));
   112    112     INSERT INTO t1 VALUES(rblob(500), rblob(500));
   113    113     INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; --    2
   114    114     INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; --    4
   115    115     INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; --    8
   116    116     INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; --   16
................................................................................
   250    250   } $bbb
   251    251   
   252    252   do_test 5.5 {
   253    253     sqlite3_finalize $::STMT
   254    254   } SQLITE_OK
   255    255   
   256    256   #-------------------------------------------------------------------------
   257         -# Test various mmap_limit settings.
          257  +# Test various mmap_size settings.
   258    258   #
   259    259   foreach {tn1 mmap1 mmap2} {
   260    260        1 6144       167773
   261    261        2 18432      140399
   262    262        3 43008      401302
   263    263        4 92160      253899
   264    264        5 190464          2
................................................................................
   275    275         CREATE TABLE t2(x);
   276    276         INSERT INTO t2 VALUES('');
   277    277       }
   278    278   
   279    279       code1 [register_rblob_code db  0]
   280    280       code2 [register_rblob_code db2 444]
   281    281   
   282         -    sql1 "PRAGMA mmap_limit = $mmap1"
   283         -    sql2 "PRAGMA mmap_limit = $mmap2"
          282  +    sql1 "PRAGMA mmap_size = $mmap1"
          283  +    sql2 "PRAGMA mmap_size = $mmap2"
   284    284   
   285    285       do_test $tn1.$tn { 
   286    286         for {set i 1} {$i <= 100} {incr i} {
   287    287           if {$i % 2} {
   288    288             set c1 sql1
   289    289               set c2 sql2
   290    290           } else {

Changes to test/pager1.test.

  2526   2526   
  2527   2527   #-------------------------------------------------------------------------
  2528   2528   # Test that appending pages to the database file then moving those pages
  2529   2529   # to the free-list before the transaction is committed does not cause
  2530   2530   # an error.
  2531   2531   #
  2532   2532   foreach {tn pragma strsize} {
  2533         -  1 { PRAGMA mmap_limit = 0 } 2400
         2533  +  1 { PRAGMA mmap_size = 0 } 2400
  2534   2534     2 { }                       2400
  2535         -  3 { PRAGMA mmap_limit = 0 } 4400
         2535  +  3 { PRAGMA mmap_size = 0 } 4400
  2536   2536     4 { }                       4400
  2537   2537   } {
  2538   2538     reset_db
  2539   2539     db func a_string a_string
  2540   2540     db eval $pragma
  2541   2541     do_execsql_test 34.$tn.1 {
  2542   2542       CREATE TABLE t1(a, b);
................................................................................
  2753   2753       INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
  2754   2754       INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
  2755   2755       INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
  2756   2756     }
  2757   2757     db close
  2758   2758     sqlite3_test_control_pending_byte 0x0010000
  2759   2759     sqlite3 db test.db
  2760         -  db eval { PRAGMA mmap_limit = 0 }
         2760  +  db eval { PRAGMA mmap_size = 0 }
  2761   2761     catchsql { SELECT sum(length(y)) FROM t1 }
  2762   2762   } {1 {database disk image is malformed}}
  2763   2763   do_test 42.2 {
  2764   2764     reset_db
  2765   2765     execsql {
  2766   2766       CREATE TABLE t1(x, y);
  2767   2767       INSERT INTO t1 VALUES(randomblob(200), randomblob(200));
................................................................................
  2795   2795       INSERT INTO t2 VALUES(1, 2);
  2796   2796       CREATE TABLE t3(x, y);
  2797   2797       INSERT INTO t3 VALUES(1, 2);
  2798   2798     }
  2799   2799     db close
  2800   2800     sqlite3 db test.db
  2801   2801   
  2802         -  db eval { PRAGMA mmap_limit = 0 }
         2802  +  db eval { PRAGMA mmap_size = 0 }
  2803   2803     db eval { SELECT * FROM t1 }
  2804   2804     sqlite3_db_status db CACHE_MISS 0
  2805   2805   } {0 2 0}
  2806   2806   
  2807   2807   do_test 43.2 {
  2808   2808     db eval { SELECT * FROM t2 }
  2809   2809     sqlite3_db_status db CACHE_MISS 1

Changes to test/pagerfault.test.

  1278   1278     }
  1279   1279     expr {[file size test.db-shm] >= 96*1024}
  1280   1280   } {1}
  1281   1281   faultsim_save_and_close
  1282   1282   
  1283   1283   do_faultsim_test pagerfault-28a -faults oom* -prep {
  1284   1284     faultsim_restore_and_reopen
  1285         -  execsql { PRAGMA mmap_limit=0 }
         1285  +  execsql { PRAGMA mmap_size=0 }
  1286   1286   
  1287   1287     sqlite3 db2 test.db
  1288   1288     db2 eval { SELECT count(*) FROM t2 }
  1289   1289   
  1290   1290     db func a_string a_string
  1291   1291     execsql { 
  1292   1292       BEGIN;

Changes to test/pageropt.test.

    84     84     }
    85     85   } [list 0 0 0 $blobcontent]
    86     86   
    87     87   # But if the other thread modifies the database, then the cache
    88     88   # must refill.
    89     89   #
    90     90   ifcapable mmap {
    91         -  set x [expr {[permutation]=="nommap" ? 6 : 1}]
           91  +  set x [expr {[permutation]=="mmap" ? 1 : 6}]
    92     92   } else {
    93     93     set x 6
    94     94   }
    95     95   do_test pageropt-1.5 {
    96     96     db2 eval {CREATE TABLE t2(y)}
    97     97     pagercount_sql {
    98     98       SELECT hex(x) FROM t1

Changes to test/permutations.test.

   134    134     "Very" quick test suite. Runs in less than 5 minutes on a workstation. 
   135    135     This test suite is the same as the "quick" tests, except that some files
   136    136     that test malloc and IO errors are omitted.
   137    137   } -files [
   138    138     test_set $allquicktests -exclude *malloc* *ioerr* *fault*
   139    139   ]
   140    140   
   141         -test_suite "nommap" -prefix "nomm-" -description {
          141  +test_suite "mmap" -prefix "mm-" -description {
   142    142     Similar to veryquick. Except with memory mapping disabled.
   143    143   } -presql {
   144         -  pragma mmap_limit = 0;
          144  +  pragma mmap_size = 268435456;
   145    145   } -files [
   146    146     test_set $allquicktests -exclude *malloc* *ioerr* *fault* -include malloc.test
   147    147   ]
   148    148   
   149    149   test_suite "valgrind" -prefix "" -description {
   150    150     Run the "veryquick" test suite with a couple of multi-process tests (that
   151    151     fail under valgrind) omitted.

Changes to test/sysfault.test.

   258    258   }
   259    259   faultsim_save_and_close
   260    260   
   261    261   do_faultsim_test 4 -faults vfsfault-* -prep {
   262    262     faultsim_restore_and_reopen
   263    263     file_control_chunksize_test db main 8192
   264    264     execsql { 
   265         -    PRAGMA mmap_limit = 1000000;
          265  +    PRAGMA mmap_size = 1000000;
   266    266     }
   267    267   } -body {
   268    268     test_syscall errno mmap     EACCES
   269    269   
   270    270     execsql {
   271    271       SELECT * FROM t1;
   272    272     }
   273    273   } -test {
   274    274     faultsim_test_result {0 {1 2}} {1 {disk I/O error}}
   275    275   }
   276    276   
   277    277   finish_test

Changes to test/wal.test.

   724    724   } [list 37 [wal_file_size 41 1024]]
   725    725   do_test wal-11.9 {
   726    726     db close
   727    727     list [expr [file size test.db]/1024] [log_deleted test.db-wal]
   728    728   } {37 1}
   729    729   sqlite3_wal db test.db
   730    730   set nWal 39
   731         -if {[permutation]=="nommap"} {set nWal 37}
          731  +if {[permutation]!="mmap"} {set nWal 37}
   732    732   ifcapable !mmap {set nWal 37}
   733    733   do_test wal-11.10 {
   734    734     execsql {
   735    735       PRAGMA cache_size = 10;
   736    736       BEGIN;
   737    737         INSERT INTO t1 SELECT blob(900) FROM t1;   -- 32
   738    738         SELECT count(*) FROM t1;

Changes to test/wal5.test.

   238    238   
   239    239       # The checkpoint above only writes page 1 of the db file. The other
   240    240       # page (page 2) is locked by the read-transaction opened by the
   241    241       # [sql2] commmand above. So normally, the db is 1 page in size here.
   242    242       # However, in mmap() mode, the db is pre-allocated to 2 pages at the
   243    243       # start of the checkpoint, even though page 2 cannot be written.
   244    244       set nDb 2
   245         -    if {[permutation]=="no-mmap"} {set nDb 1}
          245  +    if {[permutation]!="mmap"} {set nDb 1}
   246    246       ifcapable !mmap {set nDb 1}
   247    247       do_test 2.3.$tn.8 { file_page_counts } [list $nDb 4 2 4]
   248    248     }
   249    249   
   250    250     # Check that checkpoints block on the correct locks. And respond correctly
   251    251     # if they cannot obtain those locks. There are three locks that a checkpoint
   252    252     # may block on (in the following order):

Changes to test/win32lock.test.

    23     23   db close
    24     24   sqlite3_shutdown
    25     25   test_sqlite3_log xLog
    26     26   proc xLog {error_code msg} {
    27     27     lappend ::log $msg 
    28     28   }
    29     29   sqlite3 db test.db
    30         -db eval {PRAGMA mmap_limit=0}
           30  +db eval {PRAGMA mmap_size=0}
    31     31   
    32     32   do_test win32lock-1.1 {
    33     33     db eval {
    34     34       PRAGMA cache_size=10;
    35     35       CREATE TABLE t1(x,y);
    36     36       INSERT INTO t1 VALUES(1,randomblob(100000));
    37     37       INSERT INTO t1 VALUES(2,randomblob(50000));