From f88056f54a038501beeda6ecb69a3cf31f271cb0 Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Sat, 27 Apr 2024 23:44:49 +0100 Subject: [PATCH] one step further towards freebsd support. (#109) file descriptor deallocation is supported on freebsd 14 and onwards. --- src/meshable_arena.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/meshable_arena.cc b/src/meshable_arena.cc index 76e3873..5022681 100644 --- a/src/meshable_arena.cc +++ b/src/meshable_arena.cc @@ -486,11 +486,15 @@ void MeshableArena::freePhys(void *ptr, size_t sz) { const off_t off = reinterpret_cast(ptr) - reinterpret_cast(_arenaBegin); #ifdef __FreeBSD__ - // No viable solution at the moment but FreeBSD 14 (circa 2023) - // will have implemented the fallocate codepath just like linux - // since it s implemented in the kernel/ZFS side, the performance - // should be good enough -#warning "space deallocation unsupported on this platform" +#if __FreeBSD_version >= 1400000 + struct spacectl_range range = { + off, static_cast(sz) + }; + int result = fspacectl(_fd, SPACECTL_DEALLOC, &range, 0, NULL); + d_assert_msg(result == 0, "fspacectl(fd %d): %d errno %d (%s)\n", _fd, result, errno, strerror(errno)); +#else +#warning "space deallocation unsupported on FreeBSD < 14" +#endif #else #ifndef __APPLE__ int result = fallocate(_fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, off, sz);