【发布时间】:2014-02-10 13:20:29
【问题描述】:
我正在维护一个大系统(非常非常大),并发现了它的内存问题。 该系统是一个带有大量 DLL 的单个 EXE,用 C++ 编写,用 VS2008 构建并在 WinXP 上运行。
我使用 Process Explorer (sysinternals) 来观察它的内存使用情况。 我发现虚拟内存(VM)和私有字节(PB)之间的差距越来越大。 刚开始VM略大于PB,随着运行,VM和PB都快速增加。 有时,PB 会降低,但 VM 不会降低。 VM 可以比 PB 大 300MB。
发现VM总是先增大,PB先增大后减小,最后VM快2G了,系统崩溃了。
在我的系统中,没有直接调用任何虚拟内存分配函数,比如VirtualAlloc/VirtualAllocEx,只是使用new/delete/malloc/free/HeapCreate/HeapAlloc来使用内存。
我用windbg调试,用!heap -s显示进程堆的汇总,发现这个堆预留了300多MB的内存,但是只commit了15MB。
在这个输出中,我也发现了一些异常,
Virtual address fragmentation -1340964299% (191 uncommited ranges)
ERROR Cannot read SubSegmentZones list at 79858461
有谁知道为什么虚拟机总是增加?
提前谢谢。
以下是 !heap -s 00170000 的部分输出
!heap -s 00170000
Walking the heap 00170000 ...Verbose mode ON.
.......Virtual block: 26740000 - 26740000 (size 00000000)
Virtual block: 267f0000 - 267f0000 (size 00000000)
0: Heap 00170000
Flags 00000002 - HEAP_GROWABLE
Reserved memory in segments 327680 (k)
Commited memory in segments 15548 (k)
Virtual bytes (correction for large UCR) 884 (k)
Free space 5818 (k) (320 blocks)
External fragmentation 37% (320 free blocks)
Virtual address fragmentation -1340964299% (191 uncommited ranges)
Virtual blocks 2 - total 0 KBytes
Lock contention 4
Segments 10
0 hash table for the free list
Commits 0
Decommitts 0
Low fragmentation heap 15a3c9e0
ERROR Cannot read SubSegmentZones list at 79858461
Metadata usage 3072 bytes
Statistics:
Segments created 0
Segments deleted 0
Segments reused 0
【问题讨论】:
标签: c++ windows-xp virtual-memory