Skip to content

Commit 5643ae1

Browse files
committed
Merge pull request #32 from jamesgolick/master
Only try to use fallocate if it's actually present on the system.
2 parents 71ddb11 + c28dd2a commit 5643ae1

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

build_tools/build_detect_platform

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,18 @@ EOF
189189
COMMON_FLAGS="$COMMON_FLAGS -DROCKSDB_ATOMIC_PRESENT"
190190
fi
191191

192+
# Test whether fallocate is available
193+
$CXX $CFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF
194+
#include <fcntl.h>
195+
int main() {
196+
int fd = open("/dev/null", 0);
197+
fallocate(fd, 0, 0, 1024);
198+
}
199+
EOF
200+
if [ "$?" = 0 ]; then
201+
COMMON_FLAGS="$PLATFORM_LDFLAGS -DROCKSDB_FALLOCATE_PRESENT"
202+
fi
203+
192204
# Test whether Snappy library is installed
193205
# http://code.google.com/p/snappy/
194206
$CXX $CFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF

util/env_posix.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ class PosixMmapFile : public WritableFile {
389389
}
390390

391391
Status MapNewRegion() {
392-
#ifdef OS_LINUX
392+
#ifdef ROCKSDB_FALLOCATE_PRESENT
393393
assert(base_ == nullptr);
394394

395395
TEST_KILL_RANDOM(rocksdb_kill_odds);
@@ -575,7 +575,7 @@ class PosixMmapFile : public WritableFile {
575575
#endif
576576
}
577577

578-
#ifdef OS_LINUX
578+
#ifdef ROCKSDB_FALLOCATE_PRESENT
579579
virtual Status Allocate(off_t offset, off_t len) {
580580
TEST_KILL_RANDOM(rocksdb_kill_odds);
581581
if (!fallocate(fd_, FALLOC_FL_KEEP_SIZE, offset, len)) {
@@ -752,7 +752,7 @@ class PosixWritableFile : public WritableFile {
752752
#endif
753753
}
754754

755-
#ifdef OS_LINUX
755+
#ifdef ROCKSDB_FALLOCATE_PRESENT
756756
virtual Status Allocate(off_t offset, off_t len) {
757757
TEST_KILL_RANDOM(rocksdb_kill_odds);
758758
if (!fallocate(fd_, FALLOC_FL_KEEP_SIZE, offset, len)) {
@@ -856,7 +856,7 @@ class PosixRandomRWFile : public RandomRWFile {
856856
return Status::OK();
857857
}
858858

859-
#ifdef OS_LINUX
859+
#ifdef ROCKSDB_FALLOCATE_PRESENT
860860
virtual Status Allocate(off_t offset, off_t len) {
861861
if (!fallocate(fd_, FALLOC_FL_KEEP_SIZE, offset, len)) {
862862
return Status::OK();
@@ -1297,7 +1297,7 @@ class PosixEnv : public Env {
12971297
}
12981298

12991299
bool SupportsFastAllocate(const std::string& path) {
1300-
#ifdef OS_LINUX
1300+
#ifdef ROCKSDB_FALLOCATE_PRESENT
13011301
struct statfs s;
13021302
if (statfs(path.c_str(), &s)){
13031303
return false;

util/posix_logger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class PosixLogger : public Logger {
111111
assert(p <= limit);
112112
const size_t write_size = p - base;
113113

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

0 commit comments

Comments
 (0)