Skip to content

Commit 0b70ad9

Browse files
mjp41achamayou
andauthored
Benchmarking automatically (#795)
Co-authored-by: Amaury Chamayou <amaury@xargs.fr>
1 parent 3385660 commit 0b70ad9

File tree

3 files changed

+177
-53
lines changed

3 files changed

+177
-53
lines changed

.github/workflows/benchmark.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: snmalloc Benchmarking CI
2+
3+
# The following should ensure that the workflow only runs a single set of actions
4+
# for each PR. But it will not apply this to pushes to the main branch.
5+
concurrency:
6+
group: benchmarking${{ github.ref }}
7+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
8+
9+
# Controls when the workflow will run
10+
on:
11+
schedule:
12+
- cron: "0 0 * * 1" # Runs every Monday at midnight UTC
13+
# Triggers the workflow on push or pull request events but only for the master branch
14+
push:
15+
branches: [ main ]
16+
pull_request:
17+
branches: [ main ]
18+
19+
# Allows you to run this workflow manually from the Actions tab
20+
workflow_dispatch:
21+
22+
jobs:
23+
benchmark:
24+
runs-on: [self-hosted, 1ES.Pool=snmalloc-perf]
25+
26+
steps:
27+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
28+
- name: Checkout
29+
uses: actions/checkout@v3
30+
31+
# Setup docker buildx
32+
- name: Setup Docker Buildx
33+
uses: docker/setup-buildx-action@v2
34+
35+
- name: Build and run benchmarks in Docker
36+
id: docker_build
37+
uses: docker/build-push-action@v4
38+
with:
39+
context: .
40+
file: benchmark/Dockerfile
41+
push: false
42+
load: true
43+
tags: snmalloc-bench
44+
build-args: |
45+
benchs=allt
46+
repeats=5
47+
cache-from: type=gha
48+
cache-to: type=gha,mode=max
49+
50+
# Extracts the benchmark results from the Docker container
51+
- name: Extract Benchmark Results
52+
run: |
53+
docker cp `docker run -d ${{ steps.docker_build.outputs.imageid }}`:/bencher.dev.sn.json .
54+
55+
# Uploads the benchmark results as an artifact
56+
- name: Upload Benchmark Results
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: benchmark-results
60+
path: bencher.dev.sn.json
61+
62+
# Upload to graphing service
63+
- uses: bencherdev/bencher@main
64+
- name: Upload benchmark results to Bencher
65+
run: |
66+
bencher run \
67+
--project snmalloc \
68+
--token '${{ secrets.BENCHER_DEV_API_TOKEN }}' \
69+
--branch main \
70+
--adapter json \
71+
--err \
72+
--file bencher.dev.sn.json

benchmark/Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
FROM ubuntu:24.04
2+
3+
# Pull mimalloc-bench
4+
RUN apt-get update && apt-get install -y --no-install-recommends git gpg ca-certificates python3-numpy
5+
RUN git clone https://github.com/daanx/mimalloc-bench &&\
6+
cd mimalloc-bench && \
7+
git reset --hard a4ce904286365c7adfba54f0eea3a2df3fc95bd1
8+
9+
WORKDIR /mimalloc-bench
10+
# Install dependencies
11+
RUN ./build-bench-env.sh packages
12+
13+
# Tidy up apt cache
14+
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
15+
16+
# Build benchmarks
17+
RUN ./build-bench-env.sh bench
18+
19+
RUN ./build-bench-env.sh redis
20+
21+
RUN ./build-bench-env.sh rocksdb \
22+
&& find /mimalloc-bench/extern/rocksdb-8.1.1 -name "*.o" -delete
23+
24+
RUN ./build-bench-env.sh lean \
25+
&& find /mimalloc-bench/extern/lean -name "*.o" -delete
26+
27+
RUN echo "sn /snmalloc/build/libsnmallocshim.so" > /allocs.txt
28+
29+
# Build allocator
30+
RUN mkdir -p /snmalloc
31+
COPY . /snmalloc
32+
33+
RUN mkdir -p /snmalloc/build
34+
WORKDIR /snmalloc/build
35+
RUN cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ..
36+
RUN ninja libsnmallocshim.so
37+
38+
# Run benchmarks
39+
ARG benchs=allt
40+
ARG repeats=1
41+
WORKDIR /mimalloc-bench/out/bench
42+
RUN ../../bench.sh --external=/allocs.txt $benchs -r=$repeats
43+
44+
WORKDIR /
45+
RUN python3 /mimalloc-bench/scripts/bencher.dev.py /mimalloc-bench/out/bench/benchres.csv

src/test/func/jemalloc/jemalloc.cc

Lines changed: 60 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,71 @@
1-
#include <functional>
2-
#include <limits.h>
3-
#include <stdio.h>
4-
#include <test/helpers.h>
5-
#include <test/setup.h>
1+
#if defined(SNMALLOC_ENABLE_GWP_ASAN_INTEGRATION)
2+
int main()
3+
{
4+
return 0;
5+
}
6+
#else
7+
# include <functional>
8+
# include <limits.h>
9+
# include <stdio.h>
10+
# include <test/helpers.h>
11+
# include <test/setup.h>
612

7-
#define SNMALLOC_NAME_MANGLE(a) our_##a
8-
#undef SNMALLOC_NO_REALLOCARRAY
9-
#undef SNMALLOC_NO_REALLOCARR
10-
#define SNMALLOC_BOOTSTRAP_ALLOCATOR
11-
#define SNMALLOC_JEMALLOC3_EXPERIMENTAL
12-
#define SNMALLOC_JEMALLOC_NONSTANDARD
13-
#include <snmalloc/override/jemalloc_compat.cc>
14-
#include <snmalloc/override/malloc.cc>
13+
# define SNMALLOC_NAME_MANGLE(a) our_##a
14+
# undef SNMALLOC_NO_REALLOCARRAY
15+
# undef SNMALLOC_NO_REALLOCARR
16+
# define SNMALLOC_BOOTSTRAP_ALLOCATOR
17+
# define SNMALLOC_JEMALLOC3_EXPERIMENTAL
18+
# define SNMALLOC_JEMALLOC_NONSTANDARD
19+
# include <snmalloc/override/jemalloc_compat.cc>
20+
# include <snmalloc/override/malloc.cc>
1521

16-
#if __has_include(<malloc_np.h>)
17-
# include <malloc_np.h>
18-
#endif
22+
# if __has_include(<malloc_np.h>)
23+
# include <malloc_np.h>
24+
# endif
1925

20-
#ifdef __FreeBSD__
26+
# ifdef __FreeBSD__
2127
/**
2228
* Enable testing against the versions that we get from libc or elsewhere.
2329
* Enabled by default on FreeBSD where all of the jemalloc functions are
2430
* exported from libc.
2531
*/
26-
# define TEST_JEMALLOC_MALLOCX
27-
#endif
32+
# define TEST_JEMALLOC_MALLOCX
33+
# endif
2834

29-
#define OUR_MALLOCX_LG_ALIGN(la) (static_cast<int>(la))
30-
#define OUR_MALLOCX_ZERO (one_at_bit<int>(6))
35+
# define OUR_MALLOCX_LG_ALIGN(la) (static_cast<int>(la))
36+
# define OUR_MALLOCX_ZERO (one_at_bit<int>(6))
3137

32-
#define OUR_ALLOCM_NO_MOVE (one_at_bit<int>(7))
38+
# define OUR_ALLOCM_NO_MOVE (one_at_bit<int>(7))
3339

34-
#define OUR_ALLOCM_SUCCESS 0
35-
#define OUR_ALLOCM_ERR_OOM 1
36-
#define OUR_ALLOCM_ERR_NOT_MOVED 2
40+
# define OUR_ALLOCM_SUCCESS 0
41+
# define OUR_ALLOCM_ERR_OOM 1
42+
# define OUR_ALLOCM_ERR_NOT_MOVED 2
3743

38-
#ifndef MALLOCX_LG_ALIGN
39-
# define MALLOCX_LG_ALIGN(la) OUR_MALLOCX_LG_ALIGN(la)
40-
#endif
41-
#ifndef MALLOCX_ZERO
42-
# define MALLOCX_ZERO OUR_MALLOCX_ZERO
43-
#endif
44+
# ifndef MALLOCX_LG_ALIGN
45+
# define MALLOCX_LG_ALIGN(la) OUR_MALLOCX_LG_ALIGN(la)
46+
# endif
47+
# ifndef MALLOCX_ZERO
48+
# define MALLOCX_ZERO OUR_MALLOCX_ZERO
49+
# endif
4450

45-
#ifndef ALLOCM_LG_ALIGN
46-
# define ALLOCM_LG_ALIGN(la) OUR_MALLOCX_LG_ALIGN(la)
47-
#endif
48-
#ifndef ALLOCM_ZERO
49-
# define ALLOCM_ZERO OUR_MALLOCX_ZERO
50-
#endif
51-
#ifndef ALLOCM_NO_MOVE
52-
# define ALLOCM_NO_MOVE OUR_ALLOCM_NO_MOVE
53-
#endif
54-
#ifndef ALLOCM_SUCCESS
55-
# define ALLOCM_SUCCESS OUR_ALLOCM_SUCCESS
56-
#endif
57-
#ifndef ALLOCM_ERR_OOM
58-
# define ALLOCM_ERR_OOM OUR_ALLOCM_ERR_OOM
59-
#endif
60-
#ifndef ALLOCM_ERR_NOT_MOVED
61-
# define ALLOCM_ERR_NOT_MOVED OUR_ALLOCM_ERR_NOT_MOVED
62-
#endif
51+
# ifndef ALLOCM_LG_ALIGN
52+
# define ALLOCM_LG_ALIGN(la) OUR_MALLOCX_LG_ALIGN(la)
53+
# endif
54+
# ifndef ALLOCM_ZERO
55+
# define ALLOCM_ZERO OUR_MALLOCX_ZERO
56+
# endif
57+
# ifndef ALLOCM_NO_MOVE
58+
# define ALLOCM_NO_MOVE OUR_ALLOCM_NO_MOVE
59+
# endif
60+
# ifndef ALLOCM_SUCCESS
61+
# define ALLOCM_SUCCESS OUR_ALLOCM_SUCCESS
62+
# endif
63+
# ifndef ALLOCM_ERR_OOM
64+
# define ALLOCM_ERR_OOM OUR_ALLOCM_ERR_OOM
65+
# endif
66+
# ifndef ALLOCM_ERR_NOT_MOVED
67+
# define ALLOCM_ERR_NOT_MOVED OUR_ALLOCM_ERR_NOT_MOVED
68+
# endif
6369

6470
using namespace snmalloc;
6571
using namespace snmalloc::bits;
@@ -335,21 +341,22 @@ int main()
335341
our_dallocm,
336342
our_nallocm>();
337343

338-
#ifndef __PIC__
344+
# ifndef __PIC__
339345
void* bootstrap = __je_bootstrap_malloc(42);
340346
if (bootstrap == nullptr)
341347
{
342348
printf("Failed to allocate from bootstrap malloc\n");
343349
}
344350
__je_bootstrap_free(bootstrap);
345-
#endif
351+
# endif
346352

347353
// These tests are for jemalloc compatibility and so should work with
348354
// jemalloc's implementation of these functions. If TEST_JEMALLOC is
349355
// defined then we try
350-
#ifdef TEST_JEMALLOC_MALLOCX
356+
# ifdef TEST_JEMALLOC_MALLOCX
351357
test_size<mallocx, dallocx, sallocx, nallocx>();
352358
test_zeroing<mallocx, dallocx, rallocx>();
353359
test_xallocx<mallocx, dallocx, xallocx>();
354-
#endif
360+
# endif
355361
}
362+
#endif // SNMALLOC_ENABLE_GWP_ASAN_INTEGRATION

0 commit comments

Comments
 (0)