mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-12 13:01:09 +03:00
Use mremap() on Linux.
FossilOrigin-Name: 431aecc8600c29c203546e48d256510510238887
This commit is contained in:
@@ -4544,21 +4544,28 @@ static int unixMapfile(unixFile *pFd, i64 nByte){
|
||||
}
|
||||
|
||||
if( nMap!=pFd->mmapSize ){
|
||||
unixUnmapfile(pFd);
|
||||
void *pNew = 0;
|
||||
|
||||
if( nMap>0 ){
|
||||
void *pNew;
|
||||
int flags = PROT_READ;
|
||||
if( (pFd->ctrlFlags & UNIXFILE_RDONLY)==0 ) flags |= PROT_WRITE;
|
||||
pNew = osMmap(0, nMap, flags, MAP_SHARED, pFd->h, 0);
|
||||
if( pNew==MAP_FAILED ){
|
||||
return SQLITE_IOERR_MMAP;
|
||||
#if defined(__linux__) && defined(_GNU_SOURCE)
|
||||
if( pFd->pMapRegion && nMap>0 ){
|
||||
pNew = mremap(pFd->pMapRegion, pFd->mmapOrigsize, nMap, MREMAP_MAYMOVE);
|
||||
}else
|
||||
#endif
|
||||
{
|
||||
unixUnmapfile(pFd);
|
||||
if( nMap>0 ){
|
||||
int flags = PROT_READ;
|
||||
if( (pFd->ctrlFlags & UNIXFILE_RDONLY)==0 ) flags |= PROT_WRITE;
|
||||
pNew = osMmap(0, nMap, flags, MAP_SHARED, pFd->h, 0);
|
||||
}
|
||||
|
||||
pFd->pMapRegion = pNew;
|
||||
pFd->mmapSize = nMap;
|
||||
pFd->mmapOrigsize = nMap;
|
||||
}
|
||||
|
||||
if( pNew==MAP_FAILED ){
|
||||
return SQLITE_IOERR_MMAP;
|
||||
}
|
||||
pFd->pMapRegion = pNew;
|
||||
pFd->mmapSize = nMap;
|
||||
pFd->mmapOrigsize = nMap;
|
||||
}
|
||||
|
||||
return SQLITE_OK;
|
||||
|
||||
Reference in New Issue
Block a user