diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2019-08-11 16:53:06 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2019-08-11 16:53:06 +0200 |
| commit | 16ef25b5eda3a9fc51ecea309d2cb6b0508b009b (patch) | |
| tree | 23690c4d0673752310b00bd364db84bae3c9b49d | |
| parent | 58d08e433c956af1eacb60d36134d65494007a9b (diff) | |
| download | allocbench-16ef25b5eda3a9fc51ecea309d2cb6b0508b009b.tar.gz allocbench-16ef25b5eda3a9fc51ecea309d2cb6b0508b009b.zip | |
improve bumpptr_alloc
Return always 16 Byte aligned blocks and mmap the whole available
memory reported by free -t per thread.
| -rw-r--r-- | src/Makefile | 14 | ||||
| -rw-r--r-- | src/bumpptr_alloc.c | 15 |
2 files changed, 22 insertions, 7 deletions
diff --git a/src/Makefile b/src/Makefile index 9858cdf..47d0dd4 100644 --- a/src/Makefile +++ b/src/Makefile @@ -4,23 +4,27 @@ CC ?= gcc WARNFLAGS ?= -Wall -Wextra COMMONFLAGS ?= -fno-builtin -fPIC -DPIC -pthread -OPTFLAGS ?= -O3 -DNDEBUG +OPTFLAGS ?= -O0 -g CFLAGS ?= $(OPTFLAGS) $(WARNFLAGS) $(COMMONFLAGS) LDFLAGS ?= -pthread -static-libgcc +MEMSIZE_KB=$(shell free -t | tail -1 | tr -s ' ' | cut -d ' ' -f 2) +MEMSIZE=$(shell echo $(MEMSIZE_KB)"* 1024" | bc) + .PHONY: all clean all: $(OBJDIR)/print_status_on_exit.so $(OBJDIR)/allocators/bumpptr_alloc.so -$(OBJDIR)/allocators/bumpptr_alloc.so: bumpptr_alloc.c | $(OBJDIR)/allocators +$(OBJDIR)/allocators/bumpptr_alloc.so: bumpptr_alloc.c Makefile | $(OBJDIR)/allocators @echo "Compiling $@..."; - $(CC) $(LDFLAGS) -shared $(CFLAGS) -o $@ $< + $(CC) $(LDFLAGS) -shared -DMEMSIZE=$(MEMSIZE) $(CFLAGS) -o $@ $< + # $(CC) $(LDFLAGS) -shared $(CFLAGS) -o $@ $< -$(OBJDIR)/print_status_on_exit.so: print_status_on_exit.c | $(OBJDIR) +$(OBJDIR)/print_status_on_exit.so: print_status_on_exit.c Makefile | $(OBJDIR) @echo "Compiling $@..."; - $(CC) $(LDFLAGS) -shared -O2 $(CFLAGS) -o $@ $< + $(CC) $(LDFLAGS) -shared $(CFLAGS) -o $@ $< $(OBJDIR)/allocators: mkdir -p $@ diff --git a/src/bumpptr_alloc.c b/src/bumpptr_alloc.c index 2690809..576dc40 100644 --- a/src/bumpptr_alloc.c +++ b/src/bumpptr_alloc.c @@ -6,7 +6,11 @@ #include <string.h> /* memset */ #include <sys/mman.h> /* memset */ +#define MIN_ALIGNMENT 16 + +#ifndef MEMSIZE #define MEMSIZE 1024*4*1024*1024l +#endif #ifdef __cplusplus extern "C" { @@ -27,6 +31,12 @@ void* malloc(size_t size) { ptr = (uintptr_t)mem_start; } + // align ptr; + if (ptr % MIN_ALIGNMENT != 0) { + size_t mask = MIN_ALIGNMENT -1; + ptr = (ptr + mask) & ~mask; + } + void* ret = (void*)ptr; ptr += size; return ret; @@ -49,8 +59,9 @@ void* realloc(void* ptr, size_t size) { } void* memalign(size_t alignment, size_t size) { - // bump ptr to alignment and malloc - ptr = (ptr + (alignment - 1)) & -alignment; + // align ptr to alignment and malloc + size_t mask = alignment - 1; + ptr = (ptr + mask) & ~mask; return malloc(size); } |
