2014-11-05 184 views
2

我试图以检测内存泄漏一MIPS32机器上运行Valgrind的。总可用内存为32MB(无交换)。问题在于Valgrind本身无法分配他需要的内存量,并且总是生成“内存不足”错误。设置内存限制Valgrind的

[email protected]# valgrind --leak-check=yes grep -r "foo" /etc/config/ 
==9392== Memcheck, a memory error detector 
==9392== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al. 
==9392== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info 
==9392== Command: grep -r foo /etc/config/ 
==9392== 
==9392== 
==9392==  Valgrind's memory management: out of memory: 
==9392==  initialiseSector(TC)'s request for 27597024 bytes failed. 
==9392==  20516864 bytes have already been allocated. 
==9392==  Valgrind cannot continue. Sorry. 
==9392== 
==9392==  There are several possible reasons for this. 
==9392==  - You have some kind of memory limit in place. Look at the 
==9392==  output of 'ulimit -a'. Is there a limit on the size of 
==9392==  virtual memory or address space? 
==9392==  - You have run out of swap space. 
==9392==  - Valgrind has a bug. If you think this is the case or you are 
==9392==  not sure, please let us know and we'll try to fix it. 
==9392==  Please note that programs can take substantially more memory than 
==9392==  normal when running under Valgrind tools, eg. up to twice or 
==9392==  more, depending on the tool. On a 64-bit machine, Valgrind 
==9392==  should be able to make use of up 32GB memory. On a 32-bit 
==9392==  machine, Valgrind should be able to use all the memory available 
==9392==  to a single process, up to 4GB if that's how you have your 
==9392==  kernel configured. Most 32-bit Linux setups allow a maximum of 
==9392==  3GB per process. 
==9392== 
==9392==  Whatever the reason, Valgrind cannot continue. Sorry. 

我想知道的是,如果有可能限制Valgrind分配的内存量。我试着玩--max-stacksize和--max-stackframe,但结果总是一样的。

+0

结帐这篇文章增加了Valgrind的内存限制:http://sourceforge.net/p/valgrind/mailman/message/27779126/ 你可能可以降低限制,做基本相同的事情。 – 2014-11-05 17:44:15

+1

32MB非常小。假设操作系统和其他进程需要一些内存,并且你的应用程序需要一些本身,这对valgrind来说并没有太多的帮助。 – 2014-11-05 17:47:00

回答

0

正如评论所说,32MB并不多。它必须涵盖操作系统和一些其他必要的过程。当用Valgrind/Memcheck分析一个程序时,它需要比程序自身更多的内存两倍的内存。这是因为Memcheck为每个分配位存储影子值,以便它可以识别未初始化的变量。

我认为最好的解决办法是编译程序为您的桌面计算机并从那里运行MEMCHECK。如果你的程序中有泄漏,未初始化的变量等,你也可以在你的台式机上安装它们。

如果你是好奇你的程序将如何表现在MIPS,与其他Valgrind的工具,如地块(随着时间测量堆)和Cachegrind(高速缓存性能)进行分析。这些比Memcheck重量轻得多。