[英]malloc returns null when run with Valgrind
我有一個巨大的分配(數十GB)與malloc調用發生在正常情況下工作。 系統確實有一個巨大的RAM,是一台運行2.6 x86_64內核的64位機器。
mem rlimit已作為INFINITY以setrlimit完成。
我想用Valgrind運行它來進行內存分析並檢查泄漏情況。
但是當使用valgrind運行時,malloc失敗並返回NULL指針。
我嘗試減少分配的大小,但這沒有幫助。
有什么投入?
問候,-J
請注意, malloc(3)
對你說謊 - 它實際上並不是一次性分配所有內存,它只是向操作系統詢問它,操作系統位於malloc(3)
。 這是完全正常的行為,大部分時間都可以正常工作。 proc(5)
中/proc/sys/vm/overcommit_memory
的描述包含以下內容:
/proc/sys/vm/overcommit_memory
This file contains the kernel virtual memory
accounting mode. Values are:
0: heuristic overcommit (this is the default)
1: always overcommit, never check
2: always check, never overcommit
In mode 0, calls of mmap(2) with MAP_NORESERVE are not
checked, and the default check is very weak, leading
to the risk of getting a process "OOM-killed". Under
Linux 2.4 any nonzero value implies mode 1. In mode 2
(available since Linux 2.6), the total virtual address
space on the system is limited to (SS + RAM*(r/100)),
where SS is the size of the swap space, and RAM is the
size of the physical memory, and r is the contents of
the file /proc/sys/vm/overcommit_ratio.
Valgrind不能那么輕率; 它實際上跟蹤進程的已分配,已初始化和未初始化的內存。 因此,它需要比進程本身更多的內存,並且它對過度提交的內存沒有相同的容忍度。
我不知道在valgrind下運行程序需要多少內存,但是嘗試添加幾個千兆字節的交換空間。 您可以使用dd
將零寫入文件來創建一個新的交換文件 - 不要使用稀疏文件 - 然后在文件上運行mkswap(8)
以初始化它並運行帶文件名的swapon(8)
來告訴系統將其用作交換文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.