Question

I have a server that implemented in C++ running on a Windows 2003 enterprise with 25GB RAM.

During a stress test, I see when it is trying to create a new thread by calling _beginthread, I got ENOMEM which means "Not enough memory".

But I don't understand why it is out of memory, perfmon data shows that at that time, the process has used 1.2GB VM and similar physical memory, there are only 250 threads.

Can anyone help me to analyse or explain why I still got this error?

Was it helpful?

Solution 3

It ended up because of a memory leak in our application.

OTHER TIPS

A thread typically requires 1 MB of unfragmented address space. If your stress test has fragmented memory to the point where no 1 MB stretches are available, you wouldn't be able to create any new threads. This can be achieved by as little as 2000 allocations of one byte each, in the worst case.

A typical 32-bit application would run out of (virtual) memory after creating a bit less than 2048 threads. By default every thread reserves 1MB of contiguous virtual address space, so that 2048 threads would need 2GB of virtual memory. This is the maximum a 32-bit process may consume in user mode.

P.S. There's an option (at least on Windows) to configure OS to reserve up to 3GB of virtual address space in the user-mode.

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