-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Monitoring malloc usage #20363
Monitoring malloc usage #20363
Conversation
Cool! I'm almost certain that some standard c libs (looking avrlibc) do not have mallinfo anyway, so this would be a solution to add this globally. What would also be quite useful is adding a backtrace to
I found that quite useful to trace down a call to But I guess it can still be useful to resort to highest output verbosity in some cases and the implementation is pretty low-key to maintain, so I guess it could just remain. Maybe just rename that to
This is correct. What On |
Thanks for the feedback! I will then go forward and clean this up.
With backtrace you mean basically the same type of print that is used in
If we want to have the option of high verbosity, I would rather offer a configuration option for the new module and integrate the prints there behind a compile-time flag. I would suppose that a configuration option for a module is nicer for the user than having to deal with two different (pseudo)modules. I would have proposed
Are there any more boards where |
eb6c0f6
to
916a4fa
Compare
This is now ready for review. The module As discussed, |
916a4fa
to
6311d55
Compare
The murdock failure for native64:llvm is apparently only a single example of all boards with It seems the wrapping functions for malloc and friends are not properly handled by clang, which however also means that the thread-safety wrappers are ignored by that toolchain. Interestingly, |
I have to correct myself, it was a case of the compiler being smarter than the human again :P Since the memory returned by malloc was never used, all calls to malloc and free where just silently optimized away. Fixed that now by declaring the memory as volatile for the sake of the test. |
Yeah, we had a test for |
Unfortunately I can't reproduce this locally. What's the doxygen version that's used in the CI? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks in general good to me. One open issue I see is synchronization to avoid data races when accessing the monitor data.
On the malloc()
side, we do already have a mutex
called. However, a badly timed malloc_monitor_reset_high_watermark()
would result in data corruption, even on systems where writing to malloc_monitor.high_watermark
would be an atomic operation.
Thanks for the review!
Very good point o.O, thanks for pointing it out! Addressed with c5b3528, please have a look :) |
4f2a3c9
to
f31f820
Compare
Thank you! |
This is still far from ready to be merged, but before investing more time into it I would like to gather some feedback, see below.
Contribution description
This is a first attempt of a malloc monitoring implementation that is meant to be used for debugging purposes when working with (libraries that make use of) malloc and friends. Compared to the
MALLOC_TRACING
module already available in RIOT, this is not designed to print the calls to stdout, but to keep track of the amount of memory that is currently dynamically allocated, as well as the all-time max. I was using this while playing with uzlib in #20293.Discussion points
mallinfo()
but that didn't report the all-time max correctly.sys/malloc_thread_safe
which is afaik not used on all boards, and definitely not onnative
. Is there a list somewhere that shows which boards use which malloc implementation? Would it make sense to hook into all of them?MALLOC_TRACING
to stay around or should it be removed in favor of this implementation? Pinging@benpicco@maribu here since this was originally his contribution.Testing procedure
None yet.Test provided in
tests/sys/malloc_monitor
.