diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-02-16 00:39:39 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-02-16 00:39:39 -0500 |
commit | e07cbe6088d4650bedf5bf2c797fd34506952941 (patch) | |
tree | 57f7625a3d48e8794291a9abd47af52556a175ba | |
parent | fc3d3acafc253da085f7d0cdcd91059cc9bcd8e3 (diff) | |
download | mongo-e07cbe6088d4650bedf5bf2c797fd34506952941.tar.gz |
sequential option for mmap SERVER-607
Conflicts:
db/extsort.cpp
-rw-r--r-- | db/extsort.cpp | 3 | ||||
-rw-r--r-- | util/mmap.h | 6 | ||||
-rw-r--r-- | util/mmap_posix.cpp | 11 | ||||
-rw-r--r-- | util/mmap_win.cpp | 6 |
4 files changed, 21 insertions, 5 deletions
diff --git a/db/extsort.cpp b/db/extsort.cpp index 949c2e66500..751c63e650f 100644 --- a/db/extsort.cpp +++ b/db/extsort.cpp @@ -204,7 +204,8 @@ namespace mongo { BSONObjExternalSorter::FileIterator::FileIterator( string file ){ long length; - _buf = (char*)_file.map( file.c_str() , length ); + _buf = (char*)_file.map( file.c_str() , length , MemoryMappedFile::SEQUENTIAL ); + massert( "mmap failed" , _buf ); assert( (unsigned long)length == file_size( file ) ); _end = _buf + length; } diff --git a/util/mmap.h b/util/mmap.h index ed4ca99c326..140f33a5bd1 100644 --- a/util/mmap.h +++ b/util/mmap.h @@ -22,6 +22,10 @@ namespace mongo { class MemoryMappedFile { public: + enum Options { + SEQUENTIAL = 1 + }; + MemoryMappedFile(); ~MemoryMappedFile(); /* closes the file if open */ void close(); @@ -32,7 +36,7 @@ namespace mongo { /* Creates with length if DNE, otherwise uses existing file length, passed length. */ - void* map(const char *filename, long &length); + void* map(const char *filename, long &length, int options = 0 ); void flush(bool sync); diff --git a/util/mmap_posix.cpp b/util/mmap_posix.cpp index 25deb871f92..5acedf1f752 100644 --- a/util/mmap_posix.cpp +++ b/util/mmap_posix.cpp @@ -49,7 +49,7 @@ namespace mongo { #define O_NOATIME 0 #endif - void* MemoryMappedFile::map(const char *filename, long &length) { + void* MemoryMappedFile::map(const char *filename, long &length, int options) { // length may be updated by callee. theFileAllocator().allocateAsap( filename, length ); len = length; @@ -76,9 +76,16 @@ namespace mongo { } return 0; } + + if ( options & SEQUENTIAL ){ + if ( madvise( view , length , MADV_SEQUENTIAL ) ){ + out() << " madvise failed for " << filename << " " << errno << endl; + } + } + return view; } - + void MemoryMappedFile::flush(bool sync) { if ( view == 0 || fd == 0 ) return; diff --git a/util/mmap_win.cpp b/util/mmap_win.cpp index 32528342b42..7db43601b13 100644 --- a/util/mmap_win.cpp +++ b/util/mmap_win.cpp @@ -69,9 +69,13 @@ namespace mongo { updateLength( filename, length ); std::wstring filenamew = toWideString(filename); + DWORD createOptions = FILE_ATTRIBUTE_NORMAL; + if ( options & SEQUENTIAL ) + createOptions |= FILE_FLAG_SEQUENTIAL_SCAN; + fd = CreateFile( filenamew.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, - NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + NULL, OPEN_ALWAYS, createOptions , NULL); if ( fd == INVALID_HANDLE_VALUE ) { out() << "Create/OpenFile failed " << filename << ' ' << GetLastError() << endl; return 0; |