Skip to content
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

Towards heap walk #569

Merged
merged 16 commits into from
Dec 20, 2022
Merged

Towards heap walk #569

merged 16 commits into from
Dec 20, 2022

Conversation

mjp41
Copy link
Member

@mjp41 mjp41 commented Oct 31, 2022

This includes a two changes that are on the way to implementing heap walk. The changes performed are:

  • Track the laden ranges of memory: the full and almost full slabs and large allocations.
  • Ensure each slab metadata knows what range of memory it is describing. This was not previously the case for a fully used slab where there is no free list.

@SchrodingerZhu
Copy link
Contributor

Will we finally reach precise heap allocation statistics?

@mjp41
Copy link
Member Author

mjp41 commented Nov 1, 2022

Will we finally reach precise heap allocation statistics?

This is not aimed at better statistics. We could add that, but it is not on my current plan. My rough thought would be to track per sizeclass

sizeclass | total allocations | curr slabs | max slabs

The total allocations would be bumped everytime we grab a new free list, and curr slabs and max slabs would be increased on alloc_chunk and decreased on dealloc_chunk. This could then be done just with interlocked instructions on global state as it would be sufficiently infrequent to not cost too much. It wouldn't track fragmentation though, which might be a useful thing to track.

@mjp41
Copy link
Member Author

mjp41 commented Nov 1, 2022

This last commit 9042b40 is my attempt to get the fix passed the CHERI compiler. We won't really be using this value, except to look up in the pagemap, but changing all the types in freelist::Object to have a union with address_t seems painful. @nwf-msr do you have any thoughts on what the correct approach is?

src/snmalloc/mem/freelist.h Outdated Show resolved Hide resolved
This adds an additional SeqSet that is used to track all the fully
used slabs and large allocations.  This gives more chances to
detect memory leaks, and additionally catch some more UAF failures
where the object is not recycled.
Use the head of the free list builder to track an interior pointer to
the slab. This is unused unless the list contains something.
Hence, we can use this to represent an interior pointer to the slab and
report more accurate leaks.
Add an operation to get a tag free pointer from an address_t, and use it
src/snmalloc/mem/freelist.h Outdated Show resolved Hide resolved
src/test/func/statistics/stats.cc Outdated Show resolved Hide resolved
src/snmalloc/aal/address.h Outdated Show resolved Hide resolved
Copy link
Contributor

@nwf-msr nwf-msr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mjp41 mjp41 merged commit 4e88b42 into microsoft:main Dec 20, 2022
@mjp41 mjp41 deleted the better_checks branch December 20, 2022 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants