Boost C++ Libraries: Ticket #9735: No need to memset to 0 after mmap to /dev/zero https://svn.boost.org/trac10/ticket/9735 <p> In boost source /libs/coroutine/detail/standard_stack_allocator_posix.cpp:120, it has the following snippet: </p> <div class="wiki-code"><div class="code"><pre> <span class="kt">void</span> <span class="o">*</span> <span class="n">limit</span> <span class="o">=</span> <span class="cp"># if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)</span> <span class="o">::</span><span class="n">mmap</span><span class="p">(</span> <span class="mi">0</span><span class="p">,</span> <span class="n">size_</span><span class="p">,</span> <span class="n">PROT_READ</span> <span class="o">|</span> <span class="n">PROT_WRITE</span><span class="p">,</span> <span class="n">MAP_PRIVATE</span> <span class="o">|</span> <span class="n">MAP_ANON</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span> <span class="cp"># else</span> <span class="o">::</span><span class="n">mmap</span><span class="p">(</span> <span class="mi">0</span><span class="p">,</span> <span class="n">size_</span><span class="p">,</span> <span class="n">PROT_READ</span> <span class="o">|</span> <span class="n">PROT_WRITE</span><span class="p">,</span> <span class="n">MAP_PRIVATE</span><span class="p">,</span> <span class="n">fd</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span> <span class="cp"># endif</span> <span class="o">::</span><span class="n">close</span><span class="p">(</span> <span class="n">fd</span><span class="p">);</span> <span class="k">if</span> <span class="p">(</span> <span class="o">!</span> <span class="n">limit</span><span class="p">)</span> <span class="n">throw</span> <span class="n">std</span><span class="o">::</span><span class="n">bad_alloc</span><span class="p">();</span> <span class="n">std</span><span class="o">::</span><span class="n">memset</span><span class="p">(</span> <span class="n">limit</span><span class="p">,</span> <span class="sc">&#39;\0&#39;</span><span class="p">,</span> <span class="n">size_</span><span class="p">);</span> </pre></div></div><p> Since mmap() with the MAP_PRIVATE flag implies a copy-on-write mechanism which ensures that memory pointed by limit will be initialized to all-zero. The additional memset slows down coroutine creation and makes coroutine not that lightweight. In this case of memseting ~64KB memory takes ~40us on my machine. And creating a coroutine takes ~50us. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9735 Trac 1.4.3 olli Tue, 04 Mar 2014 08:15:59 GMT <link>https://svn.boost.org/trac10/ticket/9735#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9735#comment:1</guid> <description> <p> I've added class standard_stack_allocator (using malloc/free) to the library. the class is the standard stack-allocator and on my machine (Core2 Q6700) creating a coroutine consumes ca. 200ns. </p> </description> <category>Ticket</category> </item> <item> <author>Tianlong Wu <rockuw@…></author> <pubDate>Tue, 04 Mar 2014 08:21:32 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9735#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9735#comment:2</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/9735#comment:1" title="Comment 1">olli</a>: </p> <blockquote class="citation"> <p> I've added class standard_stack_allocator (using malloc/free) to the library. the class is the standard stack-allocator and on my machine (Core2 Q6700) creating a coroutine consumes ca. 200ns. </p> </blockquote> <p> Good. When can we use it? Will it be checked into 1.55 or only trunk? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>olli</dc:creator> <pubDate>Fri, 07 Mar 2014 16:12:10 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/9735#comment:3 https://svn.boost.org/trac10/ticket/9735#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> will be in boost-1.56 thx, Oliver </p> Ticket