pleriche / FastMM5

FastMM is a fast replacement memory manager for Embarcadero Delphi applications that scales well across multiple threads and CPU cores, is not prone to memory fragmentation, and supports shared memory without the use of external .DLL files.
283 stars 73 forks source link

Medium blocs are never released even with FastMM_SetOptimizationStrategy (mmosOptimizeForLowMemoryUsage) #27

Closed mterrisse closed 2 years ago

mterrisse commented 2 years ago

Hello,

We have noticed that our server applications consume much memory and never release it to the system. The system is running low virtual memory durably and ends up crashing. In detail they get much memory from medium and large blocs and release them, but OS_FreeVirtualMemory is never called for medium blocs. For medium blocs, OS_FreeVirtualMemory is called only at the end of the application in FastMM_FreeAllMemory. Just before we enter FastMM_FreeAllMemory the memory is very high, after FastMM_FreeAllMemory it is very low. So we tried FastMM_SetOptimizationStrategy (mmosOptimizeForLowMemoryUsage), but it doesn't change anything. If we set a breakpoint in FastMM_FreeMem_InternalFreeMediumBlock_ManagerAlreadyLocked where OS_FreeVirtualMemory is called, we notice that it is never called. Did we miss something? Is there anything else we should set than the optimization strategy?

Regards,

Michel Terrisse

pleriche commented 2 years ago

Hi Michel,

If FastMM is not releasing address space back the the OS, then the first thing I would check is whether it is not perhaps running in debug mode. What is the result of the FastMM_DebugModeActive call?

Pierre

mterrisse commented 2 years ago

Hello,

FastMM_DebugModeActive() returns False.

I am trying to build a sample project to help reproducing ithe problem. I will post it here when it is ready. It seams to me that you don't need to have many threads to reproduce it, I have a mono-threaded application that keeps much memory until FastMM_FreeAllMemory.

Regards,

Michel Terrisse

pleriche commented 2 years ago

Do you see this behaviour with the default memory manager or FastMM4 as well? If not, that's quite odd.

A test case will be very helpful. If it is too big to post here you're welcome to e-mail it to me directly as well. Thanks.

mterrisse commented 2 years ago

Hello,

We have run many tests with one of our applications (a web server) and we have noticed this:

So even though we can't figure how it works, FastMM behaves as expected and there is no bug here. You can close this ticket, sorry for the inconvenience.

Regards,

Michel Terrisse

pleriche commented 2 years ago

Thank you for the feedback. I'll close the ticket.