diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile | 8 | ||||
| -rw-r--r-- | src/allocator.py | 19 | ||||
| -rw-r--r-- | src/allocators/speedymalloc.py | 39 | ||||
| -rw-r--r-- | src/allocators/speedymallocs.py | 26 | ||||
| -rw-r--r-- | src/bump_alloc.h | 53 | ||||
| -rw-r--r-- | src/bumpptr_alloc.c | 50 | ||||
| -rw-r--r-- | src/malloc.c | 4 | ||||
| -rw-r--r-- | src/plots.py | 6 | ||||
| -rw-r--r-- | src/util.py | 2 |
9 files changed, 119 insertions, 88 deletions
diff --git a/src/Makefile b/src/Makefile index 5458801..84179e2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -14,21 +14,17 @@ MEMSIZE_KB=$(shell free -t | tail -1 | tr -s ' ' | cut -d ' ' -f 2) MEMSIZE="$(MEMSIZE_KB) * 1024l" TOOLS = print_status_on_exit.so exec sig_handlers.so -ALLOCS = chattymalloc.so bumpptr_alloc.so speedymalloc.so align_to_cl.so +ALLOCS = chattymalloc.so bumpptr_alloc.so align_to_cl.so TARGETS = $(addprefix $(OBJDIR)/allocators/,$(ALLOCS)) $(addprefix $(OBJDIR)/,$(TOOLS)) .PHONY: all clean all: $(TARGETS) -$(OBJDIR)/allocators/bumpptr_alloc.so: bump_alloc.h bumpptr_alloc.c malloc.c Makefile +$(OBJDIR)/allocators/bumpptr_alloc.so: bumpptr_alloc.c malloc.c Makefile @if test \( ! \( -d $(@D) \) \) ;then mkdir -p $(@D);fi $(CC) $(LDFLAGS) -shared -DMEMSIZE=$(MEMSIZE) $(CFLAGS) -o $@ bumpptr_alloc.c malloc.c -$(OBJDIR)/allocators/speedymalloc.so: speedymalloc.c malloc.c Makefile - @if test \( ! \( -d $(@D) \) \) ;then mkdir -p $(@D);fi - $(CC) $(LDFLAGS) -shared -DMEMSIZE=$(MEMSIZE) $(CFLAGS) -o $@ speedymalloc.c malloc.c - $(OBJDIR)/allocators/align_to_cl.so: align_to_cl.c Makefile @if test \( ! \( -d $(@D) \) \) ;then mkdir -p $(@D);fi $(CC) $(LDFLAGS) -shared $(CFLAGS) -o $@ $< -ldl diff --git a/src/allocator.py b/src/allocator.py index fe31ed4..00d62ac 100644 --- a/src/allocator.py +++ b/src/allocator.py @@ -146,17 +146,16 @@ class Allocator: self.prepare() print_status("Building", self.name, "...") - if self.build_cmds: - for cmd in self.build_cmds: - cmd = cmd.format(dir=self.dir, srcdir=self.srcdir) + for cmd in self.build_cmds: + cmd = cmd.format(dir=self.dir, srcdir=self.srcdir) - try: - run_cmd(cmd, cwd=BUILDDIR, shell=True) - except CalledProcessError as e: - print_debug(e.stderr, file=sys.stderr) - print_error(f"Builing {self.name} failed") - shutil.rmtree(self.dir, ignore_errors=True) - raise e + try: + run_cmd(cmd, cwd=BUILDDIR, shell=True) + except CalledProcessError as e: + print_debug(e.stderr, file=sys.stderr) + print_error(f"Builing {self.name} failed") + shutil.rmtree(self.dir, ignore_errors=True) + raise e with open(buildtimestamp_path, "w") as buildtimestamp_file: print_info2("Save build time to:", buildtimestamp_path) diff --git a/src/allocators/speedymalloc.py b/src/allocators/speedymalloc.py index 0cf6836..3e54b29 100644 --- a/src/allocators/speedymalloc.py +++ b/src/allocators/speedymalloc.py @@ -22,8 +22,39 @@ memory in speeds favor. Memory is mmapped per thread and never freed. See src/bumpptr.c for the actual implementation. """ -import os -from src.allocator import Allocator, BUILDDIR +from src.artifact import GitArtifact +from src.allocator import Allocator -speedymalloc = Allocator("speedymalloc", LD_PRELOAD=os.path.join(BUILDDIR, "speedymalloc.so"), - color="xkcd:dark") +VERSION = "4d965cd9b601d291117c11e013aa4600f694585d" + +class Speedymalloc(Allocator): + """ Speedymalloc definition for allocbench""" + + sources = GitArtifact("speedymalloc", "https://gitlab.cs.fau.de/flow/speedymalloc.git") + + def __init__(self, name, **kwargs): + + configuration = "" + for option, value in kwargs.get("options", {}).items(): + configuration += f"-D{option}={value} " + + self.build_cmds = [f"meson {{srcdir}} {{dir}} {configuration}", + "ninja -C {dir}"] + + self.LD_PRELOAD = "{dir}/libspeedymalloc.so" + super().__init__(name, **kwargs) + +speedymalloc = Speedymalloc("speedymalloc", version=VERSION) + +speedymalloc_dont_madv_free = Speedymalloc("speedymalloc_dont_madv_free", + options = {"madvise_free": "false"}, + version=VERSION) + +speedymalloc_dont_madv_willneed = Speedymalloc("speedymalloc_dont_madv_willneed", + options = {"madvise_willneed": "false"}, + version=VERSION) + +speedymalloc_4095_sc_32 = Speedymalloc("speedymalloc_dont_madv_willneed", + options = {"cache_bins": 4095, + "cache_bin_seperation": 32}, + version=VERSION) diff --git a/src/allocators/speedymallocs.py b/src/allocators/speedymallocs.py new file mode 100644 index 0000000..8961fe8 --- /dev/null +++ b/src/allocators/speedymallocs.py @@ -0,0 +1,26 @@ +# Copyright 2018-2019 Florian Fischer <florian.fl.fischer@fau.de> +# +# This file is part of allocbench. +# +# allocbench is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# allocbench is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with allocbench. If not, see <http://www.gnu.org/licenses/>. + +"""Collection containing all glibc variants""" + +import src.allocators.speedymalloc as sm + + +allocators = [sm.speedymalloc, + sm.speedymalloc_dont_madv_free, + sm.speedymalloc_dont_madv_willneed, + sm.speedymalloc_4095_sc_32] diff --git a/src/bump_alloc.h b/src/bump_alloc.h deleted file mode 100644 index 6a651a1..0000000 --- a/src/bump_alloc.h +++ /dev/null @@ -1,53 +0,0 @@ -#include <assert.h> -#include <errno.h> -#include <stddef.h> /* NULL, size_t */ -#include <stdint.h> /* uintptr_t */ -#include <sys/mman.h> /* mmap */ - -#ifndef MEMSIZE -#define MEMSIZE 1024*4*1024*1024l -#endif - -#define unlikely(x) __builtin_expect((x),0) - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct bumpptr { - uintptr_t end; - uintptr_t ptr; -} bumpptr_t; - -__thread bumpptr_t* tsd = NULL; - -static inline void* bump_up(size_t size, size_t align) { - assert(align % 2 == 0); - - if (unlikely(tsd == NULL)) { - void* mem_start = mmap(NULL, MEMSIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_HUGETLB, -1, 0); - if(mem_start == MAP_FAILED) { - perror("mmap"); - return NULL; - } - tsd = (bumpptr_t*)mem_start; - tsd->ptr = (uintptr_t)mem_start + sizeof(bumpptr_t); - tsd->end = (uintptr_t)mem_start + MEMSIZE; - } - - // align ptr; - uintptr_t aligned = (tsd->ptr + align - 1) & ~(align - 1); - - uintptr_t new_ptr = aligned + size; - if (new_ptr > tsd->end) { - errno = ENOMEM; - return NULL; - } else { - tsd->ptr = new_ptr; - return (void*)aligned; - } -} - -#ifdef __cplusplus -} -#endif diff --git a/src/bumpptr_alloc.c b/src/bumpptr_alloc.c index 77a11d9..ee2928a 100644 --- a/src/bumpptr_alloc.c +++ b/src/bumpptr_alloc.c @@ -1,16 +1,52 @@ -#include <errno.h> /* TODO: set errno */ +#include <assert.h> +#include <errno.h> #include <stddef.h> /* NULL, size_t */ #include <stdint.h> /* uintptr_t */ #include <stdio.h> /* fprintf */ - -#include "bump_alloc.h" +#include <sys/mman.h> /* mmap */ #define MIN_ALIGNMENT 16 -#ifdef __cplusplus -extern "C" { +#ifndef MEMSIZE +#define MEMSIZE 1024*4*1024*1024l #endif +#define unlikely(x) __builtin_expect((x),0) + +typedef struct bumpptr { + uintptr_t end; + uintptr_t ptr; +} bumpptr_t; + +__thread bumpptr_t* tsd = NULL; + +static inline void* bump_up(size_t size, size_t align) { + assert(align % 2 == 0); + + if (unlikely(tsd == NULL)) { + void* mem_start = mmap(NULL, MEMSIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_HUGETLB, -1, 0); + if(mem_start == MAP_FAILED) { + perror("mmap"); + return NULL; + } + tsd = (bumpptr_t*)mem_start; + tsd->ptr = (uintptr_t)mem_start + sizeof(bumpptr_t); + tsd->end = (uintptr_t)mem_start + MEMSIZE; + } + + // align ptr; + uintptr_t aligned = (tsd->ptr + align - 1) & ~(align - 1); + + uintptr_t new_ptr = aligned + size; + if (new_ptr > tsd->end) { + errno = ENOMEM; + return NULL; + } else { + tsd->ptr = new_ptr; + return (void*)aligned; + } +} + void* malloc(size_t size) { return bump_up(size, MIN_ALIGNMENT); } @@ -26,7 +62,3 @@ void malloc_stats() { fprintf(stderr, "Bump pointer allocator by muhq\n"); fprintf(stderr, "Memsize: %zu, start address: %p, bump pointer %p\n", MEMSIZE, tsd, tsd->ptr); } - -#ifdef __cplusplus -} -#endif diff --git a/src/malloc.c b/src/malloc.c index 4653aa8..92265cb 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -23,10 +23,6 @@ int posix_memalign(void **memptr, size_t alignment, size_t size) { void *out; - if(memptr == NULL) { - return 22; - } - if((alignment % sizeof(void*)) != 0) { return 22; } diff --git a/src/plots.py b/src/plots.py index 5962367..c254741 100644 --- a/src/plots.py +++ b/src/plots.py @@ -293,9 +293,11 @@ def export_stats_to_dataref(bench, datapoint, path=None): for alloc in bench.results["allocators"]: for perm in bench.iterate_args(args=bench.results["args"]): for statistic, values in stats[alloc][perm].items(): - cur_line = line.format(bench.name, alloc, + cur_line = line.format(bench.name, + alloc, "/".join([str(p) for p in list(perm)]), - statistic, values[datapoint]) + statistic, + values.get(datapoint, nan)) # Replace empty outliers cur_line.replace("[]", "") # Replace underscores diff --git a/src/util.py b/src/util.py index 2e37226..fb0e75b 100644 --- a/src/util.py +++ b/src/util.py @@ -42,6 +42,8 @@ def run_cmd(cmd, stdout = None stderr = stdout + print_debug(f"Running command {cmd}") + return subprocess.run(cmd, stdout=stdout, stderr=stderr, |
