Skip to content

Commit 43c386b

Browse files
committed
only try to use fallocate if it's actually present on the system
1 parent 5e4ab76 commit 43c386b

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

build_tools/build_detect_platform

+12
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

+4-4
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();

util/posix_logger.h

+1-1
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)