-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix heap stats overhead_size calculation #13486
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
Fix heap stats overhead_size calculation #13486
Conversation
if (c->size < 0) { | ||
c = (malloc_internal_overhead_t *)((char *)c + c->size); | ||
} | ||
return (c->size & ~0x1); |
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.
I am not sure why & ~0x1
is required.
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.
When using the newlib, overhead size (total allocated block size + size of overhead) value always size + 1
(Bug in newlib malloc implementation) so added a workaround size & ~0x1
logic as memory allocation is always aligned with 8 bytes block. Even this logic was there on existing code https://github.com/ARMmbed/mbed-os/blob/master/platform/source/mbed_alloc_wrappers.cpp#L61 .
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.
I think that the LSB is used for usage flags so we have to mask it.
75aaa5b
to
f10c97e
Compare
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.
Can you provide a generic solution for all toolchains?
f10c97e
to
ec2ca2e
Compare
ec2ca2e
to
f3c9132
Compare
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 good
@0xc0170 Could you review this PR and start the CI |
CI started |
Jenkins CI Test : ✔️ SUCCESSBuild Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
@0xc0170 Thanks for your review. This PR is ready to merge, please merge |
Summary of changes
overhead_size
heap stats element was added to maintain real malloc internal overhead size but Mbed OS assumes that( malloc returned address - 4 )
stores the actual allocated block size( including internal overhead size), but GCC_ARM newlib and newlib nano this location is used for padding when non-alignment memory allocation requested and it stores the negative offset.So updated Mbed OS allocated block size calculation like when reading from
( malloc returned address - 4 )
is non-negative value consider to be an allocated block size. If it is a negative value ( offset ), then add this negative value into(malloc returned address - 4 )
and read the allocated block size from that location.Fixes #13324
Impact of changes
With these changes, Mbed OS
overhead_size
reports proper malloc internal overhead size when using GCC_ARM with newlib-nanoMigration actions required
None.
Documentation
None.
Pull request type
Test results
Reviewers
@evedon