Subject: [Boost-bugs] [Boost C++ Libraries] #9735: No need to memset to 0 after mmap to /dev/zero
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-03-04 07:22:01
#9735: No need to memset to 0 after mmap to /dev/zero
------------------------------------+-----------------------
Reporter: Tianlong Wu <rockuw@â¦> | Owner: olli
Type: Bugs | Status: new
Milestone: To Be Determined | Component: coroutine
Version: Boost 1.55.0 | Severity: Problem
Keywords: |
------------------------------------+-----------------------
In boost source
/libs/coroutine/detail/standard_stack_allocator_posix.cpp:120, it has the
following snippet:
{{{#!c
void * limit =
# if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
::mmap( 0, size_, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1,
0);
# else
::mmap( 0, size_, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
# endif
::close( fd);
if ( ! limit) throw std::bad_alloc();
std::memset( limit, '\0', size_);
}}}
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.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/9735> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:15 UTC