将内存限制设置为Valgrind

时间:2014-11-05 15:02:43

标签: out-of-memory mips valgrind

我试图在mips32机器上运行Valgrind以检测内存泄漏。总可用内存为32MB(无SWAP)。问题是Valgrind本身无法分配他所需的内存量,并且总是会产生内存不足的问题。错误。

root@babidi# 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,但结果总是一样。

1 个答案:

答案 0 :(得分:0)

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

我认为最好的解决方案是为您的台式计算机编译程序并从那里运行Memcheck。如果您的程序中有泄漏,未初始化的变量等,您也可以在台式计算机上使用它们。

如果您对程序在MIPS上的行为表示好奇,请使用其他Valgrind工具进行分析,例如Massif(测量堆随时间变化)和Cachegrind(缓存性能)。那些比Memcheck更轻盈。