aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--allocators/BA_allocators.py63
-rw-r--r--allocators/glibc_2.28_no_passive_falsesharing.patch22
-rw-r--r--allocators/hoard_make.patch16
-rw-r--r--allocators/no_falsesharing.py44
-rw-r--r--allocators/tcmalloc_2.7_no_active_falsesharing.patch17
-rw-r--r--src/allocator.py150
6 files changed, 312 insertions, 0 deletions
diff --git a/allocators/BA_allocators.py b/allocators/BA_allocators.py
new file mode 100644
index 0000000..accd1a2
--- /dev/null
+++ b/allocators/BA_allocators.py
@@ -0,0 +1,63 @@
+import os
+import subprocess
+
+from src.allocator import library_path
+from src.allocator import Allocator as Alloc
+from src.allocator import Allocator_Patched as Alloc_Patched
+from src.allocator import Allocator_Sources as Alloc_Src
+from src.allocator import builddir
+
+optimisation_flag = "-O2"
+
+glibc_src = Alloc_Src("glibc",
+ retrieve_cmds=["git clone git://sourceware.org/git/glibc.git"],
+ prepare_cmds=["git checkout release/2.28/master"])
+
+glibc = Alloc("glibc", sources=glibc_src,
+ build_cmds=["mkdir -p glibc-build",
+ "cd glibc-build; {srcdir}/configure --prefix={dir}",
+ "cd glibc-build; make",
+ "cd glibc-build; make install"],
+ cmd_prefix="{dir}/lib/ld-linux-x86-64.so.2 --library-path {dir}/lib:"+library_path,
+ color="C1")
+
+glibc_notc = Alloc("glibc-notc", sources=glibc_src,
+ build_cmds=["mkdir -p glibc-build",
+ "cd glibc-build; {srcdir}/configure --prefix={dir} --disable-experimental-malloc",
+ "cd glibc-build; make",
+ "cd glibc-build; make install"],
+ cmd_prefix="{dir}/lib/ld-linux-x86-64.so.2 --library-path {dir}/lib:"+library_path,
+ color="C2")
+
+tcmalloc = Alloc("tcmalloc",
+ sources=Alloc_Src("gperftools",
+ retrieve_cmds=["git clone https://github.com/gperftools/gperftools.git"],
+ prepare_cmds=["git checkout gperftools-2.7", "./autogen.sh"]),
+ LD_PRELOAD="{dir}/lib/libtcmalloc.so",
+ build_cmds=["cd {srcdir}; ./configure --prefix={dir} CXXFLAGS=" + optimisation_flag,
+ "cd {srcdir}; make install -j4"],
+ color="C3")
+
+jemalloc = Alloc("jemalloc",
+ sources=Alloc_Src("jemalloc",
+ retrieve_cmds=["git clone https://github.com/jemalloc/jemalloc.git"],
+ prepare_cmds=["git checkout 5.1.0", "./autogen.sh"]),
+ LD_PRELOAD="{dir}/lib/libjemalloc.so",
+ build_cmds=["cd {srcdir}; ./configure --prefix={dir} CFLAGS=" + optimisation_flag,
+ "mkdir {dir}"],
+ color="C4")
+
+hoard = Alloc_Patched("Hoard",
+ Alloc("Hoard", sources=Alloc_Src("Hoard",
+ retrieve_cmds=["git clone https://github.com/emeryberger/Hoard.git"]),
+ LD_PRELOAD="{srcdir}/src/libhoard.so",
+ build_cmds=["cd {srcdir}/src; make",
+ "mkdir {dir}"],
+ color="C5"),
+ ["allocators/hoard_make.patch"])
+
+
+
+allocators_to_build = [glibc, glibc_notc, tcmalloc, jemalloc, hoard]
+
+allocators = {a.name: a.build(verbose=verbose) for a in allocators_to_build}
diff --git a/allocators/glibc_2.28_no_passive_falsesharing.patch b/allocators/glibc_2.28_no_passive_falsesharing.patch
new file mode 100644
index 0000000..fcc695c
--- /dev/null
+++ b/allocators/glibc_2.28_no_passive_falsesharing.patch
@@ -0,0 +1,22 @@
+diff --git a/malloc/malloc.c b/malloc/malloc.c
+index 27cf6137c2..3aadaddd1d 100644
+--- a/malloc/malloc.c
++++ b/malloc/malloc.c
+@@ -4172,6 +4172,9 @@ _int_free (mstate av, mchunkptr p, int have_lock)
+
+ #if USE_TCACHE
+ {
++ /* Check if chunk is from our own arena. */
++ if (av == thread_arena)
++ {
+ size_t tc_idx = csize2tidx (size);
+ if (tcache != NULL && tc_idx < mp_.tcache_bins)
+ {
+@@ -4201,6 +4204,7 @@ _int_free (mstate av, mchunkptr p, int have_lock)
+ return;
+ }
+ }
++ }
+ }
+ #endif
+
diff --git a/allocators/hoard_make.patch b/allocators/hoard_make.patch
new file mode 100644
index 0000000..4848c57
--- /dev/null
+++ b/allocators/hoard_make.patch
@@ -0,0 +1,16 @@
+diff --git a/src/GNUmakefile b/src/GNUmakefile
+index 2b2958e..7fa433a 100644
+--- a/src/GNUmakefile
++++ b/src/GNUmakefile
+@@ -1,9 +1,9 @@
+ # Commands to compile Hoard for various targets.
+ # Run make (with no arguments) to see the complete target list.
+
+-CPPFLAGS = -std=c++14 -O3 -DNDEBUG -ffast-math -fno-builtin-malloc -Wall -Wextra -Wshadow -Wconversion -Wuninitialized
++CPPFLAGS = -std=c++14 -O2 -DNDEBUG -ffast-math -fno-builtin-malloc -Wall -Wextra -Wshadow -Wconversion -Wuninitialized
+ #CPPFLAGS = -std=c++14 -g -O0 -ffast-math -fno-builtin-malloc -Wall -Wextra -Wshadow -Wconversion -Wuninitialized
+-CXX = clang++
++CXX = g++
+
+ # Compute platform (OS and architecture) and build accordingly.
+
diff --git a/allocators/no_falsesharing.py b/allocators/no_falsesharing.py
new file mode 100644
index 0000000..880d4e8
--- /dev/null
+++ b/allocators/no_falsesharing.py
@@ -0,0 +1,44 @@
+import os
+import subprocess
+
+from src.allocator import library_path
+from src.allocator import Allocator as Alloc
+from src.allocator import Allocator_Patched as Alloc_Patched
+from src.allocator import Allocator_Sources as Alloc_Src
+from src.allocator import builddir
+
+optimisation_flag = "-O2"
+
+glibc_src = Alloc_Src("glibc",
+ retrieve_cmds=["git clone git://sourceware.org/git/glibc.git"],
+ prepare_cmds=["git checkout release/2.29/master"],
+ reset_cmds=["git stash"])
+
+glibc = Alloc("glibc", sources=glibc_src,
+ build_cmds=["mkdir -p glibc-build",
+ "cd glibc-build; {srcdir}/configure --prefix={dir}",
+ "cd glibc-build; make",
+ "cd glibc-build; make install"],
+ cmd_prefix="{dir}/lib/ld-linux-x86-64.so.2 --library-path {dir}/lib:"+library_path)
+
+glibc_nofs = Alloc_Patched("glibc_nofs", glibc,
+ ["allocators/glibc_2.28_no_passive_falsesharing.patch"])
+
+tcmalloc_src = Alloc_Src("gperftools",
+ ["git clone https://github.com/gperftools/gperftools.git"],
+ ["git checkout gperftools-2.7", "./autogen.sh"],
+ ["git stash"])
+
+tcmalloc = Alloc("tcmalloc", sources=tcmalloc_src,
+ LD_PRELOAD="{dir}/lib/libtcmalloc.so",
+ build_cmds=["cd {srcdir}; ./configure --prefix={dir} CXXFLAGS=" + optimisation_flag,
+ "cd {srcdir}; make install -j4"],
+ color="C3")
+
+tcmalloc_nofs = Alloc_Patched("tcmalloc_nofs", tcmalloc,
+ ["allocators/tcmalloc_2.7_no_active_falsesharing.patch"],
+ color="C4")
+
+allocators_to_build = [glibc, glibc_nofs, tcmalloc, tcmalloc_nofs]
+
+allocators = {a.name: a.build(verbose=verbose) for a in allocators_to_build}
diff --git a/allocators/tcmalloc_2.7_no_active_falsesharing.patch b/allocators/tcmalloc_2.7_no_active_falsesharing.patch
new file mode 100644
index 0000000..c14172d
--- /dev/null
+++ b/allocators/tcmalloc_2.7_no_active_falsesharing.patch
@@ -0,0 +1,17 @@
+diff --git a/src/thread_cache.cc b/src/thread_cache.cc
+index 6d2f832..2074f4a 100644
+--- a/src/thread_cache.cc
++++ b/src/thread_cache.cc
+@@ -120,7 +120,11 @@ void* ThreadCache::FetchFromCentralCache(uint32 cl, int32_t byte_size,
+ ASSERT(list->empty());
+ const int batch_size = Static::sizemap()->num_objects_to_move(cl);
+
+- const int num_to_move = min<int>(list->max_length(), batch_size);
++ int num_to_move = min<int>(list->max_length(), batch_size);
++ const int cache_line_parts = 64 / byte_size;
++ if (cache_line_parts > 0 && cache_line_parts > num_to_move)
++ num_to_move = cache_line_parts;
++
+ void *start, *end;
+ int fetch_count = Static::central_cache()[cl].RemoveRange(
+ &start, &end, num_to_move);
diff --git a/src/allocator.py b/src/allocator.py
new file mode 100644
index 0000000..a163b14
--- /dev/null
+++ b/src/allocator.py
@@ -0,0 +1,150 @@
+import copy
+import os
+import shutil
+import subprocess
+import sys
+
+library_path = ""
+for l in subprocess.run(["ldconfig", "-v"], stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ universal_newlines=True).stdout.splitlines():
+ if not l.startswith('\t'):
+ library_path += l
+
+builddir = os.path.join(os.getcwd(), "build", "allocators")
+srcdir = os.path.join(builddir, "src")
+
+if not os.path.isdir(srcdir):
+ os.makedirs(srcdir)
+
+
+class Allocator_Sources (object):
+ # indicate if this source was patched
+ available = False
+ clean = True
+
+ def __init__(self, name, retrieve_cmds=[], prepare_cmds=[], reset_cmds=[]):
+ self.name = name
+ self.dir = os.path.join(srcdir, self.name)
+ self.retrieve_cmds = retrieve_cmds
+ self.prepare_cmds = prepare_cmds
+ self.reset_cmds = reset_cmds
+
+ def run_cmds(self, function, verbose, cwd=srcdir):
+ print(function, self.name, "...")
+ cmds = getattr(self, function+"_cmds")
+ for cmd in cmds:
+ stdout = subprocess.PIPE if not verbose else None
+ stderr = subprocess.PIPE if not verbose else None
+ p = subprocess.run(cmd, shell=True, cwd=cwd, stderr=stderr,
+ stdout=stdout)
+
+ if p.returncode:
+ print(function, self.name, "failed with", p.returncode,
+ file=sys.stderr)
+ print(p.stderr, file=sys.stderr)
+ return False
+ return True
+
+ def prepare(self, verbose):
+ if not os.path.isdir(self.dir):
+ if (not self.run_cmds("retrieve", verbose) or
+ not self.run_cmds("prepare", verbose, cwd=self.dir)):
+
+ shutil.rmtree(self.dir, ignore_errors=True)
+ exit(1)
+
+ self.available = True
+ return True
+
+ def reset(self, verbose):
+ if not self.run_cmds("reset", verbose, cwd=self.dir):
+ exit(1)
+ self.clean = True
+
+ def patch(self, patches, verbose):
+ self.prepare(verbose)
+ stdout = subprocess.PIPE if not verbose else None
+ stderr = subprocess.PIPE
+ cwd = os.path.join(srcdir, self.name)
+
+ print("Patching", self.name, "...")
+ for patch in patches:
+ with open(patch, "rb") as f:
+ p = subprocess.run("patch -p1", shell=True, cwd=cwd, stderr=stderr,
+ stdout=stdout, input=f.read())
+
+ if p.returncode:
+ print("Patching of", self.name, "failed.", file=sys.stderr)
+ exit(1)
+
+
+class Allocator (object):
+ allowed_attributes = ["binary_suffix", "version", "sources", "build_cmds",
+ "LD_PRELOAD", "cmd_prefix", "color"]
+
+ def __init__(self, name, **kwargs):
+ self.name = name
+ self.dir = os.path.join(builddir, self.name)
+ # Update attributes
+ self.__dict__.update((k, v) for k, v in kwargs.items() if k in self.allowed_attributes)
+
+ # create all unset attributes
+ for attr in self.allowed_attributes:
+ if not hasattr(self, attr):
+ setattr(self, attr, None)
+
+ def build(self, verbose=False):
+ if not os.path.isdir(self.dir):
+ if self.sources:
+ if not self.sources.available:
+ self.sources.prepare(verbose)
+ if not self.sources.clean:
+ self.sources.reset(verbose)
+
+ if self.build_cmds:
+ print("Building", self.name, "...")
+ for cmd in self.build_cmds:
+ cmd = cmd.format(**{"dir": self.dir,
+ "srcdir": self.sources.dir})
+ stdout = subprocess.PIPE if not verbose else None
+ stderr = subprocess.PIPE
+ p = subprocess.run(cmd, cwd=builddir, shell=True,
+ stderr=stderr, stdout=stdout)
+ if p.returncode:
+ print(cmd)
+ print(p.stderr)
+ print("Building", self.name, "failed ...")
+ shutil.rmtree(self.dir, ignore_errors=True)
+ exit(1)
+
+ for attr in ["LD_PRELOAD", "cmd_prefix"]:
+ try:
+ value = getattr(self, attr)
+ setattr(self, attr, value.format(**{"dir": self.dir,
+ "srcdir": self.sources.dir}))
+ except AttributeError:
+ setattr(self, attr, "")
+
+ return {"cmd_prefix": self.cmd_prefix,
+ "binary_suffix": self.binary_suffix or "",
+ "LD_PRELOAD": self.LD_PRELOAD,
+ "color": self.color}
+
+
+class Allocator_Patched (object):
+ def __init__(self, name, alloc, patches, **kwargs):
+ self.name = name
+ self.patches = patches
+
+ self.alloc = copy.deepcopy(alloc)
+ self.alloc.name = self.name
+ self.alloc.dir = os.path.join(builddir, self.name)
+ self.alloc.__dict__.update((k, v) for k, v in kwargs.items() if k in self.alloc.allowed_attributes)
+
+ def build(self, verbose=False):
+
+ if not os.path.isdir(self.alloc.dir):
+ self.alloc.sources.patch(self.patches, verbose)
+
+ return self.alloc.build(verbose=verbose)