-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
does memleax handle allocations from free list correctly? #37
Comments
There is no such problem in memleax. The new memory block allocation time is set at
and it is used for expiration checking at
When a memory block is freed, the record ( |
Thanks for the reply! Something else must be going on then, because when I run memleax on my application it terminates after reaching the maximum number of expired blocks (1000 blocks older than 60 seconds). However, without memleax the same application is running for several days with perfectly flat memory usage (VIRT & RES) according to top. I was hoping that the discrepancy was caused by malloc returning new allocations from the free list, but it seems that is not the case. Please let me know if you have any thoughts on how to resolve this. Thanks! |
So I've tried a few things to resolve this, so far with no luck. I noticed that memleax was using a lot of CPU when run, so I reduced the load on the target application, to the point where it uses < 2% CPU -- at that load, memleax is running at approx. 2% CPU. Memory utilization of both memleax and the target application is steady at approx. 100-200MB (on a 16GB machine). I also reduced the size of the call stack captured to 10 frames. Even with these settings I am seeing what I am convinced are spurious reports from memleax:
I'm having a hard time understanding how any allocations can live for > 60 seconds if neither memleax nor the target application are using significant CPU or memory. FWIW, the target application simply subscribes to messages sent by a publishing application (using ZeroMQ) and discards each message after processing. As mentioned previously, the same target application has been running for several days at a much higher message rate (100,000 m/s) with flat memory utilization. Any suggestions would be much appreciated - thanks! P.S. I'm running memleax 1.1.1 with the patch from #36. The test machine is running CentOS 6.9 w/4x i5-2400 CPUs and 16GB RAM. |
P.S. I terminated memleax and here's the report it gives:
|
This may be a bug! When memleax works with multi-thread process,
For the your output, most memory block is freed, and in 1 second (
I do not know how to fix it by now. Maybe I could study how GDB does. Thanks for this report. |
memleax may use lots of CPU, if your program call Besides, why do you use memleax if your program seems no memory leak? |
I know the target application "leaks" (grows memory) in other scenarios, so I was trying to establish a baseline with memleax in a scenario where it does not leak before attempting to diagnose the other problem. |
I'm sure you know this, but other memory debuggers work by intercepting malloc, free (etc.) to insert their own code. It sounds like memleax is using self-modifying code, which is definitely going to be a problem in multi-threaded applications (like mine). I'm not sure why memleax needs to delete the breakpoint at entry to free -- would it make sense to have both the entry and exit breakpoint active at all times? Of course, that would mean that memleax would need to use thread-safe data structures, but in order to be usable with multi-threaded apps it would need to do that in any case. You may want to consider adding a note to the README that memleax doesn't necessarily work correctly with multi-threaded apps. If I can come up with anything that would help, I'll be sure to post back here. Thanks again! |
I do not know this in fact :( I just know basic knowledge about debugging from school, and do not know the detail in practice.
memleax just places an INT3 instruction at the entry of free(). When trapping, memleax replace it by the origin instruction to let the target program continue; and re-places the INT3 later. Besides, I do not know how to get the exit address of free(), so I set the breakpoint at the return address actually when trapping into free().
Yes, I have added a note, and post issues. Thanks again! |
FWIW, here's a good writeup on the LD_PRELOAD technique: http://stackoverflow.com/questions/426230/what-is-the-ld-preload-trick This was referenced from another useful post: http://milianw.de/blog/heaptrack-a-heap-memory-profiler-for-linux This could be a more robust technique for hooking malloc etc. esp. for multi-threaded code. |
The |
Thanks for putting this out! I looks to be a very useful adjunct to other tools like valgrind, and covers a scenario that valgrind really doesn't handle very well.
I'm trying to use memleax to diagnose a problem with memory growing over time while a process is running. valgrind reports no leaks at shutdown, but top shows memory increasing steadily until the process is terminated.
But I'm having a problem, and I think it may be that malloc is returning the same block address that was previously freed -- since the address is the same memleax thinks that it exceeds the expire time, when in reality it has just been malloc'd and free'd over and over again.
Do you know if that's possible with memleax? If so, can you help point me to the code in memleax that timestamps the allocation? Perhaps that is not being updated with subsequent allocations after the first?
Thanks again for a terrific tool, and for any help you may be able to provide.
The text was updated successfully, but these errors were encountered: