void* MemoryMappedFile::remapPrivateView(void *oldPrivateAddr) { d.dbMutex.assertWriteLocked(); // short window where we are unmapped so must be exclusive RemapLock lk; // Interlock with PortMessageServer::acceptedMP() to stop thread creation clearWritableBits(oldPrivateAddr); if( !UnmapViewOfFile(oldPrivateAddr) ) { DWORD dosError = GetLastError(); log() << "UnMapViewOfFile for " << filename() << " failed with error " << errnoWithDescription( dosError ) << endl; fassertFailed( 16147 ); } void* newPrivateView = MapViewOfFileEx( maphandle, // file mapping handle FILE_MAP_READ, // access 0, 0, // file offset, high and low 0, // bytes to map, 0 == all oldPrivateAddr ); // we want the same address we had before if ( 0 == newPrivateView ) { DWORD dosError = GetLastError(); log() << "MapViewOfFileEx for " << filename() << " failed with error " << errnoWithDescription( dosError ) << endl; } fassert( 16148, newPrivateView == oldPrivateAddr ); return newPrivateView; }
void* MemoryMappedFile::remapPrivateView(void *oldPrivateAddr) { verify( Lock::isW() ); LockMongoFilesExclusive lockMongoFiles; clearWritableBits(oldPrivateAddr); if( !UnmapViewOfFile(oldPrivateAddr) ) { DWORD dosError = GetLastError(); log() << "UnMapViewOfFile for " << filename() << " failed with error " << errnoWithDescription( dosError ) << " in MemoryMappedFile::remapPrivateView" << endl; fassertFailed( 16168 ); } void* newPrivateView = MapViewOfFileEx( maphandle, // file mapping handle FILE_MAP_READ, // access 0, 0, // file offset, high and low 0, // bytes to map, 0 == all oldPrivateAddr ); // we want the same address we had before if ( 0 == newPrivateView ) { DWORD dosError = GetLastError(); log() << "MapViewOfFileEx for " << filename() << " failed with error " << errnoWithDescription( dosError ) << " (file size is " << len << ")" << " in MemoryMappedFile::remapPrivateView" << endl; } fassert( 16148, newPrivateView == oldPrivateAddr ); return newPrivateView; }
void MemoryMappedFile::close() { LockMongoFilesShared::assertExclusivelyLocked(); for( vector<void*>::iterator i = views.begin(); i != views.end(); i++ ) { clearWritableBits(*i); UnmapViewOfFile(*i); } views.clear(); if ( maphandle ) CloseHandle(maphandle); maphandle = 0; if ( fd ) CloseHandle(fd); fd = 0; destroyed(); // cleans up from the master list of mmaps }
void* MemoryMappedFile::createPrivateMap() { verify( maphandle ); scoped_lock lk(mapViewMutex); LPVOID thisAddress = getNextMemoryMappedFileLocation( len ); void* privateMapAddress = NULL; int current_retry = 0; while (true) { privateMapAddress = MapViewOfFileEx( maphandle, // file mapping handle FILE_MAP_READ, // access 0, 0, // file offset, high and low 0, // bytes to map, 0 == all thisAddress); // address to place file if (privateMapAddress == 0) { DWORD dosError = GetLastError(); ++current_retry; // If we failed to allocate a memory mapped file, try again in case we picked // an address that Windows is also trying to use for some other VM allocations if (dosError == ERROR_INVALID_ADDRESS && current_retry < 5) { continue; } log() << "MapViewOfFileEx for " << filename() << " failed with error " << errnoWithDescription(dosError) << " (file size is " << len << ")" << " in MemoryMappedFile::createPrivateMap" << endl; fassertFailed(16167); } break; } clearWritableBits( privateMapAddress ); views.push_back( privateMapAddress ); return privateMapAddress; }
void* MemoryMappedFile::createPrivateMap() { verify( maphandle ); scoped_lock lk(mapViewMutex); void *p = MapViewOfFile(maphandle, FILE_MAP_READ, 0, 0, 0); if ( p == 0 ) { DWORD e = GetLastError(); log() << "createPrivateMap failed " << filename() << " " << errnoWithDescription(e) << " filelen:" << len << ((sizeof(void*) == 4 ) ? " (32 bit build)" : "") << endl; } else { clearWritableBits(p); views.push_back(p); memconcept::is(p, memconcept::concept::memorymappedfile, filename()); } return p; }
void MemoryMappedFile::close() { LockMongoFilesShared::assertExclusivelyLocked(); // Prevent flush and close from concurrently running boost::lock_guard<boost::mutex> lk(_flushMutex); for( vector<void*>::iterator i = views.begin(); i != views.end(); i++ ) { clearWritableBits(*i); UnmapViewOfFile(*i); } views.clear(); if ( maphandle ) CloseHandle(maphandle); maphandle = 0; if ( fd ) CloseHandle(fd); fd = 0; destroyed(); // cleans up from the master list of mmaps }
void* MemoryMappedFile::createPrivateMap() { verify( maphandle ); scoped_lock lk(mapViewMutex); void* privateMapAddress = MapViewOfFile( maphandle, // file mapping handle FILE_MAP_READ, // access 0, 0, // file offset, high and low 0 ); // bytes to map, 0 == all if ( privateMapAddress == 0 ) { DWORD dosError = GetLastError(); log() << "MapViewOfFile for " << filename() << " failed with error " << errnoWithDescription( dosError ) << " (file size is " << len << ")" << " in MemoryMappedFile::createPrivateMap" << endl; fassertFailed( 16167 ); } clearWritableBits( privateMapAddress ); views.push_back( privateMapAddress ); memconcept::is( privateMapAddress, memconcept::concept::memorymappedfile, filename() ); return privateMapAddress; }