diff --git a/.github/workflows/all.yml b/.github/workflows/all.yml index 930eee13..099f3756 100644 --- a/.github/workflows/all.yml +++ b/.github/workflows/all.yml @@ -17,11 +17,8 @@ jobs: strategy: matrix: platform: [ubuntu, alpine, fedora] - exclude: - # Fedora is not currently building lean. - - platform: fedora fail-fast: false uses: ./.github/workflows/platform.yml name: ${{ matrix.platform }} with: - platform: ${{ matrix.platform }} \ No newline at end of file + platform: ${{ matrix.platform }} diff --git a/.gitignore b/.gitignore index f16f8006..f623cc7e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +archives/ extern/ out/ bench/doc/ diff --git a/Dockerfile b/Dockerfile index fe54d991..3c86bc89 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,36 @@ ARG platform=ubuntu FROM ubuntu:24.04 AS ubuntu - +RUN apt-get update +RUN apt-get install -y --no-install-recommends build-essential git gpg \ + g++ clang lld llvm-dev unzip dos2unix linuxinfo bc libgmp-dev wget \ + cmake python3 ruby ninja-build libtool autoconf sed ghostscript \ + time curl automake libatomic1 libgflags-dev libsnappy-dev \ + zlib1g-dev libbz2-dev liblz4-dev libzstd-dev libreadline-dev \ + pkg-config gawk util-linux +# Install bazel +RUN apt-get install -y --no-install-recommends apt-transport-https curl gnupg +RUN curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg +RUN mv bazel.gpg /etc/apt/trusted.gpg.d/bazel.gpg +RUN echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" > /etc/apt/sources.list.d/bazel.list +RUN apt-get update && apt-get install bazel FROM fedora:latest AS fedora - +RUN dnf -y --quiet --nodocs install gcc-c++ clang lld llvm-devel unzip \ + dos2unix bc gmp-devel wget gawk cmake python3 ruby ninja-build libtool \ + autoconf git patch time sed ghostscript libatomic libstdc++ which \ + gflags-devel xz readline-devel snappy-devel +RUN dnf -y --quiet copr enable ohadm/bazel +RUN dnf -y --quiet --nodocs install bazel8 FROM alpine:latest AS alpine +RUN echo "@testing http://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories +RUN apk update RUN apk add --no-cache bash - +RUN apk add -q clang lld unzip dos2unix bc gmp-dev wget cmake python3 \ + automake gawk samurai libtool git build-base linux-headers autoconf \ + util-linux sed ghostscript libatomic gflags-dev readline-dev snappy-dev +RUN apk add -q bazel@testing FROM ${platform} AS bench-env @@ -17,17 +39,13 @@ RUN mkdir -p /mimalloc-bench COPY . /mimalloc-bench WORKDIR /mimalloc-bench -# Install dependencies -RUN ./build-bench-env.sh packages - -# Build benchmarks -RUN ./build-bench-env.sh bench - -RUN ./build-bench-env.sh redis - -RUN ./build-bench-env.sh rocksdb -RUN ./build-bench-env.sh lean +RUN make benchmarks +RUN make redis +RUN make rocksdb +RUN make lean +RUN make lua +RUN make linux FROM bench-env AS benchmark @@ -37,8 +55,8 @@ ARG allocator=mi ARG benchs=cfrac ARG repeats=1 -RUN ./build-bench-env.sh $allocator +RUN make $allocator # Run benchmarks WORKDIR /mimalloc-bench/out/bench -RUN ../../bench.sh $allocator $benchs -r=$repeats \ No newline at end of file +RUN ../../bench.sh $allocator $benchs -r=$repeats diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..2a538c8d --- /dev/null +++ b/Makefile @@ -0,0 +1,305 @@ +SUDO=sudo +ifeq ($(shell whoami), root) +$(warning running as root, avoid doing this if possible.) +SUDO= +endif + +DARWIN=no +PROCS=$(shell nproc) +EXTSO=so +SHA256SUM=sha256sum +SHA256SUM_FLAGS=-c --status +ORIG= + +ifeq ($(shell uname), Darwin) +DARWIN=yes +PROCS=$(shell sysctl -n hw.physicalcpu) +EXTSO=dylib +SHA256SUM=shasum -a 256 +SHA256SUM_FLAGS=-c -s +export HOMEBREW_NO_EMOJI=1 +ORIG=_orig +endif + +ifneq ($(shell grep -e 'ID=alpine' /etc/os-release),) +SHA256SUM_FLAGS=-c -s +endif + +BENCHMARKS_EXTERN=lean linux lua redis rocksdb +ALLOCS = dh ff fg gd hd hm iso je lf lp lt mesh mi mi2 mng nomesh rp sc scudo sg sm sn tbb tc tcg yal +PDFDOC=extern/large.pdf + +######################################################################## +# Environment flags for the individual make processes, may just be the # +# respective target name. # +######################################################################## + +fg_ENV=SSE2RNG=1 +iso_ENV=library +mesh_ENV=build +lf_ENV=liblite-malloc-shared.so +lt_ENV=-C gnu.make.lib +hd_ENV=-C src +redis_ENV=USE_JEMALLOC=no MALLOC=libc BUILD_TLS=no -C src +rocksdb_ENV=DISABLE_WARNING_AS_ERROR=1 DISABLE_JEMALLOC=1 ROCKSDB_DISABLE_TCMALLOC=1 db_bench + +# TODO: Mac seems to report 'arm64' here +ifeq ($(shell uname -m), aarch64) +ALLOCS := $(filter-out fg lt mesh nomesh sc sm, $(ALLOCS)) +endif + +all: allocs benchmarks_all +allocs: $(ALLOCS) +benchmarks_all: benchmarks $(BENCHMARKS_EXTERN) + +# TODO: Mac seems to report 'arm64' here +ifeq ($(shell uname -m), aarch64) +# gd uses SSE on x86, but ARC4 on ARM - and arc4 needs a fix +gd_ENV := ARC4RNG=1 +extern/gd/.built: extern/gd/.unpacked + sed -i_orig 's/getentropy(/_getentropy(/g' $(@D)/rng/arc4random.{c,h} + make -C $(@D) $(gd_ENV) -j$(PROCS) + touch $@ +endif + +.PHONY: all allocs benchmarks benchmarks_all benchmarks_big + +benchmarks: bench/CMakeLists.txt bench/shbench/sh6bench-new.c bench/shbench/sh8bench-new.c $(PDFDOC) + cmake -B out/bench -S bench + cmake --build out/bench -j $(PROCS) + +PDF_URL=https://raw.githubusercontent.com/geekaaron/Resources/master/resources/Writing_a_Simple_Operating_System--from_Scratch.pdf +$(PDFDOC): + mkdir -p extern + wget --no-verbose -O $(PDFDOC) $(PDF_URL) + +bench/shbench/sh6bench-new.c: bench/shbench/sh6bench.patch bench/shbench/sh6bench.c + dos2unix $< + patch -p1 -o $@ $(filter-out $<, $^) $< + +bench/shbench/sh8bench-new.c: bench/shbench/sh8bench.patch bench/shbench/SH8BENCH.C + dos2unix $< + patch -p1 -o $@ $(filter-out $<, $^) $< + +bench/shbench/sh6bench.c: bench/shbench/bench.zip + cd $(@D) && unzip -o $( make +sc_ENV=BUILDTYPE=Release +extern/sc/.built: extern/sc/Makefile + make -C $(@D) $(sc_ENV) -j$(PROCS) + touch $@ + +extern/sc/Makefile: extern/sc/build/gyp/gyp + cd $(@D) && build/gyp/gyp --depth=. scalloc.gyp + +extern/sc/build/gyp/gyp: extern/sc/.unpacked + cd extern/sc && tools/make_deps.sh + +#scudo: partial checkout, native clang, in a sub-directory +extern/scudo/.unpacked: + git clone --depth 1 --single-branch -b $(scudo_VERSION) --sparse --filter=blob:none $(scudo_URL) $(@D) + cd $(@D) && git sparse-checkout add compiler-rt/lib/scudo/standalone + touch $@ + +extern/scudo/.built: extern/scudo/.unpacked + cd $(@D)/compiler-rt/lib/scudo/standalone && clang++ -flto -fuse-ld=lld -fPIC -fno-exceptions $(CXXFLAGS) -fno-rtti -fvisibility=internal -O3 -I include -shared -o libscudo.$(EXTSO) *.cpp + touch $@ + +#sm: make, but a fix before +extern/sm/.built: extern/sm/.unpacked + sed -i "s/-Werror//" $(@D)/Makefile.include + make -C $(@D)/release -j$(PROCS) ../release/lib/libsupermalloc.so + touch $@ + +#sn: cmake+ninja, builds in sn/release +extern/sn/.built: extern/sn/release/build.ninja + cd $(@D)/release && ninja libsnmallocshim.$(EXTSO) libsnmallocshim-checks.$(EXTSO) + touch $@ + +extern/sn/release/build.ninja: extern/sn/.unpacked + env CXX=clang++ cmake -S $(@D)/.. -B $(@D) -G Ninja -DCMAKE_BUILD_TYPE=Release + +#tbb: cmake to configure +extern/tbb/.built: extern/tbb/.configured + make -C $(@D) -j$(PROCS) + touch $@ + +extern/tbb/.configured: extern/tbb/.unpacked + cd $(@D) && cmake -DCMAKE_BUILD_TYPE=Release -DTBB_BUILD=OFF -DTBB_TEST=OFF -DTBB_OUTPUT_DIR_BASE=bench -DCMAKE_POLICY_VERSION_MINIMUM=3.5 . + touch $@ + +#tc: autogen+configure +extern/tc/.built: extern/tc/Makefile + make -C $(@D) -j $(PROCS) + touch $@ + +extern/tc/Makefile: extern/tc/configure + cd $(@D) && CXXFLAGS="$(CXXFLAGS) -w -DNDEBUG -O2" ./configure --enable-minimal --disable-debugalloc + +extern/tc/configure: extern/tc/.unpacked + cd $(@D) && ./autogen.sh + +#tcg: bazel +extern/tcg/.built: extern/tcg/.unpacked + cd $(@D) && bazel build -c opt tcmalloc + touch $@ + +#yal: custom shell script +extern/yal/.built: extern/yal/.unpacked + cd $(@D) && ./build.sh -V + touch $@ + +######################################################################## +# benchmarks residing in ./extern # +######################################################################## +# lean: cmake, additional mathlib setup +extern/lean/.built: extern/lean/.unpacked + mkdir -p $(@D)/out/release + env CC=gcc CXX="g++" cmake -S $(@D)/src -B $(@D)/out/release -DCUSTOM_ALLOCATORS=OFF -DLEAN_EXTRA_CXX_FLAGS="-w" -DCMAKE_POLICY_VERSION_MINIMUM=3.5 + make -C $(@D)/out/release -j$(PROCS) bin_lean + mkdir -p extern/mathlib + cp -u $(@D)/leanpkg/leanpkg.toml extern/mathlib + touch $@ + +# lua only needs to be fetched, not more. +extern/lua/.built: extern/lua/.unpacked + touch $@ + +# linux only needs to be fetched, not more. +extern/linux/.built: extern/linux/.unpacked + touch $@ + +# rocksdb: needs patching +extern/rocksdb/.built: extern/rocksdb/.patched + make -C $(@D) $(rocksdb_ENV) -j$(PROCS) + touch $@ + +extern/rocksdb/.patched: extern/rocksdb/.unpacked + patch -d $(@D) -p1 -N -r- < patches/rocksdb_build.patch + touch $@ diff --git a/README.md b/README.md index efce48f8..c5c34b58 100644 --- a/README.md +++ b/README.md @@ -10,15 +10,8 @@ Collection of various benchmarks from the academic literature, together with automated scripts to pull specific versions of benchmark programs and allocators from Github and build them. -Due to the large variance in programs and allocators, the suite is currently -only developed for Unix-like systems, and specifically Ubuntu with `apt-get`, Fedora with `dnf`, -and macOS (for a limited set of allocators and benchmarks). The only system-installed allocator used is glibc's implementation that ships as part of Linux's libc. -All other allocators are downloaded and built as part of `build-bench-env.sh` -- -if you are looking to run these benchmarks on a different Linux distribution look at -the `setup_packages` function to see the packages required to build the full set of -allocators. - +All other allocators are downloaded and built with `make`. It is quite easy to add new benchmarks and allocator implementations -- please do so!. @@ -27,19 +20,77 @@ Enjoy, Daan - Note that all the code in the `bench` directory is not part of _mimalloc-bench_ as such, and all programs in the `bench` directory are governed under their own specific licenses and copyrights as detailed in their `README.md` (or `license.txt`) files. They are just included here for convenience. +# Dependencies +Some of the allocators and benchmarks need packages installed on the +system to be built and/or run. See the following collection for your +distribution: +
+ Ubuntu/Debian + +```bash +sudo apt-get install --no-install-recommends build-essential git gpg \ + g++ clang lld llvm-dev unzip dos2unix linuxinfo bc libgmp-dev wget \ + cmake python3 ruby ninja-build libtool autoconf sed ghostscript \ + time curl automake libatomic1 libgflags-dev libsnappy-dev \ + zlib1g-dev libbz2-dev liblz4-dev libzstd-dev libreadline-dev \ + pkg-config gawk util-linux bazel-bootstrap +``` +
+ +
+ Fedora + +```bash +sudo dnf --nodocs gcc-c++ clang lld llvm-devel unzip dos2unix bc \ + gmp-devel wget gawk cmake python3 ruby ninja-build libtool autoconf \ + git patch time sed ghostscript libatomic libstdc++ which gflags-devel \ + xz readline-devel snappy-devel dnf-plugins-core +sudo dnf copr -y enable ohadm/bazel +sudo dnf --nodocs install bazel8 +``` +
+ +
+ Alpine + +```bash +sudo apk add clang lld unzip dos2unix bc gmp-dev wget cmake python3 \ + automake gawk samurai libtool git build-base linux-headers autoconf \ + util-linux sed ghostscript libatomic gflags-dev readline-dev snappy-dev +echo "@testing http://nl.alpinelinux.org/alpine/edge/testing" | sudo tee -a /etc/apk/repositories +sudo apk add -q bazel@testing +``` +
+ +
+ ArchLinux + +```bash +sudo pacman -S dos2unix wget cmake ninja automake libtool time gmp sed \ + ghostscript bazelisk gflags snappy python-six +``` +
+ +
+ Mac OS + +```bash +brew install dos2unix wget cmake ninja automake libtool gnu-time gmp \ + mpir gnu-sed ghostscript bazelisk gflags snappy +``` +
# Benchmarking -The `build-bench-env.sh` script with the `all` argument will automatically pull -all needed benchmarks and allocators and build them in the `extern` directory: +`make all` will automatically pull all needed benchmarks and allocators +and build them in the `extern` directory: ``` -~/dev/mimalloc-bench> ./build-bench-env.sh all +~/dev/mimalloc-bench> make all ``` It starts installing packages and you will need to enter the sudo password. All other programs are build in the `mimalloc-bench/extern` directory. diff --git a/VERSIONS b/VERSIONS new file mode 100644 index 00000000..a7af451b --- /dev/null +++ b/VERSIONS @@ -0,0 +1,31 @@ +dh: master, master, https://github.com/emeryberger/DieHard +ff: master, master, https://github.com/bwickman97/ffmalloc +fg: master, master, https://github.com/UTSASRG/FreeGuard +gd: master, master, https://github.com/UTSASRG/Guarder +hd: 6577c22b, 6577c22, https://github.com/emeryberger/Hoard +hm: 11, 995ce07, https://github.com/GrapheneOS/hardened_malloc +iso: 1.2.5, 2670d5f, https://github.com/struct/isoalloc +je: 5.3.0, 54eaed1d, https://github.com/jemalloc/jemalloc +lean: 21d264a66d53b0a910178ae7d9529cb5886a39b6, 21d264a66, https://github.com/leanprover-community/lean +lf: master, master, https://github.com/Begun/lockfree-malloc +linux: 6.6.105, fe9731e1, https://github.com/torvalds/linux +lp: main, main, https://github.com/WebKit/WebKit +lt: master, master, https://github.com/r-lyeh-archived/ltalloc +lua: v5.4.7, 1ab3208a, https://github.com/lua/lua +mesh: master, master, https://github.com/plasma-umass/mesh +mi2: v2.1.2, 43ce4bd7, https://github.com/microsoft/mimalloc +mi: v1.8.2, b66e3214, https://github.com/microsoft/mimalloc +mng: master, master, https://github.com/richfelker/mallocng-draft +pa: main, main, https://github.com/1c3t3a/partition_alloc_builder +redis: 6.2.7, e6f6709, https://github.com/redis/redis +rocksdb: 8.1.1, 6a43615, https://github.com/facebook/rocksdb +rp: 1.4.5, e4393ff, https://github.com/mjansson/rpmalloc +sc: master, master, https://github.com/cksystemsgroup/scalloc +scudo: main, main, https://github.com/llvm/llvm-project +sg: master, master, https://github.com/ssrg-vt/SlimGuard +sm: master, master, https://github.com/kuszmaul/SuperMalloc +sn: 0.7.1, 32495fd, https://github.com/Microsoft/snmalloc +tbb: v2021.9.0, a00cc3b8, https://github.com/oneapi-src/oneTBB +tcg: 98fd24303c7b5ef5e30da625f11fb623a5e038b6, 98fd2430, https://github.com/google/tcmalloc +tc: gperftools-2.16.90, 83edb60, https://github.com/gperftools/gperftools +yal: main, main, https://github.com/jorisgeer/yalloc diff --git a/bench.sh b/bench.sh index c03fe2de..19c0a054 100755 --- a/bench.sh +++ b/bench.sh @@ -24,14 +24,6 @@ tests_run="" tests_exclude="" readonly tests_exclude_macos="sh6bench sh8bench redis" -# -------------------------------------------------------------------- -# benchmark versions -# -------------------------------------------------------------------- - -readonly version_redis=6.2.7 -readonly version_rocksdb=8.1.1 -readonly version_linux=6.5.1 - # -------------------------------------------------------------------- # Environment # -------------------------------------------------------------------- @@ -98,7 +90,7 @@ readonly lib_tbb="$localdevdir/tbb/bench_release/libtbbmalloc_proxy$extso" readonly lib_tbb_dir="$(dirname $lib_tbb)" -alloc_lib_add "dh" "$localdevdir/dh/src/build/libdieharder$extso" +alloc_lib_add "dh" "$localdevdir/dh/build/libdieharder$extso" alloc_lib_add "ff" "$localdevdir/ff/libffmallocnpmt$extso" alloc_lib_add "fg" "$localdevdir/fg/libfreeguard$extso" alloc_lib_add "gd" "$localdevdir/gd/libguarder$extso" @@ -110,9 +102,9 @@ alloc_lib_add "je" "$localdevdir/je/lib/libjemalloc$extso" alloc_lib_add "lf" "$localdevdir/lf/liblite-malloc-shared$extso" alloc_lib_add "lp" "$localdevdir/lp/Source/bmalloc/libpas/build-cmake-default/Release/libpas_lib$extso" alloc_lib_add "lt" "$localdevdir/lt/gnu.make.lib/libltalloc$extso" -alloc_lib_add "mesh" "$localdevdir/mesh/build/lib/libmesh$extso" +alloc_lib_add "mesh" "$localdevdir/mesh/bazel-bin/src/libmesh$extso" alloc_lib_add "mng" "$localdevdir/mng/libmallocng$extso" -alloc_lib_add "nomesh" "$localdevdir/nomesh/build/lib/libmesh$extso" +alloc_lib_add "nomesh" "$localdevdir/nomesh/bazel-bin/src/libmesh$extso" alloc_lib_add "pa" "$localdevdir/pa/partition_alloc_builder/out/Default/libpalib$extso" alloc_lib_add "rp" "$lib_rp" alloc_lib_add "sc" "$localdevdir/sc/out/Release/lib.target/libscalloc$extso" @@ -163,10 +155,10 @@ fi readonly luadir="$localdevdir/lua" readonly leandir="$localdevdir/lean" readonly leanmldir="$leandir/../mathlib" -readonly redis_dir="$localdevdir/redis-$version_redis/src" +readonly redis_dir="$localdevdir/redis/src" readonly pdfdoc="$localdevdir/large.pdf" -readonly rocksdb_dir="$localdevdir/rocksdb-$version_rocksdb" -readonly linux_dir="$localdevdir/linux-$version_linux" +readonly rocksdb_dir="$localdevdir/rocksdb" +readonly linux_dir="$localdevdir/linux" readonly spec_dir="$localdevdir/../../spec2017" readonly spec_base="base" diff --git a/build-bench-env.sh b/build-bench-env.sh index 4cd9fed1..159174e1 100755 --- a/build-bench-env.sh +++ b/build-bench-env.sh @@ -463,7 +463,9 @@ if test "$setup_packages" = "1"; then brewinstall "dos2unix wget cmake ninja automake libtool gnu-time gmp mpir gnu-sed \ ghostscript bazelisk gflags snappy" elif grep -q 'Arch Linux' /etc/os-release; then - sudo pacman -S dos2unix wget cmake ninja automake libtool time gmp sed ghostscript bazelisk gflags snappy + sudo pacman -S dos2unix wget cmake ninja automake libtool time gmp sed ghostscript \ + bazelisk gflags snappy python-six + # python-six is needed for gyp which is used by sc fi fi