[英]Boost thread memory usage on 64bit linux
一段时间以来,我一直在32位linux上使用Boost线程,并且到目前为止对它们的性能感到非常满意。 最近,该项目移至64位平台,我们看到内存使用量大幅度增加(从大约2.5gb增长到16-17gb)。 我完成了性能分析,发现升压线程是大量分配的源头。 每个线程分配的内存大约是32位上的10倍。
我使用valgrind的块进行了剖析,并已在单独的测试应用程序中仅使用boost线程确认了该问题。 我还尝试使用std :: threads代替,这些都没有出现大内存分配问题。
我想知道是否还有其他人已经看到这种行为并知道问题出在哪里? 谢谢。
这里没有问题。 这是虚拟内存,每个64位进程都可以在每个现代操作系统上分配TB的虚拟内存。 它基本上是免费的,没有理由担心它使用了多少。
它基本上只是线程堆栈的保留空间。 如果需要,可以通过更改默认堆栈大小来减小它。 但是绝对没有理由这么做。
使用pthread_attr_getstacksize查看。 使用boost :: thread :: attributes进行更改(pthread_attr_setstacksize)。
gdb boost.thread的示例
0 0x000000000040ffe0 in boost::detail::get_once_per_thread_epoch() ()
1 0x0000000000407c12 in void boost::call_once<void (*)()>(boost::once_flag&, void (*)()) [clone .constprop.120] ()
2 0x00000000004082cf in thread_proxy ()
3 0x000000000041120a in start_thread (arg=0x7ffff7ffd700) at pthread_create.c:308
4 0x00000000004c5cf9 in clone ()
5 0x0000000000000000 in ?? ()
您会发现data=malloc(sizeof(boost::uintmax_t));
在get_once_per_thread_epoch( boost_1_50_0 / libs / thread / src / pthread / once.cpp )中
继续
1 0x000000000041a0d3 in new_heap ()
2 0x000000000041b045 in arena_get2.isra.5.part.6 ()
3 0x000000000041ed13 in malloc ()
4 0x0000000000401b1a in test () at pthread_malloc_8byte.cc:9
5 0x0000000000402d3a in start_thread (arg=0x7ffff7ffd700) at pthread_create.c:308
6 0x00000000004413d9 in clone ()
7 0x0000000000000000 in ?? ()
在new_heap函数( glibc-2.15 \\ malloc \\ arena.c )中,它将为64位操作系统中的每个线程预映射 64M内存。 换句话说,每个线程将使用64M + 8M(默认线程堆栈)= 72M 。
glibc-2.15\ChangeLog.17
2009-03-13 Ulrich Drepper <drepper@redhat.com>
* malloc/malloc.c: Implement PER_THREAD and ATOMIC_FASTBINS features.
* malloc/arena.c: Likewise.
* malloc/hooks.c: Likewise.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.