diff --git a/db/db_bench.cc b/db/db_bench.cc index 878a89b65..176927ba6 100644 --- a/db/db_bench.cc +++ b/db/db_bench.cc @@ -110,6 +110,8 @@ static int FLAGS_cache_numshardbits = -1; // Verify checksum for every block read from storage static bool FLAGS_verify_checksum = false; +extern bool useOsBuffer; + namespace leveldb { namespace { @@ -782,7 +784,7 @@ class Benchmark { void ReadRandom(ThreadState* thread) { ReadOptions options(FLAGS_verify_checksum, true); std::string value; - int found = 0; + long found = 0; for (long i = 0; i < reads_; i++) { char key[100]; const int k = thread->rand.Next() % FLAGS_num; @@ -793,7 +795,7 @@ class Benchmark { thread->stats.FinishedSingleOp(); } char msg[100]; - snprintf(msg, sizeof(msg), "(%d of %d found)", found, num_); + snprintf(msg, sizeof(msg), "(%ld of %ld found)", found, num_); thread->stats.AddMessage(msg); } @@ -825,7 +827,7 @@ class Benchmark { void SeekRandom(ThreadState* thread) { ReadOptions options(FLAGS_verify_checksum, true); std::string value; - int found = 0; + long found = 0; for (long i = 0; i < reads_; i++) { Iterator* iter = db_->NewIterator(options); char key[100]; @@ -837,7 +839,7 @@ class Benchmark { thread->stats.FinishedSingleOp(); } char msg[100]; - snprintf(msg, sizeof(msg), "(%d of %d found)", found, num_); + snprintf(msg, sizeof(msg), "(%ld of %ld found)", found, num_); thread->stats.AddMessage(msg); } @@ -978,6 +980,9 @@ int main(int argc, char** argv) { } else if (sscanf(argv[i], "--verify_checksum=%d%c", &n, &junk) == 1 && (n == 0 || n == 1)) { FLAGS_verify_checksum = n; + } else if (sscanf(argv[i], "--bufferedio=%d%c", &n, &junk) == 1 && + (n == 0 || n == 1)) { + useOsBuffer = n; } else { fprintf(stderr, "Invalid flag '%s'\n", argv[i]); exit(1); diff --git a/util/env_posix.cc b/util/env_posix.cc index cb1f6fc05..95d324602 100644 --- a/util/env_posix.cc +++ b/util/env_posix.cc @@ -25,6 +25,8 @@ #include "util/logging.h" #include "util/posix_logger.h" +bool useOsBuffer = 1; // cache data in OS buffers + namespace leveldb { namespace { @@ -86,6 +88,9 @@ class PosixRandomAccessFile: public RandomAccessFile { // An error: return a non-ok status s = IOError(filename_, errno); } + if (!useOsBuffer) { + posix_fadvise(fd_, offset, n, POSIX_FADV_DONTNEED); // free OS pages + } return s; } }; @@ -329,7 +334,7 @@ class PosixEnv : public Env { int fd = open(fname.c_str(), O_RDONLY); if (fd < 0) { s = IOError(fname, errno); - } else if (sizeof(void*) >= 8) { + } else if (useOsBuffer && sizeof(void*) >= 8) { // Use mmap when virtual address-space is plentiful. uint64_t size; s = GetFileSize(fname, &size);