Boost C++ Libraries: Ticket #1252: [pool] severe overhead with unaligned sizes. https://svn.boost.org/trac10/ticket/1252 <p> Pool will set the size of allocated blocks to the least common multiple of the requested size and LCM(sizeof(void*), sizeof(size_t)). </p> <p> Request a block size of 1500 on a 32-bit system and you get 1500 byte blocks. Request 1501 bytes and you get 6004 byte blocks - and the extra space isn't ever used. It is obviously even more pronounced on a 64-bit system. </p> <p> I believe the intent of the author was to align block sizes, not to use LCM. I propose changing pool.hpp:183 from </p> <p> <code>return details::pool::lcm&lt;size_type&gt;(requested_size, min_size);</code> </p> <p> to </p> <p> <code>return requested_size + (min_size - 1) &amp; ~(min_size - 1);</code> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1252 Trac 1.4.3 Marshall Clow Wed, 21 Nov 2007 00:12:00 GMT component changed; owner set https://svn.boost.org/trac10/ticket/1252#comment:1 https://svn.boost.org/trac10/ticket/1252#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Marshall Clow</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">pool</span> </li> </ul> Ticket cnewbold@… Thu, 27 Mar 2008 13:14:26 GMT <link>https://svn.boost.org/trac10/ticket/1252#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1252#comment:2</guid> <description> <p> I see the milestone for this is set to 1.35.0; does that mean that a fix for this problem has been (or will be) included in the upcoming release? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Tue, 01 Apr 2008 22:16:47 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1252#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1252#comment:3</guid> <description> <p> No - this fix did not make in into 1.35. I need to write a test case to make sure that this does, indeed, fix the problem. Unless you would like to write one? ;-) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Wed, 17 Sep 2008 03:08:34 GMT</pubDate> <title>status, milestone changed https://svn.boost.org/trac10/ticket/1252#comment:4 https://svn.boost.org/trac10/ticket/1252#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.36.0</span> → <span class="trac-field-new">Boost 1.37.0</span> </li> </ul> <p> Reading the design documents at <a href="http://www.boost.org/doc/libs/1_36_0/libs/pool/doc/implementation/alignment.html">http://www.boost.org/doc/libs/1_36_0/libs/pool/doc/implementation/alignment.html</a>, I'm not convinced that you are correct. </p> <p> Please read that page and tell me what you think. </p> Ticket Chris Newbold Mon, 22 Sep 2008 20:18:31 GMT cc set https://svn.boost.org/trac10/ticket/1252#comment:5 https://svn.boost.org/trac10/ticket/1252#comment:5 <ul> <li><strong>cc</strong> <span class="trac-author">Chris Newbold</span> added </li> </ul> <p> Here are my thoughts... </p> <p> I believe that the design outlined in the linked documents is sound, including the use of LCM to find the chunk size which will satisfy the alignment requirements of the free list pointer and block size. </p> <p> The problem with the original design is using requested_size in the LCM computation. Just because I asked for chunks of X bytes does not mean that each chunk must be aligned on an X byte boundary. </p> <p> Predicate 2 of the "Guaranteeing Alignment" document quotes language from 5.3.4/10 of the C++ standard indicating that memory obtained in a 'new' expression must be aligned on a boundary that is a multiple of that required by the type with the most stringent alignment requirement. On most platforms, this is going to be double, or long long, or maybe long double. </p> <p> The point being that the "worst-case" scenario is that the programmer tries to lay down a structure at the start of a chunk obtained from the pool and that structure has an element of such a type. </p> <p> This is exactly what malloc() or operator new() does. I do not think that the pool needs to do anything more. </p> <p> The proposed change in this ticket, however, is not correct. It does not account for the possibility that some type may have a more stringent alignment requirement than the free-list pointer and/or block size value. </p> Ticket Chris Newbold Mon, 22 Sep 2008 20:25:08 GMT <link>https://svn.boost.org/trac10/ticket/1252#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1252#comment:6</guid> <description> <p> As an aside, a couple of months back I stepped up and volunteered to take owner maintainership of Boost.Pool since it appeared to have been orphaned. If you'd like to wash your hands of this, just assign the ticket to me. :) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 22 Sep 2008 20:50:25 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1252#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1252#comment:7</guid> <description> <p> Sorry, I just got around to seeing this. I agree with cnewbold. </p> <p> I think the alignment should be align(max(min_size, min(requested_size, sizeof(max_type))), 2). </p> <p> I'm not familiar with other platforms but on x86/x64, sizeof(max_type) is now 32 bytes (for the new AVX instructions from Intel). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Chris Newbold</dc:creator> <pubDate>Tue, 23 Sep 2008 14:52:07 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1252#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1252#comment:8</guid> <description> <p> What is max_type? </p> <p> After some further thought, I think that a clean solution would be to leverage alignment_of from Boost.Typetraits. </p> <p> Change: </p> <pre class="wiki">return details::pool::lcm&lt;size_type&gt;(requested_size, min_size); </pre><p> to: </p> <pre class="wiki">return details::pool::lcm&lt;size_type&gt;(alignment_of(requested_size), min_size); </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Chris Newbold</dc:creator> <pubDate>Mon, 29 Sep 2008 20:34:30 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1252#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1252#comment:9</guid> <description> <p> Marshall-- </p> <p> I'm currently in the pool code fixing several other tickets and, if you like and if you think that my suggested fix above is correct, I'd be happy to apply it and write some test cases. Let me know... Thanks. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Mon, 29 Sep 2008 21:03:08 GMT</pubDate> <title>owner, status changed https://svn.boost.org/trac10/ticket/1252#comment:10 https://svn.boost.org/trac10/ticket/1252#comment:10 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Marshall Clow</span> to <span class="trac-author">Chris Newbold</span> </li> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">new</span> </li> </ul> <p> Works for me - especially the tests. Pool seems to be lacking in tests. ;-) </p> Ticket Chris Newbold Wed, 08 Oct 2008 15:59:43 GMT status, milestone changed https://svn.boost.org/trac10/ticket/1252#comment:11 https://svn.boost.org/trac10/ticket/1252#comment:11 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.37.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> <p> Not going to make 1.37; the changes are somewhat delicate and I'd like to have some bake time before releasing. </p> Ticket klin <kevin.ic@…> Sat, 02 May 2009 10:03:44 GMT cc changed https://svn.boost.org/trac10/ticket/1252#comment:12 https://svn.boost.org/trac10/ticket/1252#comment:12 <ul> <li><strong>cc</strong> <span class="trac-author">kevin.ic@…</span> added </li> </ul> <p> Would it be more efficient to simply ignore the alignment requirements for the pointers, and just copy in and out of the memory using aligned addresses before using them? </p> <p> So we can always allocate in multiples of requested_size (large enough to cover min_size). Then, to access embedded data such as the next pointer, we can do: </p> <pre class="wiki">void* get_nextof(void const* ptr) { void* p; memcpy(&amp;p, ptr, sizeof(void*)); return p; } </pre><p> Seems like the copying penalty would be worth it for a more reasonable overhead. </p> Ticket John Maddock Fri, 07 Jan 2011 11:21:00 GMT cc changed https://svn.boost.org/trac10/ticket/1252#comment:13 https://svn.boost.org/trac10/ticket/1252#comment:13 <ul> <li><strong>cc</strong> <span class="trac-author">boostpool@…</span> added </li> </ul> Ticket John Maddock Tue, 15 Feb 2011 19:03:05 GMT <link>https://svn.boost.org/trac10/ticket/1252#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1252#comment:14</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/68922" title="Add test case for issue #1252. Refs #1252.">[68922]</a>) Add test case for issue <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1252" title="#1252: Bugs: [pool] severe overhead with unaligned sizes. (closed: fixed)">#1252</a>. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1252" title="#1252: Bugs: [pool] severe overhead with unaligned sizes. (closed: fixed)">#1252</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Thu, 24 Feb 2011 10:25:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1252#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1252#comment:15</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/69235" title="Fixes issue #1252. Add test case for #1252. Update docs accordingly. ...">[69235]</a>) Fixes issue <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1252" title="#1252: Bugs: [pool] severe overhead with unaligned sizes. (closed: fixed)">#1252</a>. Add test case for <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1252" title="#1252: Bugs: [pool] severe overhead with unaligned sizes. (closed: fixed)">#1252</a>. Update docs accordingly. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1252" title="#1252: Bugs: [pool] severe overhead with unaligned sizes. (closed: fixed)">#1252</a>. Correct return value from test_pool_alloc.cpp. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Tue, 02 Aug 2011 17:04:12 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/1252#comment:16 https://svn.boost.org/trac10/ticket/1252#comment:16 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/73495" title="Merge updated Pool lib from trunk. Fixes #1252. Fixes #2696. Fixes ...">[73495]</a>) Merge updated Pool lib from trunk. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1252" title="#1252: Bugs: [pool] severe overhead with unaligned sizes. (closed: fixed)">#1252</a>. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2696" title="#2696: Bugs: max_size for boost pool (closed: fixed)">#2696</a>. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4960" title="#4960: Bugs: boost::pool_allocator for vector of vectors exhausts memory (closed: fixed)">#4960</a>. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5526" title="#5526: Bugs: fast_pool_allocator crash (closed: fixed)">#5526</a>. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5568" title="#5568: Bugs: singleton_pool doesn't propagate MaxSize value to his pool (closed: fixed)">#5568</a>. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5700" title="#5700: Bugs: warning in object_pool.hpp:56 (closed: fixed)">#5700</a>. </p> Ticket Jonathan Jones <jonathan.jones@…> Wed, 01 Aug 2012 20:05:03 GMT cc changed https://svn.boost.org/trac10/ticket/1252#comment:17 https://svn.boost.org/trac10/ticket/1252#comment:17 <ul> <li><strong>cc</strong> <span class="trac-author">jonathan.jones@…</span> added </li> </ul> Ticket