Linux 中的 malloc 挂起
我在一台具有 16 G 内存和 2 个四核 CPU 的机器上使用 SUSE 10 Linux。 有 8 个进程正在执行一些工作(CPU 密集型/网络 I/O)。其中 4 个存在内存泄漏(这些是测试条件,因此这里发生泄漏没有问题)。 所有进程占用的总空间约为15.4G,系统中仅200MB可用。 几个小时内一切都很好。但之后 malloc 挂起(对于没有内存泄漏的进程)。 卡住了超过 4 分钟(注意 CPU 不是 100%,但 io 明显上升)。 现在挂起的进程没有问题(它没有损坏内存)。 malloc 在做什么? (它是否试图进行碎片整理或建立交换空间)。
有什么指点吗?
I am using SUSE 10 Linux on a machine with 16 G ram and 2 quad core CPUs.
There are 8 processes which are doing some work (CPU intensive/network i/o). Out of which 4 have a memory leak (These are test conditions so no problem in having leaks here).
Total space is occupied by all processes is around 15.4 G only 200 MB is free in system.
Things are fine for some hours. But after that malloc hangs (for a process which doesn't have a memory leak).
Its stuck for more than 4 minutes (Note CPU is not 100% but io has gone up signficantly).
Now there is no problem in the hanged process (it has not corrupted the memory).
What is malloc doing? (is it trying to defragment or building up swap space).
Any pointers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在你的机器之前,内存的寿命很短。现在你的 malloc 超出了你机器的 16G 限制,你的系统开始交换。
但按照 PierreBdR 的提示检查您的申请无疑是个好主意。
Before you machine was just short on life RAM. Now your malloc goes beyond the 16G limit of your machine and your system starts swapping.
But checking your application as hinted by PierreBdR is certainly a good idea.
这可能很烦人,但我建议在阻塞的进程上使用 Valgrind。可能存在您之前未检测到的错误。至少,您可能知道正在发生什么。然而,这几个小时可能会变成几天:/
It might be annoying, but I would recommend using Valgrind on the process that blocks. There might be errors you didn't detect before. At least, you might have an idea of what is happening. However, the few hours might become days :/
如果
malloc()
只是花费很长时间,那么您可能正在遍历一个碎片化的空闲列表,其中许多条目已被换出。这与低 CPU、高 IO 和有限的可用 RAM 是一致的。有关
malloc()
实现的更多信息(包括了解碎片空闲列表),维基百科文章很好:http://en.wikipedia.org/wiki/Malloc#Implementations哦,内存泄漏是不可接受的,即使在测试环境中也是如此。正如您所看到的,它们会干扰(据您所知)没有泄漏的程序,并浪费您的时间。
If
malloc()
simply takes a long time, you're probably traversing a fragmented free list, many of whose entries have been swapped out. That is consistent with low CPU, high IO, and limited free RAM.For more information on
malloc()
implementations (including understanding fragmented free lists), the Wikipedia article is good: http://en.wikipedia.org/wiki/Malloc#ImplementationsOh, and memory leaks aren't acceptable, even in a test environment. As you can see, they're interfering with programs that (as far as you know) don't have leaks, and costing you time.