Skip to content

Commit

Permalink
Merge pull request #32 from jamesgolick/master
Browse files Browse the repository at this point in the history
Only try to use fallocate if it's actually present on the system.
  • Loading branch information
liukai committed Dec 26, 2013
2 parents 71ddb11 + c28dd2a commit 5643ae1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
12 changes: 12 additions & 0 deletions build_tools/build_detect_platform
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@ EOF
COMMON_FLAGS="$COMMON_FLAGS -DROCKSDB_ATOMIC_PRESENT"
fi

# Test whether fallocate is available
$CXX $CFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF
#include <fcntl.h>
int main() {
int fd = open("/dev/null", 0);
fallocate(fd, 0, 0, 1024);
}
EOF
if [ "$?" = 0 ]; then
COMMON_FLAGS="$PLATFORM_LDFLAGS -DROCKSDB_FALLOCATE_PRESENT"
fi

# Test whether Snappy library is installed
# http://code.google.com/p/snappy/
$CXX $CFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF
Expand Down
10 changes: 5 additions & 5 deletions util/env_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ class PosixMmapFile : public WritableFile {
}

Status MapNewRegion() {
#ifdef OS_LINUX
#ifdef ROCKSDB_FALLOCATE_PRESENT
assert(base_ == nullptr);

TEST_KILL_RANDOM(rocksdb_kill_odds);
Expand Down Expand Up @@ -575,7 +575,7 @@ class PosixMmapFile : public WritableFile {
#endif
}

#ifdef OS_LINUX
#ifdef ROCKSDB_FALLOCATE_PRESENT
virtual Status Allocate(off_t offset, off_t len) {
TEST_KILL_RANDOM(rocksdb_kill_odds);
if (!fallocate(fd_, FALLOC_FL_KEEP_SIZE, offset, len)) {
Expand Down Expand Up @@ -752,7 +752,7 @@ class PosixWritableFile : public WritableFile {
#endif
}

#ifdef OS_LINUX
#ifdef ROCKSDB_FALLOCATE_PRESENT
virtual Status Allocate(off_t offset, off_t len) {
TEST_KILL_RANDOM(rocksdb_kill_odds);
if (!fallocate(fd_, FALLOC_FL_KEEP_SIZE, offset, len)) {
Expand Down Expand Up @@ -856,7 +856,7 @@ class PosixRandomRWFile : public RandomRWFile {
return Status::OK();
}

#ifdef OS_LINUX
#ifdef ROCKSDB_FALLOCATE_PRESENT
virtual Status Allocate(off_t offset, off_t len) {
if (!fallocate(fd_, FALLOC_FL_KEEP_SIZE, offset, len)) {
return Status::OK();
Expand Down Expand Up @@ -1297,7 +1297,7 @@ class PosixEnv : public Env {
}

bool SupportsFastAllocate(const std::string& path) {
#ifdef OS_LINUX
#ifdef ROCKSDB_FALLOCATE_PRESENT
struct statfs s;
if (statfs(path.c_str(), &s)){
return false;
Expand Down
2 changes: 1 addition & 1 deletion util/posix_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class PosixLogger : public Logger {
assert(p <= limit);
const size_t write_size = p - base;

#ifdef OS_LINUX
#ifdef ROCKSDB_FALLOCATE_PRESENT
// If this write would cross a boundary of kDebugLogChunkSize
// space, pre-allocate more space to avoid overly large
// allocations from filesystem allocsize options.
Expand Down

3 comments on commit 5643ae1

@igorcanadi
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liukai we also need to add -DROCKSDB_FALLOCATE_PRESENT to our fbcode build

@igorcanadi
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liukai
Copy link
Contributor Author

@liukai liukai commented on 5643ae1 Jan 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igorcanadi that's right, thank you!

Please sign in to comment.