Opened 9 years ago
Closed 9 years ago
#9735 closed Bugs (fixed)
No need to memset to 0 after mmap to /dev/zero
Reported by: | Owned by: | olli | |
---|---|---|---|
Milestone: | To Be Determined | Component: | coroutine |
Version: | Boost 1.55.0 | Severity: | Problem |
Keywords: | Cc: |
Description
In boost source /libs/coroutine/detail/standard_stack_allocator_posix.cpp:120, it has the following snippet:
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.
Change History (3)
follow-up: 2 comment:1 by , 9 years ago
comment:2 by , 9 years ago
Replying to olli:
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.
Good. When can we use it? Will it be checked into 1.55 or only trunk?
comment:3 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
will be in boost-1.56 thx, Oliver
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.