0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

sequential option for mmap SERVER-607

This commit is contained in:
Eliot Horowitz 2010-02-04 17:12:14 -05:00
parent 08d0a95688
commit 424e7d9585
4 changed files with 20 additions and 5 deletions

View File

@ -204,7 +204,7 @@ 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( 10308 , "mmap failed" , _buf );
assert( (unsigned long)length == file_size( file ) );
_end = _buf + length;

View File

@ -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);

View File

@ -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;
@ -79,9 +79,16 @@ namespace mongo {
}
return 0;
}
if ( options & SEQUENTIAL ){
if ( madvise( view , length , MADV_SEQUENTIAL ) ){
out() << " madvise failed for " << filename << " " << OUTPUT_ERRNO << endl;
}
}
return view;
}
void MemoryMappedFile::flush(bool sync) {
if ( view == 0 || fd == 0 )
return;

View File

@ -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;