bmalloc: support aligned allocation
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Jan 2015 22:49:45 +0000 (22:49 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Jan 2015 22:49:45 +0000 (22:49 +0000)
commit596046451659a314f5b03495da1eb8a936af0ef7
tree3d58fa601fd6dc28ecddc193b95ba096dcf1255f
parent6399d456378853527dadb843d3ac712eb694ba84
bmalloc: support aligned allocation
https://bugs.webkit.org/show_bug.cgi?id=140732

Reviewed by Andreas Kling.

PerformanceTests:

* MallocBench/MallocBench.xcodeproj/project.pbxproj:
* MallocBench/MallocBench/Benchmark.cpp:
* MallocBench/MallocBench/memalign.cpp:
(test):
(benchmark_memalign): Added a test for specific interesting memalign values.

* MallocBench/MallocBench/stress_aligned.cpp: Added.
(benchmark_stress_aligned):
* MallocBench/MallocBench/stress_aligned.h: Added. Added a stress test
for arbitrary memalign values.

Source/bmalloc:

* bmalloc/Allocator.cpp:
(bmalloc::Allocator::allocate): New function for aligned allocation.

Small and medium requests just allocate and free until they find an
aligned pointer. This is slightly inefficient in the worst case, but
still constant-time with little-to-no space overhead.

Large requests use a new API that requires the client to specify both
its ideal size and alignment, and the worst-case size you would have to
allocate in order to produce some interior pointer of the requested size
and alignment. We put the burden of this calculation on the client
because it simplifies things if we guarantee that allocation won't fail.

XLarge requests are easy: we just forward them to vmAllocate, which
already supported aligned requests.

* bmalloc/BoundaryTag.h:
* bmalloc/BoundaryTagInlines.h:
(bmalloc::BoundaryTag::mergeLeft):
(bmalloc::BoundaryTag::mergeRight):
(bmalloc::BoundaryTag::merge):
(bmalloc::BoundaryTag::deallocate):
(bmalloc::BoundaryTag::split):
(bmalloc::BoundaryTag::allocate): No behavior change here. I just
refactored the interface to remove some reference out parameters in
order to clarify what changes and what doesn't.

* bmalloc/Heap.cpp:
(bmalloc::Heap::allocateXLarge): Added an alignment API.

(bmalloc::Heap::allocateLarge):
* bmalloc/Heap.h: Added an alignment API. I split out allocateLarge into
a few variants, so aligned and unaligned allocation could share some code.

* bmalloc/SegregatedFreeList.cpp:
(bmalloc::SegregatedFreeList::take):
* bmalloc/SegregatedFreeList.h: Changed to use a separate, explicit API
for aligned allocation. It turns out that the aligned path is pretty
different, since it ends up searching for two potential ways to satisfy
an allocation: either large enough and aligned, or large enough to split
into something not aligned and something large enough and aligned.

* bmalloc/VMAllocate.h:
(bmalloc::vmAllocate): Switched alignment to come before size because
that's how the memalign API specifies it.

* bmalloc/VMHeap.h:
(bmalloc::VMHeap::allocateLargeRange): Added an alignment API.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@178861 268f45cc-cd09-0410-ab3c-d52691b4dbfc
16 files changed:
PerformanceTests/ChangeLog
PerformanceTests/MallocBench/MallocBench.xcodeproj/project.pbxproj
PerformanceTests/MallocBench/MallocBench/Benchmark.cpp
PerformanceTests/MallocBench/MallocBench/memalign.cpp
PerformanceTests/MallocBench/MallocBench/stress_aligned.cpp [new file with mode: 0644]
PerformanceTests/MallocBench/MallocBench/stress_aligned.h [new file with mode: 0644]
Source/bmalloc/ChangeLog
Source/bmalloc/bmalloc/Allocator.cpp
Source/bmalloc/bmalloc/BoundaryTag.h
Source/bmalloc/bmalloc/BoundaryTagInlines.h
Source/bmalloc/bmalloc/Heap.cpp
Source/bmalloc/bmalloc/Heap.h
Source/bmalloc/bmalloc/SegregatedFreeList.cpp
Source/bmalloc/bmalloc/SegregatedFreeList.h
Source/bmalloc/bmalloc/VMAllocate.h
Source/bmalloc/bmalloc/VMHeap.h