Title: [199246] trunk/Source/bmalloc
- Revision
- 199246
- Author
- [email protected]
- Date
- 2016-04-08 13:59:51 -0700 (Fri, 08 Apr 2016)
Log Message
bmalloc: stress_aligned test fails if you increase smallMax
https://bugs.webkit.org/show_bug.cgi?id=156414
Reviewed by Oliver Hunt.
When size exceeds alignment and is a multiple of alignment and is not
a power of two, such as 24kB with 8kB alignment, the small allocator
did not always guarantee alignment. Let's fix that.
* bmalloc/Algorithm.h:
(bmalloc::divideRoundingUp): Math is hard.
* bmalloc/Allocator.cpp:
(bmalloc::Allocator::allocate): Align to the page size unconditionally.
Even if the page size is not a power of two, it might be a multiple of
a power of two, and we want alignment to that smaller power of two to
be guaranteed.
Modified Paths
Diff
Modified: trunk/Source/bmalloc/ChangeLog (199245 => 199246)
--- trunk/Source/bmalloc/ChangeLog 2016-04-08 20:46:25 UTC (rev 199245)
+++ trunk/Source/bmalloc/ChangeLog 2016-04-08 20:59:51 UTC (rev 199246)
@@ -1,3 +1,23 @@
+2016-04-08 Geoffrey Garen <[email protected]>
+
+ bmalloc: stress_aligned test fails if you increase smallMax
+ https://bugs.webkit.org/show_bug.cgi?id=156414
+
+ Reviewed by Oliver Hunt.
+
+ When size exceeds alignment and is a multiple of alignment and is not
+ a power of two, such as 24kB with 8kB alignment, the small allocator
+ did not always guarantee alignment. Let's fix that.
+
+ * bmalloc/Algorithm.h:
+ (bmalloc::divideRoundingUp): Math is hard.
+
+ * bmalloc/Allocator.cpp:
+ (bmalloc::Allocator::allocate): Align to the page size unconditionally.
+ Even if the page size is not a power of two, it might be a multiple of
+ a power of two, and we want alignment to that smaller power of two to
+ be guaranteed.
+
2016-04-06 Geoffrey Garen <[email protected]>
bmalloc: handle aligned allocations on the fast path
Modified: trunk/Source/bmalloc/bmalloc/Algorithm.h (199245 => 199246)
--- trunk/Source/bmalloc/bmalloc/Algorithm.h 2016-04-08 20:46:25 UTC (rev 199245)
+++ trunk/Source/bmalloc/bmalloc/Algorithm.h 2016-04-08 20:59:51 UTC (rev 199246)
@@ -87,7 +87,7 @@
return roundDownToMultipleOf(divisor, x);
}
-template<typename T> void divideRoundingUp(T numerator, T denominator, T& quotient, T& remainder)
+template<typename T> inline void divideRoundingUp(T numerator, T denominator, T& quotient, T& remainder)
{
// We expect the compiler to emit a single divide instruction to extract both the quotient and the remainder.
quotient = numerator / denominator;
@@ -96,6 +96,11 @@
quotient += 1;
}
+template<typename T> inline T divideRoundingUp(T numerator, T denominator)
+{
+ return (numerator + denominator - 1) / denominator;
+}
+
// Version of sizeof that returns 0 for empty classes.
template<typename T> inline constexpr size_t sizeOf()
Modified: trunk/Source/bmalloc/bmalloc/VMHeap.cpp (199245 => 199246)
--- trunk/Source/bmalloc/bmalloc/VMHeap.cpp 2016-04-08 20:46:25 UTC (rev 199245)
+++ trunk/Source/bmalloc/bmalloc/VMHeap.cpp 2016-04-08 20:59:51 UTC (rev 199246)
@@ -87,12 +87,9 @@
size_t pageSize = bmalloc::pageSize(pageClass);
size_t smallPageCount = pageSize / smallPageSize;
- // If our page size is a power of two, we align to it in order to guarantee
- // that we can service aligned allocation requests at the same power of two.
- size_t alignment = vmPageSizePhysical();
- if (isPowerOfTwo(pageSize))
- alignment = pageSize;
- size_t metadataSize = roundUpToMultipleOf(alignment, sizeof(Chunk));
+ // We align to our page size in order to guarantee that we can service
+ // aligned allocation requests at equal and smaller powers of two.
+ size_t metadataSize = divideRoundingUp(sizeof(Chunk), pageSize) * pageSize;
Object begin(chunk, metadataSize);
Object end(chunk, chunkSize);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes