From 7f8e758031c69f8ea02ae107a2ce8f35881c96c2 Mon Sep 17 00:00:00 2001 From: Stephan Bauroth Date: Thu, 5 Nov 2026 13:40:07 +0000 Subject: [PATCH] rocksdb: use posix_memalign for cache shards on musl --- build-bench-env.sh | 5 +++++ patches/rocksdb_cacheline_alloc.patch | 11 +++++++++++ 2 files changed, 16 insertions(+) create mode 100644 patches/rocksdb_cacheline_alloc.patch diff --git a/build-bench-env.sh b/build-bench-env.sh index d4c4a7a..c4cb0ba 100755 --- a/build-bench-env.sh +++ b/build-bench-env.sh @@ -856,6 +856,11 @@ if test "$setup_rocksdb" = "1"; then fi cd "rocksdb-$version_rocksdb" + # musl defines neither _POSIX_C_SOURCE nor _XOPEN_SOURCE by default, so + # without this rocksdb allocates its cache shards with plain malloc + set +e + patch -p1 -N -r- < ../../patches/rocksdb_cacheline_alloc.patch + set -e DISABLE_WARNING_AS_ERROR=1 DISABLE_JEMALLOC=1 ROCKSDB_DISABLE_TCMALLOC=1 make db_bench -j $procs [ "$CI" ] && find . -name '*.o' -delete popd diff --git a/patches/rocksdb_cacheline_alloc.patch b/patches/rocksdb_cacheline_alloc.patch new file mode 100644 index 0000000..850fc3d --- /dev/null +++ b/patches/rocksdb_cacheline_alloc.patch @@ -0,0 +1,11 @@ +--- a/port/port_posix.cc ++++ b/port/port_posix.cc +@@ -228,7 +228,7 @@ + void* cacheline_aligned_alloc(size_t size) { + #if __GNUC__ < 5 && defined(__SANITIZE_ADDRESS__) + return malloc(size); +-#elif (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600 || defined(__APPLE__)) ++#elif (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600 || defined(__APPLE__) || defined(__linux__)) + void* m; + errno = posix_memalign(&m, CACHE_LINE_SIZE, size); + return errno ? nullptr : m;