From 186b3afaa850053f2368ddc78eef4bdec59b85c0 Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Mon, 4 Mar 2019 15:40:26 -0800 Subject: [PATCH] Use `fallocate` even if hole-punching unsupported (#5023) Summary: The compiler flag `-DROCKSDB_FALLOCATE_PRESENT` was only set when `fallocate`, `FALLOC_FL_KEEP_SIZE`, and `FALLOC_FL_PUNCH_HOLE` were all present. However, the last of the three is not really necessary for the primary `fallocate` use case; furthermore, it was introduced only in later Linux kernel versions (2.6.38+). This PR changes the flag `-DROCKSDB_FALLOCATE_PRESENT` to only require `fallocate` and `FALLOC_FL_KEEP_SIZE` to be present. There is a separate check for `FALLOC_FL_PUNCH_HOLE` only in the place where it is used. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5023 Differential Revision: D14248487 Pulled By: siying fbshipit-source-id: a10ed0b902fa755988e957bd2dcec9081ec0502e --- CMakeLists.txt | 2 +- build_tools/build_detect_platform | 2 +- env/io_posix.cc | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 40cdd26bb..9cabf3b38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -416,7 +416,7 @@ if(WITH_FALLOCATE) #include int main() { int fd = open(\"/dev/null\", 0); - fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, 0, 1024); + fallocate(fd, FALLOC_FL_KEEP_SIZE, 0, 1024); } " HAVE_FALLOCATE) if(HAVE_FALLOCATE) diff --git a/build_tools/build_detect_platform b/build_tools/build_detect_platform index 5b99aad7f..e17c9a0fd 100755 --- a/build_tools/build_detect_platform +++ b/build_tools/build_detect_platform @@ -234,7 +234,7 @@ else #include int main() { int fd = open("/dev/null", 0); - fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, 0, 1024); + fallocate(fd, FALLOC_FL_KEEP_SIZE, 0, 1024); } EOF if [ "$?" = 0 ]; then diff --git a/env/io_posix.cc b/env/io_posix.cc index d0a53763d..967a6ace8 100644 --- a/env/io_posix.cc +++ b/env/io_posix.cc @@ -825,7 +825,8 @@ Status PosixWritableFile::Close() { // but it will be nice to log these errors. int dummy __attribute__((__unused__)); dummy = ftruncate(fd_, filesize_); -#if defined(ROCKSDB_FALLOCATE_PRESENT) && !defined(TRAVIS) +#if defined(ROCKSDB_FALLOCATE_PRESENT) && defined(FALLOC_FL_PUNCH_HOLE) && \ + !defined(TRAVIS) // in some file systems, ftruncate only trims trailing space if the // new file size is smaller than the current size. Calling fallocate // with FALLOC_FL_PUNCH_HOLE flag to explicitly release these unused