Reduce the amount of memory taken up by WAL mmaped regions under Windows.

FossilOrigin-Name: f213e133f6e69b0edd73d96142014bdcab9dfe41
This commit is contained in:
shaneh 2010-09-03 04:29:30 +00:00
parent 9dd55f5187
commit 420398ce09
3 changed files with 45 additions and 22 deletions

View File

@ -1,8 +1,5 @@
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
C Fix\sa\sdiscrepancy\sbetween\sthe\sdocumented\sbehavior\sof\sSQLITE_DBCONFIG_LOOKASIDE\nand\swhat\sit\sactually\sdoes.\s\sAlso\sadd\sevidence\smarks\son\sthe\sDBCONFIG_LOOKASIDE\nimplementation.
D 2010-09-03T03:32:47
C Reduce\sthe\samount\sof\smemory\staken\sup\sby\sWAL\smmaped\sregions\sunder\sWindows.
D 2010-09-03T04:29:31
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in c599a15d268b1db2aeadea19df2adc3bf2eb6bee
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -161,7 +158,7 @@ F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9
F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f
F src/os_os2.c 72d0b2e562952a2464308c4ce5f7913ac10bef3e
F src/os_unix.c 6152042c3a619fbc390eeb59a8eecafa40afc2e4
F src/os_win.c 6fb3447ffe56df0dbb2d1ac93f75c9c748e009e1
F src/os_win.c 2f90f7bdec714fad51cd31b4ecad3cc1b4bb5aad
F src/pager.c 51d77a9df463f77bf214f32bb2dbc2d0da41fc3e
F src/pager.h 8167a1e720d0b7a2790079007128e594010220ad
F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58
@ -856,14 +853,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P a55842cfb56b659c88832dce9ce7bafb50258211
R 594e3dfa3a6dc8d6a5c8c27345538f42
U drh
Z ee5272a19c79aeac7c1c4ce2730a97f0
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFMgGxjoxKgR168RlERAhqOAJ9FP1hqTUFVkGHxgeL6o/5M5ubTIACdEZ+8
j6hDw1rJ1tox5dDUeDLXEFM=
=rovz
-----END PGP SIGNATURE-----
P f483be441323e1cb91516964cd6ab0edecad4366
R fea23b14c42fedda7d16ff1cb4b9cee7
U shaneh
Z 0fd3f5ddcf6cc38ff6e323baec639592

View File

@ -1 +1 @@
f483be441323e1cb91516964cd6ab0edecad4366
f213e133f6e69b0edd73d96142014bdcab9dfe41

View File

@ -1212,6 +1212,14 @@ static int winDeviceCharacteristics(sqlite3_file *id){
#ifndef SQLITE_OMIT_WAL
/*
** Windows will only let you create file view mappings
** on allocation size granularity boundaries.
** During sqlite3_os_init() we do a GetSystemInfo()
** to get the granularity size.
*/
SYSTEM_INFO winSysInfo;
/*
** Helper functions to obtain and relinquish the global mutex. The
** global mutex is used to protect the winLockInfo objects used by
@ -1380,6 +1388,7 @@ static int winDelete(sqlite3_vfs *,const char*,int);
static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){
winShmNode **pp;
winShmNode *p;
BOOL bRc;
assert( winShmMutexHeld() );
pp = &winShmNodeList;
while( (p = *pp)!=0 ){
@ -1387,8 +1396,14 @@ static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){
int i;
if( p->mutex ) sqlite3_mutex_free(p->mutex);
for(i=0; i<p->nRegion; i++){
UnmapViewOfFile(p->aRegion[i].pMap);
CloseHandle(p->aRegion[i].hMap);
bRc = UnmapViewOfFile(p->aRegion[i].pMap);
OSTRACE(("SHM-PURGE pid-%d unmap region=%d %s\n",
(int)GetCurrentProcessId(), i,
bRc ? "ok" : "failed"));
bRc = CloseHandle(p->aRegion[i].hMap);
OSTRACE(("SHM-PURGE pid-%d close region=%d %s\n",
(int)GetCurrentProcessId(), i,
bRc ? "ok" : "failed"));
}
if( p->hFile.h != INVALID_HANDLE_VALUE ){
SimulateIOErrorBenign(1);
@ -1465,6 +1480,7 @@ static int winOpenSharedMemory(winFile *pDbFd){
rc = SQLITE_NOMEM;
goto shm_open_err;
}
rc = winOpen(pDbFd->pVfs,
pShmNode->zFilename, /* Name of the file (UTF-8) */
(sqlite3_file*)&pShmNode->hFile, /* File handle here */
@ -1776,10 +1792,18 @@ static int winShmMap(
hMap = CreateFileMapping(pShmNode->hFile.h,
NULL, PAGE_READWRITE, 0, nByte, NULL
);
OSTRACE(("SHM-MAP pid-%d create region=%d nbyte=%d %s\n",
(int)GetCurrentProcessId(), pShmNode->nRegion, nByte,
hMap ? "ok" : "failed"));
if( hMap ){
int iOffset = pShmNode->nRegion*szRegion;
int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
pMap = MapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ,
0, 0, nByte
0, iOffset - iOffsetShift, szRegion + iOffsetShift
);
OSTRACE(("SHM-MAP pid-%d map region=%d offset=%d size=%d %s\n",
(int)GetCurrentProcessId(), pShmNode->nRegion, iOffset, szRegion,
pMap ? "ok" : "failed"));
}
if( !pMap ){
pShmNode->lastErrno = GetLastError();
@ -1796,8 +1820,10 @@ static int winShmMap(
shmpage_out:
if( pShmNode->nRegion>iRegion ){
int iOffset = iRegion*szRegion;
int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
char *p = (char *)pShmNode->aRegion[iRegion].pMap;
*pp = (void *)&p[iRegion*szRegion];
*pp = (void *)&p[iOffsetShift];
}else{
*pp = 0;
}
@ -2738,6 +2764,13 @@ int sqlite3_os_init(void){
winCurrentTimeInt64, /* xCurrentTimeInt64 */
};
#ifndef SQLITE_OMIT_WAL
/* get memory map allocation granularity */
memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
GetSystemInfo(&winSysInfo);
assert(winSysInfo.dwAllocationGranularity > 0);
#endif
sqlite3_vfs_register(&winVfs, 1);
return SQLITE_OK;
}