2014-11-05 182 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重量輕得多。