aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2019-06-24 14:51:21 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2019-06-24 14:51:21 +0200
commit2d86e20f5a44aea66725686531463931f38aa2dc (patch)
treeb3e42e10e212aa61069775812cc821a2445a3b45
parent366c9e27b13e976ce26ec6a97c6796eb1cdca887 (diff)
downloadallocbench-2d86e20f5a44aea66725686531463931f38aa2dc.tar.gz
allocbench-2d86e20f5a44aea66725686531463931f38aa2dc.zip
rework allocator definitions #2
bench.py no evals only if argument to -a is file path. Otherwise it will check if "arg".py is found in src/allocators/ then it imports it. Collection definitions must export a iterable member called allocators. Allocator definitions must export a member named "arg".
-rwxr-xr-xbench.py47
-rw-r--r--src/allocators/BA_allocators.py24
-rw-r--r--src/allocators/all.py41
-rw-r--r--src/allocators/glibc.py21
-rw-r--r--src/allocators/glibcs.py37
-rw-r--r--src/allocators/hoard.py4
-rw-r--r--src/allocators/installed_allocators.py19
-rw-r--r--src/allocators/je_tc_super.py22
-rw-r--r--src/allocators/jemalloc.py6
-rw-r--r--src/allocators/no_falsesharing.py19
-rw-r--r--src/allocators/scalloc.py30
-rw-r--r--src/allocators/scalloc/scalloc_fix_log.patch35
-rw-r--r--src/allocators/supermalloc.py6
-rw-r--r--src/allocators/tcmalloc.py12
14 files changed, 167 insertions, 156 deletions
diff --git a/bench.py b/bench.py
index 1e8b8b1..e75fa01 100755
--- a/bench.py
+++ b/bench.py
@@ -18,13 +18,13 @@ parser = argparse.ArgumentParser(description="benchmark memory allocators")
parser.add_argument("-ds, --dont-save", action='store_true', dest="dont_save",
help="don't save benchmark results in RESULTDIR")
parser.add_argument("-l", "--load", help="load benchmark results from directory", type=str)
-parser.add_argument("-a", "--allocators", help="load allocator definitions from file", type=str)
parser.add_argument("--analyse", help="analyse benchmark behaviour using malt", action="store_true")
parser.add_argument("-r", "--runs", help="how often the benchmarks run", default=3, type=int)
parser.add_argument("-v", "--verbose", help="more output", action='count')
parser.add_argument("-vdebug", "--verbose-debug", help="debug output",
action='store_true', dest="verbose_debug")
parser.add_argument("-b", "--benchmarks", help="benchmarks to run", nargs='+')
+parser.add_argument("-a", "--allocators", help="allocators to test", type=str, nargs='+')
parser.add_argument("-ns", "--nosum", help="don't produce plots", action='store_true')
parser.add_argument("-rd", "--resultdir", help="directory where all results go", type=str)
parser.add_argument("--license", help="print license info and exit", action='store_true')
@@ -80,27 +80,44 @@ def main():
subprocess.run(make_cmd)
- # collect facts
+ # collect facts about benchmark environment
src.facter.collect_facts()
- # Default allocator definition file
- allocators_file = os.path.join("build", "allocators", "allocators.py")
-
- if args.allocators or os.path.isfile(allocators_file):
- allocators_file = args.allocators or allocators_file
- src.globalvars.allocators_file = allocators_file
-
- with open(allocators_file, "r") as f:
- print_status("Sourcing allocators definitions at", allocators_file,
- "...")
- g = {}
- exec(f.read(), g)
- src.globalvars.allocators = g["allocators"]
+ # allocators to benchmark
+ allocators = {}
+ # Default allocators definition file
+ default_allocators_file = "build/allocators/allocators.py"
+
+ if args.allocators is None and os.path.isfile(default_allocators_file):
+ allocators.append(default_allocators_file)
+
+ elif args.allocators is not None:
+ for name in args.allocators:
+ # file exists -> interpret as python file with a global field allocators
+ if os.path.isfile(name):
+ with open(name, "r") as f:
+ print_status("Sourcing allocators definitions at", name,
+ "...")
+ g = {}
+ exec(f.read(), g)
+ allocators.update(g["allocators"])
+ # file is one of our allocator definitions import it
+ elif os.path.isfile("src/allocators/" + name + ".py"):
+ module = importlib.import_module('src.allocators.' + name)
+ # name is collection
+ if hasattr(module, "allocators"):
+ for alloc in module.allocators:
+ allocators[alloc.name] = alloc.build()
+ # name is single allocator
+ elif issubclass(getattr(module, name).__class__, src.allocator.Allocator):
+ allocators[name] = getattr(module, name).build()
else:
print_status("Using system-wide installed allocators ...")
# Normal import fails
importlib.import_module('src.allocators.installed_allocators')
+ allocators = src.allocators.installed_allocators.allocators
+ src.globalvars.allocators = allocators
print_info("Allocators:", *src.globalvars.allocators.keys())
# Load facts
diff --git a/src/allocators/BA_allocators.py b/src/allocators/BA_allocators.py
index 5f4577e..5ac8870 100644
--- a/src/allocators/BA_allocators.py
+++ b/src/allocators/BA_allocators.py
@@ -1,20 +1,6 @@
-from src.allocators.glibc import Glibc
-from src.allocators.tcmalloc import TCMalloc
-from src.allocators.jemalloc import Jemalloc
-from src.allocators.hoard import Hoard
+from src.allocators.glibc import glibc, glibc_notc
+from src.allocators.tcmalloc import tcmalloc
+from src.allocators.jemalloc import jemalloc
+from src.allocators.hoard import hoard
-glibc = Glibc("glibc", color="C1")
-
-glibc_notc = Glibc("glibc-notc",
- configure_args="--disable-experimental-malloc",
- color="C2")
-
-tcmalloc = TCMalloc("tcmalloc", color="C3")
-
-jemalloc = Jemalloc("jemalloc", color="C4")
-
-hoard = Hoard("Hoard", color="C5", patches=["allocators/hoard_make.patch"])
-
-allocators_to_build = [glibc, glibc_notc, tcmalloc, jemalloc, hoard]
-
-allocators = {a.name: a.build() for a in allocators_to_build}
+allocators = [glibc, glibc_notc, tcmalloc, jemalloc, hoard]
diff --git a/src/allocators/all.py b/src/allocators/all.py
index 3973c37..bf2babd 100644
--- a/src/allocators/all.py
+++ b/src/allocators/all.py
@@ -1,44 +1,21 @@
from src.allocator import Allocator as Alloc
from src.allocator import Allocator_Sources as Alloc_Src
-from src.allocators.glibc import Glibc
-from src.allocators.tcmalloc import TCMalloc
-from src.allocators.jemalloc import Jemalloc
-from src.allocators.hoard import Hoard
+import src.allocators.glibcs
+from src.allocators.tcmalloc import tcmalloc, tcmalloc_nofs
+from src.allocators.jemalloc import jemalloc
+from src.allocators.hoard import hoard
+from src.allocators.supermalloc import supermalloc
-glibc = Glibc("glibc", color="C1")
-
-glibc_notc = Glibc("glibc-notc",
- configure_args="--disable-experimental-malloc",
- color="C2")
-
-glibc_nofs = Glibc("glibc_nofs",
- patches=["allocators/glibc_2.28_no_passive_falsesharing.patch"],
- color="C3")
-
-glibc_nofs_fancy = Glibc("glibc_nofs_fancy",
- patches=["allocators/glibc_2.28_no_passive_falsesharing_fancy.patch"],
- color="C4")
-
-tcmalloc = TCMalloc("tcmalloc", color="C5")
-
-tcmalloc_nofs = TCMalloc("tcmalloc_nofs",
- patches= ["{patchdir}/tcmalloc_2.7_no_active_falsesharing.patch"],
- color="C5")
-
-jemalloc = Jemalloc("jemalloc", color="C6")
-
-hoard = Hoard("Hoard", color="C7", patches=["allocators/hoard_make.patch"])
mesh = Alloc("Mesh", sources=Alloc_Src("Mesh",
- retrieve_cmds=["git clone https://github.com/plasma-umass/Mesh"],
- reset_cmds=["git stash"]),
+ retrieve_cmds=["git clone https://github.com/plasma-umass/Mesh"],
+ reset_cmds=["git stash"]),
LD_PRELOAD="{srcdir}/libmesh.so",
build_cmds=["cd {srcdir}; git submodule update --init",
"cd {srcdir}; ./configure",
"cd {srcdir}; make -j 4",
"mkdir {dir}"])
-allocators_to_build = [glibc, glibc_notc, glibc_nofs, glibc_nofs_fancy, tcmalloc, tcmalloc_nofs, jemalloc, hoard, mesh]
-
-allocators = {a.name: a.build() for a in allocators_to_build}
+allocators = [*src.allocators.glibcs.allocators, tcmalloc, tcmalloc_nofs,
+ jemalloc, hoard, mesh, supermalloc]
diff --git a/src/allocators/glibc.py b/src/allocators/glibc.py
index eff71dc..fb962f5 100644
--- a/src/allocators/glibc.py
+++ b/src/allocators/glibc.py
@@ -1,14 +1,15 @@
-import src.allocator
+from src.allocator import Allocator, Allocator_Sources, library_path
version = 2.29
-glibc_src = src.allocator.Allocator_Sources("glibc",
+glibc_src = Allocator_Sources("glibc",
retrieve_cmds=["git clone git://sourceware.org/git/glibc.git"],
prepare_cmds=["git checkout release/{}/master".format(version)],
reset_cmds=["git stash"])
-class Glibc (src.allocator.Allocator):
+
+class Glibc (Allocator):
"""Glibc definition for allocbench"""
def __init__(self, name, **kwargs):
@@ -23,7 +24,19 @@ class Glibc (src.allocator.Allocator):
"cd glibc-build; {srcdir}/configure --prefix={dir} " + configure_args,
"cd glibc-build; make",
"cd glibc-build; make install"]
+
kwargs["cmd_prefix"] = ("{dir}/lib/ld-linux-x86-64.so.2 --library-path {dir}/lib:"
- + src.allocator.library_path)
+ + library_path)
super().__init__(name, **kwargs)
+
+
+glibc = Glibc("glibc")
+
+glibc_notc = Glibc("glibc-noThreadCache", configure_args="--disable-experimental-malloc")
+
+glibc_nofs = Glibc("glibc-noFalsesharing",
+ patches=["{patchdir}/glibc_2.28_no_passive_falsesharing.patch"])
+
+glibc_nofs_fancy = Glibc("glibc-noFalsesharingClever",
+ patches=["{patchdir}/glibc_2.28_no_passive_falsesharing_fancy.patch"])
diff --git a/src/allocators/glibcs.py b/src/allocators/glibcs.py
index 891bf15..afbc88d 100644
--- a/src/allocators/glibcs.py
+++ b/src/allocators/glibcs.py
@@ -1,37 +1,4 @@
-import os
-import subprocess
+from src.allocators.glibc import glibc, glibc_notc, glibc_nofs, glibc_nofs_fancy
-from src.allocator import *
-from src.allocator import Allocator as Alloc
-from src.allocator import Allocator_Sources as Alloc_Src
-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_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)
-
-glibc_nofs = patch_alloc("glibc_nofs", glibc,
- ["allocators/glibc_2.28_no_passive_falsesharing.patch"])
-
-glibc_nofs_fancy = patch_alloc("glibc_nofs_fancy", glibc,
- ["allocators/glibc_2.28_no_passive_falsesharing_fancy.patch"])
-
-allocators_to_build = [glibc, glibc_notc, glibc_nofs, glibc_nofs_fancy]
-
-allocators = {a.name: a.build() for a in allocators_to_build}
+allocators = [glibc, glibc_notc, glibc_nofs, glibc_nofs_fancy]
diff --git a/src/allocators/hoard.py b/src/allocators/hoard.py
index f18fcb4..ded28e4 100644
--- a/src/allocators/hoard.py
+++ b/src/allocators/hoard.py
@@ -6,6 +6,7 @@ sources = src.allocator.Allocator_Sources("Hoard",
retrieve_cmds=["git clone https://github.com/emeryberger/Hoard.git"],
reset_cmds=["git stash"])
+
class Hoard (src.allocator.Allocator):
"""Hoard definition for allocbench"""
def __init__(self, name, **kwargs):
@@ -16,3 +17,6 @@ class Hoard (src.allocator.Allocator):
kwargs["patches"] = ["{patchdir}/hoard_make.patch"]
super().__init__(name, **kwargs)
+
+
+hoard = Hoard("Hoard")
diff --git a/src/allocators/installed_allocators.py b/src/allocators/installed_allocators.py
index 26fab5b..c478f13 100644
--- a/src/allocators/installed_allocators.py
+++ b/src/allocators/installed_allocators.py
@@ -1,16 +1,13 @@
"""Default allocators using system libraries"""
-import os
import subprocess
-import src.globalvars
-
maybe_allocators = ["tcmalloc", "jemalloc", "hoard"]
-src.globalvars.allocators = {"libc": {"cmd_prefix" : "",
- "binary_suffix" : "",
- "LD_PRELOAD" : "",
- "color" : "C1"}}
+allocators = {"libc": {"cmd_prefix": "",
+ "binary_suffix": "",
+ "LD_PRELOAD": "",
+ "color": "C1"}}
for i, t in enumerate(maybe_allocators):
try:
@@ -19,9 +16,9 @@ for i, t in enumerate(maybe_allocators):
universal_newlines=True).stdout.strip()
if path != "":
- src.globalvars.allocators[t] = {"cmd_prefix": "",
- "binary_suffix": "",
- "LD_PRELOAD": path,
- "color": "C"+str(i+2)}
+ allocators[t] = {"cmd_prefix": "",
+ "binary_suffix": "",
+ "LD_PRELOAD": path,
+ "color": "C"+str(i+2)}
except:
pass
diff --git a/src/allocators/je_tc_super.py b/src/allocators/je_tc_super.py
index 2315da3..6245610 100644
--- a/src/allocators/je_tc_super.py
+++ b/src/allocators/je_tc_super.py
@@ -1,19 +1,7 @@
-from src.allocator import Allocator as Alloc
-from src.allocator import Allocator_Sources as Alloc_Src
+from src.allocators.glibc import glibc
+from src.allocators.tcmalloc import tcmalloc
+from src.allocators.jemalloc import jemalloc
+from src.allocators.supermalloc import supermalloc
-from src.allocators.glibc import Glibc
-from src.allocators.tcmalloc import TCMalloc
-from src.allocators.jemalloc import Jemalloc
-from src.allocators.supermalloc import SuperMalloc
-glibc = Glibc("glibc", color="C1")
-
-tcmalloc = TCMalloc("tcmalloc", color="C5")
-
-jemalloc = Jemalloc("jemalloc", color="C6")
-
-supermalloc = SuperMalloc("SuperMalloc", color="C8")
-
-allocators_to_build = [glibc, tcmalloc, jemalloc, supermalloc]
-
-allocators = {a.name: a.build() for a in allocators_to_build}
+allocators = [glibc, tcmalloc, jemalloc, supermalloc]
diff --git a/src/allocators/jemalloc.py b/src/allocators/jemalloc.py
index f3f43cb..d3f2c3d 100644
--- a/src/allocators/jemalloc.py
+++ b/src/allocators/jemalloc.py
@@ -1,8 +1,9 @@
import src.allocator
+
version = "5.1.0"
-sources=src.allocator.Allocator_Sources("jemalloc",
+sources = src.allocator.Allocator_Sources("jemalloc",
retrieve_cmds=["git clone https://github.com/jemalloc/jemalloc.git"],
prepare_cmds=["git checkout {}".format(version), "./autogen.sh"])
@@ -18,3 +19,6 @@ class Jemalloc (src.allocator.Allocator):
"mkdir -p {dir}"]
super().__init__(name, **kwargs)
+
+
+jemalloc = Jemalloc("jemalloc")
diff --git a/src/allocators/no_falsesharing.py b/src/allocators/no_falsesharing.py
index fee631c..2514b7c 100644
--- a/src/allocators/no_falsesharing.py
+++ b/src/allocators/no_falsesharing.py
@@ -1,18 +1,5 @@
-from src.allocators.tcmalloc import TCMalloc
-from src.allocators.glibc import Glibc
+from src.allocators.tcmalloc import tcmalloc, tcmalloc_nofs
+from src.allocators.glibc import glibc, glibc_nofs
-glibc = Glibc("glibc", color="C1")
-glibc_nofs = Glibc("glibc_nofs",
- patches=["{patchdir}/glibc_2.28_no_passive_falsesharing.patch"],
- color="C2")
-
-tcmalloc = TCMalloc("tcmalloc", color="C3")
-
-tcmalloc_nofs = TCMalloc("tcmalloc_nofs",
- patches= ["{patchdir}/tcmalloc_2.7_no_active_falsesharing.patch"],
- color="C4")
-
-allocators_to_build = [glibc, glibc_nofs, tcmalloc, tcmalloc_nofs]
-
-allocators = {a.name: a.build() for a in allocators_to_build}
+allocators = [glibc, glibc_nofs, tcmalloc, tcmalloc_nofs]
diff --git a/src/allocators/scalloc.py b/src/allocators/scalloc.py
new file mode 100644
index 0000000..b554895
--- /dev/null
+++ b/src/allocators/scalloc.py
@@ -0,0 +1,30 @@
+from src.allocator import Allocator, Allocator_Sources, library_path
+
+
+version = "v1.0.0"
+
+scalloc_src = Allocator_Sources("scalloc",
+ retrieve_cmds=["git clone https://github.com/cksystemsgroup/scalloc"],
+ prepare_cmds=["git checkout {}".format(version),
+ "cd {srcdir}; tools/make_deps.sh",
+ "cd {srcdir}; build/gyp/gyp --depth=. scalloc.gyp"],
+ reset_cmds=["git stash"])
+
+
+class Scalloc (Allocator):
+ """Scalloc definition for allocbench"""
+ def __init__(self, name, **kwargs):
+
+ kwargs["sources"] = scalloc_src
+
+ kwargs["build_cmds"] = ["cd {srcdir}; BUILDTYPE=Release make",
+ "mkdir -p {dir}"]
+
+ kwargs["LD_PRELOAD"] = "{srcdir}/out/Release/lib.target/libscalloc.so"
+
+ kwargs["patches"] = ["{patchdir}/scalloc_fix_log.patch"]
+
+ super().__init__(name, **kwargs)
+
+
+scalloc = Scalloc("scalloc")
diff --git a/src/allocators/scalloc/scalloc_fix_log.patch b/src/allocators/scalloc/scalloc_fix_log.patch
new file mode 100644
index 0000000..eaae806
--- /dev/null
+++ b/src/allocators/scalloc/scalloc_fix_log.patch
@@ -0,0 +1,35 @@
+diff --git a/src/log.h b/src/log.h
+index 3edc36d..e1d181c 100644
+--- a/src/log.h
++++ b/src/log.h
+@@ -46,13 +46,13 @@ inline void LogPrintf(
+
+ snprintf(line_buffer, sizeof(line_buffer), "%d", line);
+ // Start with "__FILENAME__:__LINE__ ".
+- strncat(buffer, file, strlen(file));
++ strncat(buffer, file, rest);
+ rest -= strlen(file);
+- strncat(buffer, ":", 1);
++ strncat(buffer, ":", rest);
+ rest -= 1;
+- strncat(buffer, line_buffer, strlen(line_buffer));
++ strncat(buffer, line_buffer, rest);
+ rest -= strlen(line_buffer);
+- strncat(buffer, " ", 1);
++ strncat(buffer, " ", rest);
+ rest -= 1;
+
+ // Sanity check.
+@@ -69,10 +69,10 @@ inline void LogPrintf(
+ // For copying the suffix we need actual rest value again.
+ strncpy(rest_start + (rest - strlen(truncate_suffix)),
+ truncate_suffix,
+- strlen(truncate_suffix));
++ rest);
+ }
+
+- strncat(buffer, "\n", 1);
++ strncat(buffer, "\n", rest);
+
+ // Sanity check.
+ if (buffer[kLogLen-1] != 0) {
diff --git a/src/allocators/supermalloc.py b/src/allocators/supermalloc.py
index 94aae7d..24fbb15 100644
--- a/src/allocators/supermalloc.py
+++ b/src/allocators/supermalloc.py
@@ -2,13 +2,13 @@ import src.allocator
version = "709663fb81ba091b0a78058869a644a272f4163d"
-sources=src.allocator.Allocator_Sources("SuperMalloc",
+sources = src.allocator.Allocator_Sources("SuperMalloc",
retrieve_cmds=["git clone https://github.com/kuszmaul/SuperMalloc"],
prepare_cmds=["git checkout {}".format(version)])
class SuperMalloc (src.allocator.Allocator):
- """jemalloc definition for allocbench"""
+ """SuperMalloc definition for allocbench"""
def __init__(self, name, **kwargs):
kwargs["sources"] = sources
@@ -18,5 +18,5 @@ class SuperMalloc (src.allocator.Allocator):
super().__init__(name, **kwargs)
+
supermalloc = SuperMalloc("SuperMalloc", color="C1")
-allocators = {supermalloc.name: supermalloc.build()}
diff --git a/src/allocators/tcmalloc.py b/src/allocators/tcmalloc.py
index 4650772..b6da1e7 100644
--- a/src/allocators/tcmalloc.py
+++ b/src/allocators/tcmalloc.py
@@ -1,13 +1,13 @@
import src.allocator
-
version = 2.7
-tcmalloc_src = src.allocator.Allocator_Sources("gperftools",
- ["git clone https://github.com/gperftools/gperftools.git"],
+tcmalloc_src = src.allocator.Allocator_Sources("tcmalloc",
+ ["git clone https://github.com/gperftools/gperftools.git tcmalloc"],
["git checkout gperftools-{}".format(version), "./autogen.sh"],
["git stash"])
+
class TCMalloc (src.allocator.Allocator):
"""TCMalloc definition for allocbench"""
def __init__(self, name, **kwargs):
@@ -18,3 +18,9 @@ class TCMalloc (src.allocator.Allocator):
"cd {srcdir}; make install -j4"]
super().__init__(name, **kwargs)
+
+
+tcmalloc = TCMalloc("TCMalloc")
+
+tcmalloc_nofs = TCMalloc("TCMalloc-NoFalsesharing",
+ patches=["{patchdir}/tcmalloc_2.7_no_active_falsesharing.patch"])