Question

We have a multi-threaded client - server project, we recently upgraded the server side applications on 64 - bit architecture. Solved many problems, our application now works steadily week under a heavy load. But after this period, the application on the server crashes with "Out of memory" error. At this time, free memory is available in large quantities, it seems that the problem of memory fragmentation. Is there any possibility to defragment memory, some tools? Or may be some other reasons "Out of memory" in a similar situation?

Memory allocation:

  1. Total amount of memory : 96Gb
  2. Physical : 48Gb
  3. Virtual : 48Gb
  4. The amount of free physical memory at the time of the collapse : 3GB
  5. The amount of free virtual memory at the time of collapse : 45Gb
  6. Maximum size of memory allocated per thread : 1GB
Was it helpful?

Solution

As you have surmised, your problem is fragmentation. There's nothing you can do to defragment memory--any tool that would attempt to do so would have to have a complete map of every pointer in your program. Note that even .NET's garbage collector can't accomplish this with the large object heap, I have crashed a 32-bit net application with only 100mb actually used.

Instead, what you need to do is avoid the fragmentation in the first place. Generally that means object pools, saving old objects for reuse rather than freeing them and later reallocating them.

OTHER TIPS

Another option (if the service isn't time critical and needs to be online 100% of every second) is to restart your service every 24 hours or so (either via the task scheduler or from within your own program).

If from within your own program, you can do it in one of two ways, depending on what type of service you have (if there can exist two instances of your service at the very same - brief - time):

1) Execute a second instance of your service from within your currently running service and then terminate
2) Execute a tiny helper program that waits f.ex. 5 seconds and then (re)starts your service, then terminate your currently running service

But the best way would be to avoid the fragmentation in the first place, as Loren Pechtel writes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top