<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[175751] trunk/Source/bmalloc</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/175751">175751</a></dd>
<dt>Author</dt> <dd>ggaren@apple.com</dd>
<dt>Date</dt> <dd>2014-11-07 10:12:40 -0800 (Fri, 07 Nov 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>bmalloc uses 8X more virtual memory than necessary
https://bugs.webkit.org/show_bug.cgi?id=138495

Reviewed by Mark Lam.

iOS has a per-process virtual memory cap around 1GB, so there's some
value to not going totally ham with virtual memory.

We currently use about 8X the necessary amount:
    - 2X to align our VM allocation
    - 4X to reserve small / medium / (2) large chunk VM ranges per superchunk

We can cut that down:
    - Return the unaligned portion of our VM allocation (-2X)
    - Use all the chunks in a superchunk, instead of allocating one
      chunk per superchunk (-4X)

* bmalloc/Algorithm.h:
(bmalloc::roundUpToMultipleOf): Added a non-constant version of this
function so we can call it with getpagesize() at runtime.

* bmalloc/Chunk.h:
* bmalloc/LargeChunk.h:
(bmalloc::LargeChunk::create): Deleted. Instead of each chunk allocating
its own VM, VMHeap allocates the superchunk and all the chunks in it at a time.

* bmalloc/VMAllocate.h:
(bmalloc::vmValidate):
(bmalloc::vmAllocate): ASSERT that mmap succeeds to make crashes clearer
if it does not succeed. Allocate precisely, and give back the extra.

* bmalloc/VMHeap.cpp:
(bmalloc::VMHeap::allocateSuperChunk):
(bmalloc::VMHeap::allocateSmallChunk): Deleted.
(bmalloc::VMHeap::allocateMediumChunk): Deleted.
(bmalloc::VMHeap::allocateLargeChunk): Deleted. Use all the chunks
in a superchunk, instead of just one.

* bmalloc/VMHeap.h:
(bmalloc::VMHeap::allocateSmallPage):
(bmalloc::VMHeap::allocateMediumPage):
(bmalloc::VMHeap::allocateLargeRange):
* bmalloc/XLargeChunk.h:
(bmalloc::XLargeChunk::create): Updated to match changes above.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourcebmallocChangeLog">trunk/Source/bmalloc/ChangeLog</a></li>
<li><a href="#trunkSourcebmallocbmallocAlgorithmh">trunk/Source/bmalloc/bmalloc/Algorithm.h</a></li>
<li><a href="#trunkSourcebmallocbmallocChunkh">trunk/Source/bmalloc/bmalloc/Chunk.h</a></li>
<li><a href="#trunkSourcebmallocbmallocLargeChunkh">trunk/Source/bmalloc/bmalloc/LargeChunk.h</a></li>
<li><a href="#trunkSourcebmallocbmallocVMAllocateh">trunk/Source/bmalloc/bmalloc/VMAllocate.h</a></li>
<li><a href="#trunkSourcebmallocbmallocVMHeapcpp">trunk/Source/bmalloc/bmalloc/VMHeap.cpp</a></li>
<li><a href="#trunkSourcebmallocbmallocVMHeaph">trunk/Source/bmalloc/bmalloc/VMHeap.h</a></li>
<li><a href="#trunkSourcebmallocbmallocXLargeChunkh">trunk/Source/bmalloc/bmalloc/XLargeChunk.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourcebmallocChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/ChangeLog (175750 => 175751)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/ChangeLog        2014-11-07 18:10:54 UTC (rev 175750)
+++ trunk/Source/bmalloc/ChangeLog        2014-11-07 18:12:40 UTC (rev 175751)
</span><span class="lines">@@ -1,3 +1,50 @@
</span><ins>+2014-11-07  Geoffrey Garen  &lt;ggaren@apple.com&gt;
+
+        bmalloc uses 8X more virtual memory than necessary
+        https://bugs.webkit.org/show_bug.cgi?id=138495
+
+        Reviewed by Mark Lam.
+
+        iOS has a per-process virtual memory cap around 1GB, so there's some
+        value to not going totally ham with virtual memory.
+
+        We currently use about 8X the necessary amount:
+            - 2X to align our VM allocation
+            - 4X to reserve small / medium / (2) large chunk VM ranges per superchunk
+
+        We can cut that down:
+            - Return the unaligned portion of our VM allocation (-2X)
+            - Use all the chunks in a superchunk, instead of allocating one
+              chunk per superchunk (-4X)
+
+        * bmalloc/Algorithm.h:
+        (bmalloc::roundUpToMultipleOf): Added a non-constant version of this
+        function so we can call it with getpagesize() at runtime.
+
+        * bmalloc/Chunk.h:
+        * bmalloc/LargeChunk.h:
+        (bmalloc::LargeChunk::create): Deleted. Instead of each chunk allocating
+        its own VM, VMHeap allocates the superchunk and all the chunks in it at a time.
+
+        * bmalloc/VMAllocate.h:
+        (bmalloc::vmValidate):
+        (bmalloc::vmAllocate): ASSERT that mmap succeeds to make crashes clearer
+        if it does not succeed. Allocate precisely, and give back the extra.
+
+        * bmalloc/VMHeap.cpp:
+        (bmalloc::VMHeap::allocateSuperChunk):
+        (bmalloc::VMHeap::allocateSmallChunk): Deleted.
+        (bmalloc::VMHeap::allocateMediumChunk): Deleted.
+        (bmalloc::VMHeap::allocateLargeChunk): Deleted. Use all the chunks
+        in a superchunk, instead of just one.
+
+        * bmalloc/VMHeap.h:
+        (bmalloc::VMHeap::allocateSmallPage):
+        (bmalloc::VMHeap::allocateMediumPage):
+        (bmalloc::VMHeap::allocateLargeRange):
+        * bmalloc/XLargeChunk.h:
+        (bmalloc::XLargeChunk::create): Updated to match changes above.
+
</ins><span class="cx"> 2014-11-01  David Kilzer  &lt;ddkilzer@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         JavaScriptCore is missing debug info for bmalloc because libbmalloc.a is stripped
</span></span></pre></div>
<a id="trunkSourcebmallocbmallocAlgorithmh"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/bmalloc/Algorithm.h (175750 => 175751)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/bmalloc/Algorithm.h        2014-11-07 18:10:54 UTC (rev 175750)
+++ trunk/Source/bmalloc/bmalloc/Algorithm.h        2014-11-07 18:12:40 UTC (rev 175751)
</span><span class="lines">@@ -62,10 +62,16 @@
</span><span class="cx">     return !!(reinterpret_cast&lt;uintptr_t&gt;(value) &amp; mask);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+template&lt;typename T&gt; inline T roundUpToMultipleOf(size_t divisor, T x)
+{
+    BASSERT(divisor &amp;&amp; !(divisor &amp; (divisor - 1)));
+    return reinterpret_cast&lt;T&gt;((reinterpret_cast&lt;uintptr_t&gt;(x) + (divisor - 1ul)) &amp; ~(divisor - 1ul));
+}
+
</ins><span class="cx"> template&lt;size_t divisor, typename T&gt; inline constexpr T roundUpToMultipleOf(T x)
</span><span class="cx"> {
</span><span class="cx">     static_assert(divisor &amp;&amp; !(divisor &amp; (divisor - 1)), &quot;'divisor' must be a power of two.&quot;);
</span><del>-    return reinterpret_cast&lt;T&gt;((reinterpret_cast&lt;uintptr_t&gt;(x) + (divisor - 1ul)) &amp; ~(divisor - 1ul));
</del><ins>+    return roundUpToMultipleOf(divisor, x);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> template&lt;size_t divisor, typename T&gt; inline constexpr T roundDownToMultipleOf(T x)
</span></span></pre></div>
<a id="trunkSourcebmallocbmallocChunkh"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/bmalloc/Chunk.h (175750 => 175751)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/bmalloc/Chunk.h        2014-11-07 18:10:54 UTC (rev 175750)
+++ trunk/Source/bmalloc/bmalloc/Chunk.h        2014-11-07 18:12:40 UTC (rev 175751)
</span><span class="lines">@@ -42,7 +42,6 @@
</span><span class="cx">     static const size_t chunkOffset = Traits::chunkOffset;
</span><span class="cx">     static const uintptr_t chunkMask = Traits::chunkMask;
</span><span class="cx"> 
</span><del>-    static Chunk* create();
</del><span class="cx">     static Chunk* get(void*);
</span><span class="cx"> 
</span><span class="cx">     Page* begin() { return Page::get(Line::get(m_memory)); }
</span><span class="lines">@@ -67,14 +66,6 @@
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> template&lt;class Traits&gt;
</span><del>-inline auto Chunk&lt;Traits&gt;::create() -&gt; Chunk*
-{
-    size_t vmSize = bmalloc::vmSize(chunkSize);
-    std::pair&lt;void*, Range&gt; result = vmAllocate(vmSize, superChunkSize, chunkOffset);
-    return new (result.first) Chunk;
-}
-
-template&lt;class Traits&gt;
</del><span class="cx"> inline auto Chunk&lt;Traits&gt;::get(void* object) -&gt; Chunk*
</span><span class="cx"> {
</span><span class="cx">     BASSERT(isSmallOrMedium(object));
</span></span></pre></div>
<a id="trunkSourcebmallocbmallocLargeChunkh"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/bmalloc/LargeChunk.h (175750 => 175751)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/bmalloc/LargeChunk.h        2014-11-07 18:10:54 UTC (rev 175750)
+++ trunk/Source/bmalloc/bmalloc/LargeChunk.h        2014-11-07 18:12:40 UTC (rev 175751)
</span><span class="lines">@@ -70,13 +70,6 @@
</span><span class="cx">     alignas(vmPageSize) char m_memory[];
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-inline LargeChunk* LargeChunk::create()
-{
-    size_t vmSize = bmalloc::vmSize(largeChunkSize);
-    std::pair&lt;void*, Range&gt; result = vmAllocate(vmSize, superChunkSize, largeChunkOffset);
-    return new (result.first) LargeChunk;
-}
-
</del><span class="cx"> inline LargeChunk* LargeChunk::get(void* object)
</span><span class="cx"> {
</span><span class="cx">     BASSERT(!isSmallOrMedium(object));
</span></span></pre></div>
<a id="trunkSourcebmallocbmallocVMAllocateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/bmalloc/VMAllocate.h (175750 => 175751)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/bmalloc/VMAllocate.h        2014-11-07 18:10:54 UTC (rev 175750)
+++ trunk/Source/bmalloc/bmalloc/VMAllocate.h        2014-11-07 18:12:40 UTC (rev 175751)
</span><span class="lines">@@ -43,20 +43,24 @@
</span><span class="cx"> {
</span><span class="cx">     return roundUpToMultipleOf&lt;vmPageSize&gt;(size);
</span><span class="cx"> }
</span><del>-    
</del><ins>+
</ins><span class="cx"> inline void vmValidate(size_t vmSize)
</span><span class="cx"> {
</span><ins>+    // We use getpagesize() here instead of vmPageSize because vmPageSize is
+    // allowed to be larger than the OS's true page size.
+
</ins><span class="cx">     UNUSED(vmSize);
</span><span class="cx">     BASSERT(vmSize);
</span><del>-    BASSERT(vmSize == bmalloc::vmSize(vmSize));
</del><ins>+    BASSERT(vmSize == roundUpToMultipleOf(static_cast&lt;size_t&gt;(getpagesize()), vmSize));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline void vmValidate(void* p, size_t vmSize)
</span><span class="cx"> {
</span><ins>+    // We use getpagesize() here instead of vmPageSize because vmPageSize is
+    // allowed to be larger than the OS's true page size.
+
</ins><span class="cx">     vmValidate(vmSize);
</span><span class="cx">     
</span><del>-    // We use getpagesize() here instead of vmPageSize because vmPageSize is
-    // allowed to be larger than the OS's true page size.
</del><span class="cx">     UNUSED(p);
</span><span class="cx">     BASSERT(p);
</span><span class="cx">     BASSERT(p == mask(p, ~(getpagesize() - 1)));
</span><span class="lines">@@ -65,7 +69,9 @@
</span><span class="cx"> inline void* vmAllocate(size_t vmSize)
</span><span class="cx"> {
</span><span class="cx">     vmValidate(vmSize);
</span><del>-    return mmap(0, vmSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, BMALLOC_VM_TAG, 0);
</del><ins>+    void* result = mmap(0, vmSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, BMALLOC_VM_TAG, 0);
+    RELEASE_BASSERT(result != MAP_FAILED);
+    return result;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline void vmDeallocate(void* p, size_t vmSize)
</span><span class="lines">@@ -74,30 +80,28 @@
</span><span class="cx">     munmap(p, vmSize);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-// Allocates vmSize bytes at a specified offset from a power-of-two alignment.
-// Use this function to create pointer masks that aren't simple powers of two.
</del><ins>+// Allocates vmSize bytes at a specified power-of-two alignment.
+// Use this function to create maskable memory regions.
</ins><span class="cx"> 
</span><del>-inline std::pair&lt;void*, Range&gt; vmAllocate(size_t vmSize, size_t alignment, size_t offset)
</del><ins>+inline void* vmAllocate(size_t vmSize, size_t vmAlignment)
</ins><span class="cx"> {
</span><span class="cx">     vmValidate(vmSize);
</span><del>-    BASSERT(isPowerOfTwo(alignment));
</del><ins>+    vmValidate(vmAlignment);
</ins><span class="cx"> 
</span><del>-    size_t mappedSize = std::max(vmSize, alignment) + alignment;
</del><ins>+    size_t mappedSize = std::max(vmSize, vmAlignment) + vmAlignment;
</ins><span class="cx">     char* mapped = static_cast&lt;char*&gt;(vmAllocate(mappedSize));
</span><ins>+    char* mappedEnd = mapped + mappedSize;
+
+    char* aligned = roundUpToMultipleOf(vmAlignment, mapped);
+    char* alignedEnd = aligned + vmSize;
</ins><span class="cx">     
</span><del>-    uintptr_t alignmentMask = alignment - 1;
-    if (!test(mapped, alignmentMask) &amp;&amp; offset + vmSize &lt;= alignment) {
-        // We got two perfectly aligned regions. Give one back to avoid wasting
-        // VM unnecessarily. This isn't costly because we aren't making holes.
-        vmDeallocate(mapped + alignment, alignment);
-        return std::make_pair(mapped + offset, Range(mapped, alignment));
-    }
</del><ins>+    if (size_t leftExtra = aligned - mapped)
+        vmDeallocate(mapped, leftExtra);
+    
+    if (size_t rightExtra = mappedEnd - alignedEnd)
+        vmDeallocate(alignedEnd, rightExtra);
</ins><span class="cx"> 
</span><del>-    // We got an unaligned region. Keep the whole thing to avoid creating holes,
-    // and hopefully realign the VM allocator for future allocations. On Darwin,
-    // VM holes trigger O(N^2) behavior in mmap, so we want to minimize them.
-    char* mappedAligned = mask(mapped, ~alignmentMask) + alignment;
-    return std::make_pair(mappedAligned + offset, Range(mapped, mappedSize));
</del><ins>+    return aligned;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline void vmDeallocatePhysicalPages(void* p, size_t vmSize)
</span></span></pre></div>
<a id="trunkSourcebmallocbmallocVMHeapcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/bmalloc/VMHeap.cpp (175750 => 175751)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/bmalloc/VMHeap.cpp        2014-11-07 18:10:54 UTC (rev 175750)
+++ trunk/Source/bmalloc/bmalloc/VMHeap.cpp        2014-11-07 18:12:40 UTC (rev 175751)
</span><span class="lines">@@ -36,24 +36,20 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void VMHeap::allocateSmallChunk()
</del><ins>+void VMHeap::allocateSuperChunk()
</ins><span class="cx"> {
</span><del>-    SmallChunk* chunk = SmallChunk::create();
-    for (auto* it = chunk-&gt;begin(); it != chunk-&gt;end(); ++it)
</del><ins>+    char* superChunk = static_cast&lt;char*&gt;(vmAllocate(superChunkSize, superChunkSize));
+
+    SmallChunk* smallChunk = new (superChunk + smallChunkOffset) SmallChunk;
+    for (auto* it = smallChunk-&gt;begin(); it != smallChunk-&gt;end(); ++it)
</ins><span class="cx">         m_smallPages.push(it);
</span><del>-}
</del><span class="cx"> 
</span><del>-void VMHeap::allocateMediumChunk()
-{
-    MediumChunk* chunk = MediumChunk::create();
-    for (auto* it = chunk-&gt;begin(); it != chunk-&gt;end(); ++it)
</del><ins>+    MediumChunk* mediumChunk = new (superChunk + mediumChunkOffset) MediumChunk;
+    for (auto* it = mediumChunk-&gt;begin(); it != mediumChunk-&gt;end(); ++it)
</ins><span class="cx">         m_mediumPages.push(it);
</span><del>-}
</del><span class="cx"> 
</span><del>-Range VMHeap::allocateLargeChunk()
-{
-    LargeChunk* chunk = LargeChunk::create();
-    return BoundaryTag::init(chunk);
</del><ins>+    LargeChunk* largeChunk = new (superChunk + largeChunkOffset) LargeChunk;
+    m_largeRanges.insert(BoundaryTag::init(largeChunk));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace bmalloc
</span></span></pre></div>
<a id="trunkSourcebmallocbmallocVMHeaph"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/bmalloc/VMHeap.h (175750 => 175751)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/bmalloc/VMHeap.h        2014-11-07 18:10:54 UTC (rev 175750)
+++ trunk/Source/bmalloc/bmalloc/VMHeap.h        2014-11-07 18:12:40 UTC (rev 175751)
</span><span class="lines">@@ -54,9 +54,7 @@
</span><span class="cx">     void deallocateLargeRange(std::unique_lock&lt;StaticMutex&gt;&amp;, Range);
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    void allocateSmallChunk();
-    void allocateMediumChunk();
-    Range allocateLargeChunk();
</del><ins>+    void allocateSuperChunk();
</ins><span class="cx"> 
</span><span class="cx">     Vector&lt;SmallPage*&gt; m_smallPages;
</span><span class="cx">     Vector&lt;MediumPage*&gt; m_mediumPages;
</span><span class="lines">@@ -66,7 +64,7 @@
</span><span class="cx"> inline SmallPage* VMHeap::allocateSmallPage()
</span><span class="cx"> {
</span><span class="cx">     if (!m_smallPages.size())
</span><del>-        allocateSmallChunk();
</del><ins>+        allocateSuperChunk();
</ins><span class="cx"> 
</span><span class="cx">     return m_smallPages.pop();
</span><span class="cx"> }
</span><span class="lines">@@ -74,7 +72,7 @@
</span><span class="cx"> inline MediumPage* VMHeap::allocateMediumPage()
</span><span class="cx"> {
</span><span class="cx">     if (!m_mediumPages.size())
</span><del>-        allocateMediumChunk();
</del><ins>+        allocateSuperChunk();
</ins><span class="cx"> 
</span><span class="cx">     return m_mediumPages.pop();
</span><span class="cx"> }
</span><span class="lines">@@ -82,8 +80,11 @@
</span><span class="cx"> inline Range VMHeap::allocateLargeRange(size_t size)
</span><span class="cx"> {
</span><span class="cx">     Range range = m_largeRanges.take(size);
</span><del>-    if (!range)
-        range = allocateLargeChunk();
</del><ins>+    if (!range) {
+        allocateSuperChunk();
+        range = m_largeRanges.take(size);
+        BASSERT(range);
+    }
</ins><span class="cx">     return range;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourcebmallocbmallocXLargeChunkh"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/bmalloc/XLargeChunk.h (175750 => 175751)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/bmalloc/XLargeChunk.h        2014-11-07 18:10:54 UTC (rev 175750)
+++ trunk/Source/bmalloc/bmalloc/XLargeChunk.h        2014-11-07 18:12:40 UTC (rev 175751)
</span><span class="lines">@@ -56,8 +56,8 @@
</span><span class="cx"> inline XLargeChunk* XLargeChunk::create(size_t size)
</span><span class="cx"> {
</span><span class="cx">     size_t vmSize = bmalloc::vmSize(sizeof(XLargeChunk) + size);
</span><del>-    std::pair&lt;void*, Range&gt; result = vmAllocate(vmSize, superChunkSize, largeChunkOffset);
-    return new (result.first) XLargeChunk(result.second, size);
</del><ins>+    auto xlargeChunk = vmAllocate(vmSize, superChunkSize);
+    return new (xlargeChunk) XLargeChunk(Range(xlargeChunk, vmSize), size);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline void XLargeChunk::destroy(XLargeChunk* chunk)
</span></span></pre>
</div>
</div>

</body>
</html>