/ Check-in [f4b8faab]
Login

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

Overview
Comment:Expand scope of the SQLITE_MAX_MMAP_SIZE define for the Win32 VFS.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:f4b8faab45e217f227bd7ce65d4741754731b8cd
User & Date: mistachkin 2013-04-15 20:08:27
Context
2013-04-16
14:52
Disable memory-mapped I/O when the codec is enabled. check-in: 340cca30 user: drh tags: trunk
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
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

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  +#if SQLITE_MAX_MMAP_SIZE>0
   153    154     int nFetchOut;                /* Number of outstanding xFetch references */
   154    155     HANDLE hMap;                  /* Handle for accessing memory mapping */
   155    156     void *pMapRegion;             /* Area memory mapped */
   156    157     sqlite3_int64 mmapSize;       /* Usable size of mapped region */
   157    158     sqlite3_int64 mmapSizeActual; /* Actual size of mapped region */
   158    159     sqlite3_int64 mmapSizeMax;    /* Configured FCNTL_MMAP_SIZE value */
          160  +#endif
   159    161   };
   160    162   
   161    163   /*
   162    164   ** Allowed values for winFile.ctrlFlags
   163    165   */
   164    166   #define WINFILE_RDONLY          0x02   /* Connection is read only */
   165    167   #define WINFILE_PERSIST_WAL     0x04   /* Persistent WAL mode */
