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

Capability to check metrics (free space, used, blocks occupied) #1

Open
timblakely opened this issue Sep 2, 2021 · 2 comments
Open
Labels
enhancement New feature or request

Comments

@timblakely
Copy link

Heya!

Got this working on a cortex-m embedded system with the global allocator. It'd be really helpful to have some metrics to know how much is used, fragmentation wastage, etc. Regardless, thanks for the implementation! Works great so far 👍

@yvt
Copy link
Owner

yvt commented Oct 12, 2021

Hi, sorry for the late response. I have been working on a block enumeration API in the feat-inspection branch. It provides Tlsf::iter_blocks, which returns an iterator over blocks in a specified pool (a contiguous memory block added by insert_free_block_ptr). Does this look good for your use case?

It requires specifying a pool manually because Tlsf doesn't track information about inserted pools at all (it only knows about free memory blocks). It doesn't support inspecting the pools inserted by insert_free_block (the method that takes &mut [_] in lieu of *mut [_]) because I'm uncertain whether it can be done safely under the Stacked Borrows model.

@yvt yvt added the enhancement New feature or request label Oct 12, 2021
@timblakely
Copy link
Author

No worries at all, thanks for looking into this!

Yup, looks like that iterator would do the trick. My use case is primarily monitoring how much space is actually available to allocate, which if I understand the Tlsf algorithm correctly is effectively block occupancy (I think? :). Looks like using that branch I can combine is_occupied and max_payload_size to get an upper bound for both available memory and an upper bound for memory allocated (where mem_allocated + mem_available <= total_mem_in_blocks due to overhead and not-completely-filled blocks).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants