Skip to content

Commit

Permalink
Refactored and optimized implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansson authored Aug 8, 2019
2 parents 5ffaa23 + 9ebe0ce commit 75e19cc
Show file tree
Hide file tree
Showing 14 changed files with 1,908 additions and 1,340 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
1.4.0

Improved cross thread deallocations by using per-span atomic free list to minimize thread
contention and localize free list processing to actual span

Change span free list to a linked list, conditionally initialized one memory page at a time

Reduce number of conditionals in the fast path allocation and avoid touching heap structure
at all in best case

Avoid realigning block in deallocation unless span marked as used by alignment > 32 bytes

Revert block granularity and natural alignment to 16 bytes to reduce memory waste

Bugfix for preserving data when reallocating a previously aligned (>32 bytes) block

Use compile time span size by default for improved performance, added build time RPMALLOC_CONFIGURABLE
preprocessor directive to reenable configurability of span and page size

More detailed statistics

Disabled adaptive thread cache by default

Fixed an issue where reallocations of large blocks could read outsize of memory page boundaries

Tag mmap requests on macOS with tag 240 for identification with vmmap tool


1.3.2

Support for alignment equal or larger than memory page size, up to span size
Expand Down
45 changes: 25 additions & 20 deletions README.md

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions build/ninja/clang.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ def initialize(self, project, archs, configs, includepaths, dependlibs, libpaths

#Base flags
self.cflags = ['-D' + project.upper() + '_COMPILE=1',
'-funit-at-a-time', '-fstrict-aliasing',
'-fno-math-errno','-ffinite-math-only', '-funsafe-math-optimizations',
'-funit-at-a-time', '-fstrict-aliasing', '-fvisibility=hidden', '-fno-stack-protector',
'-fomit-frame-pointer', '-fno-math-errno','-ffinite-math-only', '-funsafe-math-optimizations',
'-fno-trapping-math', '-ffast-math']
self.cwarnflags = ['-W', '-Werror', '-pedantic', '-Wall', '-Weverything',
'-Wno-padded', '-Wno-documentation-unknown-command']
'-Wno-padded', '-Wno-documentation-unknown-command', '-Wno-static-in-inline']
self.cmoreflags = []
self.mflags = []
self.arflags = []
self.linkflags = []
self.linkflags = ['-fomit-frame-pointer']
self.oslibs = []
self.frameworks = []

Expand All @@ -65,7 +65,6 @@ def initialize(self, project, archs, configs, includepaths, dependlibs, libpaths
if self.target.is_linux() or self.target.is_bsd() or self.target.is_raspberrypi():
self.cflags += ['-D_GNU_SOURCE=1']
self.linkflags += ['-pthread']
self.oslibs += ['m']
if self.target.is_linux() or self.target.is_raspberrypi():
self.oslibs += ['dl']
if self.target.is_bsd():
Expand All @@ -85,7 +84,7 @@ def initialize(self, project, archs, configs, includepaths, dependlibs, libpaths
self.cflags += ['-w']
self.cxxflags = list(self.cflags)

self.cflags += ['-std=c11']
self.cflags += ['-std=gnu11']
if self.target.is_macos() or self.target.is_ios():
self.cxxflags += ['-std=c++14', '-stdlib=libc++']
else:
Expand Down Expand Up @@ -311,7 +310,7 @@ def make_carchflags(self, arch, targettype):
flags = []
if targettype == 'sharedlib':
flags += ['-DBUILD_DYNAMIC_LINK=1']
if self.target.is_linux():
if self.target.is_linux() or self.target.is_bsd():
flags += ['-fPIC']
flags += self.make_targetarchflags(arch, targettype)
return flags
Expand All @@ -321,11 +320,11 @@ def make_cconfigflags(self, config, targettype):
if config == 'debug':
flags += ['-DBUILD_DEBUG=1', '-g']
elif config == 'release':
flags += ['-DBUILD_RELEASE=1', '-O3', '-g', '-funroll-loops']
flags += ['-DBUILD_RELEASE=1', '-DNDEBUG', '-O3', '-g', '-funroll-loops']
elif config == 'profile':
flags += ['-DBUILD_PROFILE=1', '-O3', '-g', '-funroll-loops']
flags += ['-DBUILD_PROFILE=1', '-DNDEBUG', '-O3', '-g', '-funroll-loops']
elif config == 'deploy':
flags += ['-DBUILD_DEPLOY=1', '-O3', '-g', '-funroll-loops']
flags += ['-DBUILD_DEPLOY=1', '-DNDEBUG', '-O3', '-g', '-funroll-loops']
return flags

def make_ararchflags(self, arch, targettype):
Expand Down Expand Up @@ -363,7 +362,9 @@ def make_linkconfigflags(self, config, targettype, variables):
flags += ['-dynamiclib']
else:
if targettype == 'sharedlib':
flags += ['-shared']
flags += ['-shared', '-fPIC']
if config == 'release':
flags += ['-DNDEBUG', '-O3']
return flags

def make_linkarchlibs(self, arch, targettype):
Expand Down
3 changes: 1 addition & 2 deletions build/ninja/gcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def initialize(self, project, archs, configs, includepaths, dependlibs, libpaths
if self.target.is_linux() or self.target.is_bsd() or self.target.is_raspberrypi():
self.cflags += ['-D_GNU_SOURCE=1']
self.linkflags += ['-pthread']
self.oslibs += ['m']
if self.target.is_linux() or self.target.is_raspberrypi():
self.oslibs += ['dl']
if self.target.is_bsd():
Expand Down Expand Up @@ -183,7 +182,7 @@ def make_carchflags(self, arch, targettype):
flags = []
if targettype == 'sharedlib':
flags += ['-DBUILD_DYNAMIC_LINK=1']
if self.target.is_linux():
if self.target.is_linux() or self.target.is_bsd():
flags += ['-fPIC']
flags += self.make_targetarchflags(arch, targettype)
return flags
Expand Down
2 changes: 1 addition & 1 deletion build/ninja/msvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def initialize(self, project, archs, configs, includepaths, dependlibs, libpaths
self.linker = 'link'
self.dller = 'dll'

#Command definitions
#Command definitions (to generate assembly, add "/FAs /Fa$out.asm")
self.cccmd = '$toolchain$cc /showIncludes /I. $includepaths $moreincludepaths $cflags $carchflags $cconfigflags $cmoreflags /c $in /Fo$out /Fd$pdbpath /FS /nologo'
self.cxxcmd = '$toolchain$cxx /showIncludes /I. $includepaths $moreincludepaths $cxxflags $carchflags $cconfigflags $cmoreflags /c $in /Fo$out /Fd$pdbpath /FS /nologo'
self.ccdepfile = None
Expand Down
15 changes: 4 additions & 11 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,14 @@
import generator

generator = generator.Generator(project = 'rpmalloc', variables = [('bundleidentifier', 'com.rampantpixels.rpmalloc.$(binname)')])
target = generator.target
writer = generator.writer
toolchain = generator.toolchain

rpmalloc_lib = generator.lib(module = 'rpmalloc', libname = 'rpmalloc', sources = ['rpmalloc.c'])

if not target.is_android() and not target.is_ios():
if not generator.target.is_android() and not generator.target.is_ios():
rpmalloc_so = generator.sharedlib(module = 'rpmalloc', libname = 'rpmalloc', sources = ['rpmalloc.c'])

if not target.is_windows():
if not target.is_android() and not target.is_ios():
rpmallocwrap_lib = generator.lib(module = 'rpmalloc', libname = 'rpmallocwrap', sources = ['rpmalloc.c', 'malloc.c', 'new.cc'], variables = {'defines': ['ENABLE_PRELOAD=1']})
rpmallocwrap_so = generator.sharedlib(module = 'rpmalloc', libname = 'rpmallocwrap', sources = ['rpmalloc.c'], variables = {'defines': ['ENABLE_PRELOAD=1', 'ENABLE_OVERRIDE=1']})
rpmallocwrap_lib = generator.lib(module = 'rpmalloc', libname = 'rpmallocwrap', sources = ['rpmalloc.c'], variables = {'defines': ['ENABLE_PRELOAD=1', 'ENABLE_OVERRIDE=1']})

if not target.is_windows() and not target.is_android() and not target.is_ios():
rpmallocwrap_so = generator.sharedlib(module = 'rpmalloc', libname = 'rpmallocwrap', sources = ['rpmalloc.c', 'malloc.c', 'new.cc'], variables = {'runtime': 'c++', 'defines': ['ENABLE_PRELOAD=1']})

if not target.is_ios() and not target.is_android():
generator.bin(module = 'test', sources = ['thread.c', 'main.c'], binname = 'rpmalloc-test', implicit_deps = [rpmalloc_lib], libs = ['rpmalloc'], includepaths = ['rpmalloc', 'test'], variables = {'defines': ['ENABLE_ASSERTS=1', 'ENABLE_STATISTICS=1']})
generator.bin(module = 'test', sources = ['thread.c', 'main-override.cc'], binname = 'rpmallocwrap-test', implicit_deps = [rpmallocwrap_lib], libs = ['rpmallocwrap'], includepaths = ['rpmalloc', 'test'], variables = {'runtime': 'c++', 'defines': ['ENABLE_ASSERTS=1', 'ENABLE_STATISTICS=1']})
Loading

0 comments on commit 75e19cc

Please sign in to comment.