diff options
author | Antonin Kral <a.kral@bobek.cz> | 2011-09-14 17:08:06 +0200 |
---|---|---|
committer | Antonin Kral <a.kral@bobek.cz> | 2011-09-14 17:08:06 +0200 |
commit | 5d342a758c6095b4d30aba0750b54f13b8916f51 (patch) | |
tree | 762e9aa84781f5e3b96db2c02d356c29cf0217c0 /util/mmap_posix.cpp | |
parent | cbe2d992e9cd1ea66af9fa91df006106775d3073 (diff) | |
download | mongodb-5d342a758c6095b4d30aba0750b54f13b8916f51.tar.gz |
Imported Upstream version 2.0.0
Diffstat (limited to 'util/mmap_posix.cpp')
-rw-r--r-- | util/mmap_posix.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/util/mmap_posix.cpp b/util/mmap_posix.cpp index f47a06f..5b5e86d 100644 --- a/util/mmap_posix.cpp +++ b/util/mmap_posix.cpp @@ -19,13 +19,12 @@ #include "mmap.h" #include "file_allocator.h" #include "../db/concurrency.h" - #include <errno.h> #include <sys/mman.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> - +#include "../util/processinfo.h" #include "mongoutils/str.h" using namespace mongoutils; @@ -39,6 +38,7 @@ namespace mongo { } void MemoryMappedFile::close() { + mmmutex.assertExclusivelyLocked(); for( vector<void*>::iterator i = views.begin(); i != views.end(); i++ ) { munmap(*i,len); } @@ -47,6 +47,7 @@ namespace mongo { if ( fd ) ::close(fd); fd = 0; + destroyed(); // cleans up from the master list of mmaps } #ifndef O_NOATIME @@ -57,6 +58,19 @@ namespace mongo { #define MAP_NORESERVE (0) #endif +#if defined(__sunos__) + MAdvise::MAdvise(void *,unsigned, Advice) { } + MAdvise::~MAdvise() { } +#else + MAdvise::MAdvise(void *p, unsigned len, Advice a) : _p(p), _len(len) { + assert( a == Sequential ); // more later + madvise(_p,_len,MADV_SEQUENTIAL); + } + MAdvise::~MAdvise() { + madvise(_p,_len,MADV_NORMAL); + } +#endif + void* MemoryMappedFile::map(const char *filename, unsigned long long &length, int options) { // length may be updated by callee. setFilename(filename); @@ -68,6 +82,7 @@ namespace mongo { fd = open(filename, O_RDWR | O_NOATIME); if ( fd <= 0 ) { log() << "couldn't open " << filename << ' ' << errnoWithDescription() << endl; + fd = 0; // our sentinel for not opened return 0; } @@ -149,6 +164,7 @@ namespace mongo { int err = errno; error() << "13601 Couldn't remap private view: " << errnoWithDescription(err) << endl; log() << "aborting" << endl; + printMemInfo(); abort(); } assert( x == oldPrivateAddr ); @@ -158,7 +174,7 @@ namespace mongo { void MemoryMappedFile::flush(bool sync) { if ( views.empty() || fd == 0 ) return; - if ( msync(views[0], len, sync ? MS_SYNC : MS_ASYNC) ) + if ( msync(viewForFlushing(), len, sync ? MS_SYNC : MS_ASYNC) ) problem() << "msync " << errnoWithDescription() << endl; } @@ -181,7 +197,7 @@ namespace mongo { }; MemoryMappedFile::Flushable * MemoryMappedFile::prepareFlush() { - return new PosixFlushable( views.empty() ? 0 : views[0] , fd , len ); + return new PosixFlushable( viewForFlushing() , fd , len ); } void MemoryMappedFile::_lock() { |