views:

64

answers:

3

Hello I developed a multi-threaded TCP server application that allows 10 concurrent connections receives continuous requests from them, after some processing requests, responds them to clients. I'm running it on a TI OMAP l137 processor based board it runs Monta Vista Linux. Threads are created per client ie 10 threads and it's pre-threaded. it's physical memory usage is about %1.5 and CPU usage is about %2 according to ps, top and meminfo. It's vm usage rises up to 80M where i have 48M (i reduced it from u-boot to reserve some mem for DSP). Any help is appreciated, how can i reduce it??.(/proc/sys/vm/.. tricks doesn't help :)

Thanks.

A: 

Does it rise to that level and stay there? Or does it eventually run out of memory? If the former, you simply need to figure out a way to have a smaller working set. If the latter, you have a memory leak and need to fix it.

Amardeep
It stays there and works good for a day time but after 48 hours it was killed by a magical force, which i could not find any clue of. dmesg, and the other logs are clean the process is just ended.
yet
I'd wager that 'magical force' was your memory leak causing your application to exhaust its heap.
Amardeep
thanks btw, if it's killed by OOM-Killer where can i find the logs? as i said it's like a magical hand that stops it. (i double checked the logins :)
yet
Which language? If C then check each malloc()'s return value and if NULL you should log it. If C++ then make sure you are using new (nothrow) then do the same. Otherwise put try...catch around each new and log the allocation failure in either case.
Amardeep
@Amardeep it's ANSI C, i ll check 'errno' but i think, the thing you said, leads to memory corruption and segmentation faults not a mem leakage.
yet
+1  A: 

Most VM is probably just for stacks. Of course, it's virtual, so it doesn't get commited if you don't use it.

(I'm wondering if thread's default stack size has anything to do with ulimit -s)

Apparently yes, according to this other SO question

ninjalj
yes ulimit verboses that it is unlimited, i tried it this morning it did not help, i ll try to set some thread specific limitation.
yet
+1  A: 

You can try using a drop in garbage collecting replacement for malloc(), and see if that solves your problem. If it does, find the leaks and fix them, then get rid of the garbage collector.

Its 'interesting' to chase these kinds of problems on platforms that most heap analyzers and profilers (e.g. valgrind) don't fully (if at all) support.

On another note, given the constraints .. I'm assuming you have decreased the default thread stack size? I think the default is 8M, you probably don't need that much. See pthread_attr_setstacksize() if you haven't adjusted it.

Edit:

You can check the default stack size with pthread_attr_getstacksize(). If it is at 8M, you've already blown your ceiling during thread creation (10 threads, as you mentioned).

Tim Post
ulimit doesnt help i will try pthread_attr_setstacksize() i think it's at default values, if it is not set by kernel configuration.
yet
@yet , then each thread probably has either a 4 or 8 MB stack. You can check with pthread_attr_getstacksize() to see the default.
Tim Post
@Tim Post, thanks! virtual memory usage is fine now,it worked thank you.
yet