summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Kreuter <richard@10gen.com>2010-02-18 14:24:10 -0500
committerRichard Kreuter <richard@10gen.com>2010-02-18 14:24:10 -0500
commitb790e13761f1e29ec2757ef00e4de86c5ff6ca60 (patch)
tree210d045d09cf86bd8fb00acc0a8cc0ea3f3232a0
parent899328a8cf10626eebf8a235f38040c35e7e01cf (diff)
parentb83c5efe356b31b2fdb7411bc6352e0433bf1339 (diff)
downloadmongo-b790e13761f1e29ec2757ef00e4de86c5ff6ca60.tar.gz
Merge branch 'v1.2' of github.com:mongodb/mongo into v1.2
-rw-r--r--db/extsort.cpp3
-rw-r--r--util/goodies.h2
-rw-r--r--util/mmap.h6
-rw-r--r--util/mmap_posix.cpp11
-rw-r--r--util/mmap_win.cpp6
5 files changed, 22 insertions, 6 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/goodies.h b/util/goodies.h
index f4829d9aba4..f366107a4e3 100644
--- a/util/goodies.h
+++ b/util/goodies.h
@@ -25,7 +25,7 @@
namespace mongo {
-#if !defined(_WIN32) && !defined(NOEXECINFO)
+#if !defined(_WIN32) && !defined(NOEXECINFO) && !defined(__freebsd__)
} // namespace mongo
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;