................................................................................
  2064   2066       return 1;
  2065   2067     }
  2066   2068   
  2067   2069     return 0;
  2068   2070   #endif
  2069   2071   }
  2070   2072   
         2073  +#if SQLITE_MAX_MMAP_SIZE>0
  2071   2074   /* Forward references to VFS methods */
  2072   2075   static int winUnmapfile(winFile*);
         2076  +#endif
  2073   2077   
  2074   2078   /*
  2075   2079   ** Close a file.
  2076   2080   **
  2077   2081   ** It is reported that an attempt to close a handle might sometimes
  2078   2082   ** fail.  This is a very unreasonable result, but Windows is notorious
  2079   2083   ** for being unreasonable so I do not doubt that it might happen.  If
................................................................................
  2089   2093     assert( id!=0 );
  2090   2094   #ifndef SQLITE_OMIT_WAL
  2091   2095     assert( pFile->pShm==0 );
  2092   2096   #endif
  2093   2097     OSTRACE(("CLOSE %d\n", pFile->h));
  2094   2098     assert( pFile->h!=NULL && pFile->h!=INVALID_HANDLE_VALUE );
  2095   2099   
         2100  +#if SQLITE_MAX_MMAP_SIZE>0
  2096   2101     rc = winUnmapfile(pFile);
  2097   2102     if( rc!=SQLITE_OK ) return rc;
         2103  +#endif
  2098   2104   
  2099   2105     do{
  2100   2106       rc = osCloseHandle(pFile->h);
  2101   2107       /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
  2102   2108     }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) );
  2103   2109   #if SQLITE_OS_WINCE
  2104   2110   #define WINCE_DELETION_ATTEMPTS 3
................................................................................
  2838   2844         char *zTFile = sqlite3MallocZero( pFile->pVfs->mxPathname );
  2839   2845         if( zTFile ){
  2840   2846           getTempname(pFile->pVfs->mxPathname, zTFile);
  2841   2847           *(char**)pArg = zTFile;
  2842   2848         }
  2843   2849         return SQLITE_OK;
  2844   2850       }
         2851  +#if SQLITE_MAX_MMAP_SIZE>0
  2845   2852       case SQLITE_FCNTL_MMAP_SIZE: {
  2846   2853         i64 newLimit = *(i64*)pArg;
  2847   2854         if( newLimit>sqlite3GlobalConfig.mxMmap ){
  2848   2855           newLimit = sqlite3GlobalConfig.mxMmap;
  2849   2856         }
  2850   2857         *(i64*)pArg = pFile->mmapSizeMax;
  2851   2858         if( newLimit>=0 ) pFile->mmapSizeMax = newLimit;
  2852   2859         return SQLITE_OK;
  2853   2860       }
         2861  +#endif
  2854   2862     }
  2855   2863     return SQLITE_NOTFOUND;
  2856   2864   }
  2857   2865   
  2858   2866   /*
  2859   2867   ** Return the sector size in bytes of the underlying block device for
  2860   2868   ** the specified file. This is almost always 512 bytes, but may be
................................................................................
  3520   3528   # define winShmBarrier 0
  3521   3529   # define winShmUnmap   0
  3522   3530   #endif /* #ifndef SQLITE_OMIT_WAL */
  3523   3531   
  3524   3532   /*
  3525   3533   ** Cleans up the mapped region of the specified file, if any.
  3526   3534   */
         3535  +#if SQLITE_MAX_MMAP_SIZE>0
  3527   3536   static int winUnmapfile(winFile *pFile){
  3528   3537     assert( pFile!=0 );
  3529         -#if SQLITE_MAX_MMAP_SIZE>0
  3530   3538     if( pFile->pMapRegion ){
  3531   3539       if( !osUnmapViewOfFile(pFile->pMapRegion) ){
  3532   3540         pFile->lastErrno = osGetLastError();
  3533   3541         return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
  3534   3542                            "winUnmap1", pFile->zPath);
  3535   3543       }
  3536   3544       pFile->pMapRegion = 0;
................................................................................
  3541   3549       if( !osCloseHandle(pFile->hMap) ){
  3542   3550         pFile->lastErrno = osGetLastError();
  3543   3551         return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
  3544   3552                            "winUnmap2", pFile->zPath);
  3545   3553       }
  3546   3554       pFile->hMap = NULL;
  3547   3555     }
  3548         -#endif
  3549   3556     return SQLITE_OK;
  3550   3557   }
  3551   3558   
  3552         -#if SQLITE_MAX_MMAP_SIZE>0
  3553   3559   /*
  3554   3560   ** Memory map or remap the file opened by file-descriptor pFd (if the file
  3555   3561   ** is already mapped, the existing mapping is replaced by the new). Or, if 
  3556   3562   ** there already exists a mapping for this file, and there are still 
  3557   3563   ** outstanding xFetch() references to it, this function is a no-op.
  3558   3564   **
  3559   3565   ** If parameter nByte is non-negative, then it is the requested size of 
................................................................................
  3648   3654   ** Finally, if an error does occur, return an SQLite error code. The final
  3649   3655   ** value of *pp is undefined in this case.
  3650   3656   **
  3651   3657   ** If this function does return a pointer, the caller must eventually 
  3652   3658   ** release the reference by calling unixUnfetch().
  3653   3659   */
  3654   3660   static int winFetch(sqlite3_file *fd, i64 iOff, int nAmt, void **pp){
         3661  +#if SQLITE_MAX_MMAP_SIZE>0
  3655   3662     winFile *pFd = (winFile*)fd;   /* The underlying database file */
         3663  +#endif
  3656   3664     *pp = 0;
  3657   3665   
  3658   3666   #if SQLITE_MAX_MMAP_SIZE>0
  3659   3667     if( pFd->mmapSizeMax>0 ){
  3660   3668       if( pFd->pMapRegion==0 ){
  3661   3669         int rc = winMapfile(pFd, -1);
  3662   3670         if( rc!=SQLITE_OK ) return rc;
................................................................................
  3677   3685   ** argument that was passed to the unixFetch() invocation. 
  3678   3686   **
  3679   3687   ** Or, if the third argument is NULL, then this function is being called 
  3680   3688   ** to inform the VFS layer that, according to POSIX, any existing mapping 
  3681   3689   ** may now be invalid and should be unmapped.
  3682   3690   */
  3683   3691   static int winUnfetch(sqlite3_file *fd, i64 iOff, void *p){
         3692  +#if SQLITE_MAX_MMAP_SIZE>0
  3684   3693     winFile *pFd = (winFile*)fd;   /* The underlying database file */
  3685   3694   
  3686   3695     /* If p==0 (unmap the entire file) then there must be no outstanding 
  3687   3696     ** xFetch references. Or, if p!=0 (meaning it is an xFetch reference),
  3688   3697     ** then there must be at least one outstanding.  */
  3689   3698     assert( (p==0)==(pFd->nFetchOut==0) );
  3690   3699   
................................................................................
  3698   3707       ** file while a mapping is held, then the following winUnmapfile() call
  3699   3708       ** is unnecessary can can be omitted - potentially improving
  3700   3709       ** performance.  */
  3701   3710       winUnmapfile(pFd);
  3702   3711     }
  3703   3712   
  3704   3713     assert( pFd->nFetchOut>=0 );
         3714  +#endif
  3705   3715     return SQLITE_OK;
  3706   3716   }
  3707   3717   
  3708   3718   /*
  3709   3719   ** Here ends the implementation of all sqlite3_file methods.
  3710   3720   **
  3711   3721   ********************** End sqlite3_file Methods *******************************
................................................................................
  4125   4135       pFile->ctrlFlags |= WINFILE_RDONLY;
  4126   4136     }
  4127   4137     if( sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) ){
  4128   4138       pFile->ctrlFlags |= WINFILE_PSOW;
  4129   4139     }
  4130   4140     pFile->lastErrno = NO_ERROR;
  4131   4141     pFile->zPath = zName;
         4142  +#if SQLITE_MAX_MMAP_SIZE>0
  4132   4143     pFile->hMap = NULL;
  4133   4144     pFile->pMapRegion = 0;
  4134   4145     pFile->mmapSize = 0;
  4135   4146     pFile->mmapSizeActual = 0;
  4136   4147     pFile->mmapSizeMax = sqlite3GlobalConfig.mxMmap;
         4148  +#endif
  4137   4149   
  4138   4150     OpenCounter(+1);
  4139   4151     return rc;
  4140   4152   }
  4141   4153   
  4142   4154   /*
  4143   4155   ** Delete the named file.