1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

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----- C Reduce\sthe\samount\sof\smemory\staken\sup\sby\sWAL\smmaped\sregions\sunder\sWindows.
Hash: SHA1 D 2010-09-03T04:29:31
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
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in c599a15d268b1db2aeadea19df2adc3bf2eb6bee F Makefile.in c599a15d268b1db2aeadea19df2adc3bf2eb6bee
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -161,7 +158,7 @@ F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9
F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f
F src/os_os2.c 72d0b2e562952a2464308c4ce5f7913ac10bef3e F src/os_os2.c 72d0b2e562952a2464308c4ce5f7913ac10bef3e
F src/os_unix.c 6152042c3a619fbc390eeb59a8eecafa40afc2e4 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.c 51d77a9df463f77bf214f32bb2dbc2d0da41fc3e
F src/pager.h 8167a1e720d0b7a2790079007128e594010220ad F src/pager.h 8167a1e720d0b7a2790079007128e594010220ad
F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58 F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58
@@ -856,14 +853,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P a55842cfb56b659c88832dce9ce7bafb50258211 P f483be441323e1cb91516964cd6ab0edecad4366
R 594e3dfa3a6dc8d6a5c8c27345538f42 R fea23b14c42fedda7d16ff1cb4b9cee7
U drh U shaneh
Z ee5272a19c79aeac7c1c4ce2730a97f0 Z 0fd3f5ddcf6cc38ff6e323baec639592
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFMgGxjoxKgR168RlERAhqOAJ9FP1hqTUFVkGHxgeL6o/5M5ubTIACdEZ+8
j6hDw1rJ1tox5dDUeDLXEFM=
=rovz
-----END PGP SIGNATURE-----

View File

@@ -1 +1 @@
f483be441323e1cb91516964cd6ab0edecad4366 f213e133f6e69b0edd73d96142014bdcab9dfe41

View File

@@ -1212,6 +1212,14 @@ static int winDeviceCharacteristics(sqlite3_file *id){
#ifndef SQLITE_OMIT_WAL #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 ** Helper functions to obtain and relinquish the global mutex. The
** global mutex is used to protect the winLockInfo objects used by ** 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){ static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){
winShmNode **pp; winShmNode **pp;
winShmNode *p; winShmNode *p;
BOOL bRc;
assert( winShmMutexHeld() ); assert( winShmMutexHeld() );
pp = &winShmNodeList; pp = &winShmNodeList;
while( (p = *pp)!=0 ){ while( (p = *pp)!=0 ){
@@ -1387,8 +1396,14 @@ static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){
int i; int i;
if( p->mutex ) sqlite3_mutex_free(p->mutex); if( p->mutex ) sqlite3_mutex_free(p->mutex);
for(i=0; i<p->nRegion; i++){ for(i=0; i<p->nRegion; i++){
UnmapViewOfFile(p->aRegion[i].pMap); bRc = UnmapViewOfFile(p->aRegion[i].pMap);
CloseHandle(p->aRegion[i].hMap); 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 ){ if( p->hFile.h != INVALID_HANDLE_VALUE ){
SimulateIOErrorBenign(1); SimulateIOErrorBenign(1);
@@ -1465,6 +1480,7 @@ static int winOpenSharedMemory(winFile *pDbFd){
rc = SQLITE_NOMEM; rc = SQLITE_NOMEM;
goto shm_open_err; goto shm_open_err;
} }
rc = winOpen(pDbFd->pVfs, rc = winOpen(pDbFd->pVfs,
pShmNode->zFilename, /* Name of the file (UTF-8) */ pShmNode->zFilename, /* Name of the file (UTF-8) */
(sqlite3_file*)&pShmNode->hFile, /* File handle here */ (sqlite3_file*)&pShmNode->hFile, /* File handle here */
@@ -1776,10 +1792,18 @@ static int winShmMap(
hMap = CreateFileMapping(pShmNode->hFile.h, hMap = CreateFileMapping(pShmNode->hFile.h,
NULL, PAGE_READWRITE, 0, nByte, NULL 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 ){ if( hMap ){
int iOffset = pShmNode->nRegion*szRegion;
int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
pMap = MapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ, 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 ){ if( !pMap ){
pShmNode->lastErrno = GetLastError(); pShmNode->lastErrno = GetLastError();
@@ -1796,8 +1820,10 @@ static int winShmMap(
shmpage_out: shmpage_out:
if( pShmNode->nRegion>iRegion ){ if( pShmNode->nRegion>iRegion ){
int iOffset = iRegion*szRegion;
int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
char *p = (char *)pShmNode->aRegion[iRegion].pMap; char *p = (char *)pShmNode->aRegion[iRegion].pMap;
*pp = (void *)&p[iRegion*szRegion]; *pp = (void *)&p[iOffsetShift];
}else{ }else{
*pp = 0; *pp = 0;
} }
@@ -2738,6 +2764,13 @@ int sqlite3_os_init(void){
winCurrentTimeInt64, /* xCurrentTimeInt64 */ 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); sqlite3_vfs_register(&winVfs, 1);
return SQLITE_OK; return SQLITE_OK;
} }