pthreads的虚拟内存消耗

发布于 2024-09-06 18:48:54 字数 308 浏览 7 评论 0原文

你好我开发了一个多线程TCP服务器应用程序,允许10个并发连接接收来自它们的连续请求,在处理一些请求后,将它们响应给客户端。我在基于 TI OMAP l137 处理器的板上运行它,它运行 Monta Vista Linux。线程是为每个客户端创建的,即 10 个线程,并且是预线程化的。根据 ps、top 和 meminfo,它的物理内存使用率约为 %1.5,CPU 使用率约为 %2。它的虚拟机使用量上升到 80M,而我有 48M(我从 u-boot 减少了它,为 DSP 保留一些内存)。任何帮助表示赞赏,我怎样才能减少它?。(/proc/sys/vm/..技巧没有帮助:)

谢谢。

Hello I developed a multi-threaded TCP server application that allows 10 concurrent connections receives continuous requests from them, after some processing requests, responds them to clients. I'm running it on a TI OMAP l137 processor based board it runs Monta Vista Linux. Threads are created per client ie 10 threads and it's pre-threaded. it's physical memory usage is about %1.5 and CPU usage is about %2 according to ps, top and meminfo. It's vm usage rises up to 80M where i have 48M (i reduced it from u-boot to reserve some mem for DSP). Any help is appreciated, how can i reduce it??.(/proc/sys/vm/.. tricks doesn't help :)

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寄居者 2024-09-13 18:48:54

您可以尝试使用 垃圾收集替代 malloc(),看看是否能解决您的问题。如果确实如此,请找到泄漏并修复它们,然后摆脱垃圾收集器。

在大多数堆分析器和分析器(例如 valgrind)不完全(如果有的话)支持的平台上追踪此类问题是“有趣的”。

另一方面,考虑到限制..我假设您已经减小了默认线程堆栈大小?我认为默认是8M,你可能不需要那么多。如果您尚未调整,请参阅 pthread_attr_setstacksize()

编辑

您可以使用 pthread_attr_getstacksize 检查默认堆栈大小()。如果它是 8M,那么您在线程创建期间就已经突破了上限(正如您提到的,10 个线程)。

You can try using a drop in garbage collecting replacement for malloc(), and see if that solves your problem. If it does, find the leaks and fix them, then get rid of the garbage collector.

Its 'interesting' to chase these kinds of problems on platforms that most heap analyzers and profilers (e.g. valgrind) don't fully (if at all) support.

On another note, given the constraints .. I'm assuming you have decreased the default thread stack size? I think the default is 8M, you probably don't need that much. See pthread_attr_setstacksize() if you haven't adjusted it.

Edit:

You can check the default stack size with pthread_attr_getstacksize(). If it is at 8M, you've already blown your ceiling during thread creation (10 threads, as you mentioned).

北座城市 2024-09-13 18:48:54

大多数虚拟机可能只是用于堆栈。当然,它是虚拟的,所以如果你不使用它,它就不会被提交。

(我想知道线程的默认堆栈大小是否与 ulimit -s 有关)

显然是的,根据
这个其他问题

Most VM is probably just for stacks. Of course, it's virtual, so it doesn't get commited if you don't use it.

(I'm wondering if thread's default stack size has anything to do with ulimit -s)

Apparently yes, according to
this other SO question

分開簡單 2024-09-13 18:48:54

它会上升到那个水平并保持在那里吗?或者它最终会耗尽内存吗?如果是前者,您只需要找到一种方法来拥有更小的工作集。如果是后者,则说明存在内存泄漏,需要修复它。

Does it rise to that level and stay there? Or does it eventually run out of memory? If the former, you simply need to figure out a way to have a smaller working set. If the latter, you have a memory leak and need to fix it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文