fs: use ftruncate in AllocateFileRange on OpenBSD #32645

pull theStack wants to merge 1 commits into bitcoin:master from theStack:202505-fs-use_ftruncate_on_openbsd changing 1 files +4 −1
  1. theStack commented at 1:41 pm on May 30, 2025: contributor

    Closes #32643.

    Tested on OpenBSD 7.7 (amd64) by running a signet IBD, with the following patch on top to ensure the fallback isn’t executed anymore:

     0diff --git a/src/util/fs_helpers.cpp b/src/util/fs_helpers.cpp
     1index 84ac3690c9..c6dff2d29d 100644
     2--- a/src/util/fs_helpers.cpp
     3+++ b/src/util/fs_helpers.cpp
     4@@ -208,6 +208,7 @@ void AllocateFileRange(FILE* file, unsigned int offset, unsigned int length)
     5     // OpenBSD doesn't have fallocate or posix_fallocate, use ftruncate
     6     if (0 == ftruncate(fileno(file), nEndPos)) return;
     7 #endif
     8+    assert(false);
     9     // Fallback version
    10     // TODO: just write one byte per block
    11     static const char buf[65536] = {};
    

    Didn’t run any performance tests, happy to take inputs on how to best measure any potential difference.

    For another reference, here’s an OpenBSD ports patch for kitty that replaces posix_fallocate with ftruncate: https://github.com/openbsd/ports/blob/master/x11/kitty/patches/patch-glfw_backend_utils_c

  2. fs: use ftruncate in AllocateFileRange on OpenBSD
    Closes issue #32643.
    9982d525c5
  3. DrahtBot commented at 1:41 pm on May 30, 2025: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32645.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

  4. in src/util/fs_helpers.cpp:201 in 9982d525c5
    199@@ -200,10 +200,13 @@ void AllocateFileRange(FILE* file, unsigned int offset, unsigned int length)
    200     }
    201     ftruncate(fileno(file), static_cast<off_t>(offset) + length);
    


    luke-jr commented at 9:19 pm on June 6, 2025:
    We’re already calling fallocate here… seems like this whole #if mess should be sorted out.
  5. in src/util/fs_helpers.cpp:207 in 9982d525c5
    199@@ -200,10 +200,13 @@ void AllocateFileRange(FILE* file, unsigned int offset, unsigned int length)
    200     }
    201     ftruncate(fileno(file), static_cast<off_t>(offset) + length);
    202 #else
    203+    off_t nEndPos = (off_t)offset + length;
    204 #if defined(HAVE_POSIX_FALLOCATE)
    205     // Version using posix_fallocate
    206-    off_t nEndPos = (off_t)offset + length;
    207     if (0 == posix_fallocate(fileno(file), 0, nEndPos)) return;
    208+#elif defined(__OpenBSD__)
    


    luke-jr commented at 9:20 pm on June 6, 2025:
    ftruncate isn’t OpenBSD-specific. We should just check its availability and use it on platforms that support it (after preferred methods are ruled out)
  6. luke-jr changes_requested

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-06-15 06:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me