Ability to switch off filesystem read-aheads

Summary:
Ability to switch off filesystem read-aheads. This change is
backward-compatible: the default setting is to allow file
system read-aheads.

Test Plan: run benchmarks

Reviewers: heyongqiang, adsharma

Reviewed By: heyongqiang

Differential Revision: https://reviews.facebook.net/D5391
main
Dhruba Borthakur 12 years ago
parent 4028ae7d31
commit 93f4952089
  1. 4
      db/db_bench.cc
  2. 8
      util/env_posix.cc

@ -165,6 +165,7 @@ static int FLAGS_readwritepercent = 90;
static leveldb::Env* FLAGS_env = leveldb::Env::Default();
extern bool useOsBuffer;
extern bool useFsReadAhead;
namespace leveldb {
@ -1133,6 +1134,9 @@ int main(int argc, char** argv) {
} else if (sscanf(argv[i], "--bufferedio=%d%c", &n, &junk) == 1 &&
(n == 0 || n == 1)) {
useOsBuffer = n;
} else if (sscanf(argv[i], "--readhead=%d%c", &n, &junk) == 1 &&
(n == 0 || n == 1)) {
useFsReadAhead = n;
} else if (sscanf(argv[i], "--statistics=%d%c", &n, &junk) == 1 &&
(n == 0 || n == 1)) {
if (n == 1) {

@ -27,6 +27,7 @@
#include "util/posix_logger.h"
bool useOsBuffer = 1; // cache data in OS buffers
bool useFsReadAhead = 1; // allow filesystem to do readaheads
namespace leveldb {
@ -81,7 +82,12 @@ class PosixRandomAccessFile: public RandomAccessFile {
public:
PosixRandomAccessFile(const std::string& fname, int fd)
: filename_(fname), fd_(fd) { }
: filename_(fname), fd_(fd) {
if (!useFsReadAhead) {
// disable read-aheads
posix_fadvise(fd, 0, 0, POSIX_FADV_RANDOM);
}
}
virtual ~PosixRandomAccessFile() { close(fd_); }
virtual Status Read(uint64_t offset, size_t n, Slice* result,

Loading…
Cancel
Save