c++ - How to solve Memory Fragmentation -
we've been getting problems whereby our long-running server processes (running on windows server 2003) have thrown exception due memory allocation failure. our suspicion these allocations failing due memory fragmentation.
therefore, we've been looking @ alternative memory allocation mechanisms may , i'm hoping can tell me best one:
1) use windows low-fragmentation heap
2) jemalloc - used in firefox 3
3) doug lea's malloc
our server process developed using cross-platform c++ code, solution ideally cross-platform (do *nix operating systems suffer type of memory fragmentation?).
also, right in thinking lfh default memory allocation mechanism windows server 2008 / vista?... current problems "go away" if our customers upgrade server os?
first, agree other posters suggested resource leak. want rule out first.
hopefully, heap manager using has way dump out actual total free space available in heap (across free blocks) , total number of blocks divided over. if average free block size relatively small compared total free space in heap, have fragmentation problem. alternatively, if can dump size of largest free block , compare total free space, accomplish same thing. largest free block small relative total free space available across blocks if running fragmentation.
to clear above, in cases talking free blocks in heap, not allocated blocks in heap. in case, if above conditions not met, do have leak situation of sort.
so, once have ruled out leak, consider using better allocator. doug lea's malloc suggested in question allocator general use applications , robust most of time. put way, has been time tested work application. however, no algorithm ideal all applications , management algorithm approach can broken right pathelogical conditions against it's design.
why having fragmentation problem? - sources of fragmentation problems caused behavior of application , have different allocation lifetimes in same memory arena. is, objects allocated , freed regularly while other types of objects persist extended periods of time in same heap.....think of longer lifetime ones poking holes larger areas of arena , thereby preventing coalesce of adjacent blocks have been freed.
to address type of problem, best thing can logically divide heap sub arenas lifetimes more similar. in effect, want transient heap , persistent heap or heaps group things of similar lifetimes.
some others have suggested approach solve problem attempt make allocation sizes more similar or identical, less ideal because creates different type of fragmentation called internal fragmentation - in effect wasted space have allocating more memory in block need.
additionally, heap allocator, doug lea's, making block sizes more similar unnecessary because allocator doing power of 2 size bucketing scheme make unnecessary artificially adjust allocation sizes passed malloc() - in effect, heap manager automatically more robustly application able make adjustments.
Comments
Post a Comment