Chinaunix首页 | 论坛 | 博客
  • 博客访问: 52449
  • 博文数量: 6
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 70
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-15 19:11
文章分类

全部博文(6)

文章存档

2015年(6)

我的朋友

分类: C/C++

2015-06-15 21:11:22

之前写了一个多线程的应用,使用的boost asio异步,发现使用的过程中linux glibc自带的malloc性能很差,
替换为tcmlloc,性能得到比较大的提升。

但是最近突然发现有时候内存增长到几个G,开始以为是内存泄露的问题,用valgrind做了大量的测试,发现
内存虽然有时候会飙升到几个G,但是valgrind显示没有内存泄露。

最后怀疑是tcmalloc缓存了这部分内存,仔细研读了tcmlloc文档和部分源码,发现了这个

Releasing Memory Back to the System

By default, tcmalloc will release no-longer-used memory back to the kernel gradually, over time. The  MallocExtension::instance()->ReleaseFreeMemory();

You can also call SetMemoryReleaseRate() to change the tcmalloc_release_rate value at runtime, or GetMemoryReleaseRate to see what the current release rate is.


TCMALLOC_RELEASE_RATE default: 1.0 Rate at which we release unused memory to the system, via madvise(MADV_DONTNEED), on systems that support it. Zero means we never release memory back to the system. Increase this flag to return memory faster; decrease it to return memory slower. Reasonable rates are in the range [0,10].


tcmalloc将逐渐的释放内存,释放的速度取决于tcmalloc_release_rate,合理情况下一般情况是0-10,另外可以手动的在你的application
中调用
   MallocExtension::instance()->ReleaseFreeMemory()
强制释放。
最后在代码中加入了ReleaseFreeMemory,问题解决




阅读(9473) | 评论(0) | 转发(0) |
0

上一篇:mysql主从复制源码分析(4)

下一篇:没有了

给主人留下些什么吧!~~