提交 93f49520 编写于 作者: D Dhruba Borthakur

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
上级 4028ae7d
......@@ -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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册