-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Introduce liballoc::actual_usable_size #32075
Comments
CC @pnkfelix |
... I don't know if we can reliably provide this for all potential allocators ... Would you be willing to make the API more flexible, e.g. have it return |
// In the alloc::heap module
pub unsafe fn usable_size(ptr: *mut u8, size: usize, align: usize) -> usize { ... } Namely, the same information we need to keep track of anyway for |
Since the size returned by |
Okay I'm fine with this as long as it meets the same input requirements as deallocate |
@retep998 You mean return |
The point of this function isn't to return how much space can be used in a give pointer, but about how much space did I need to actually allocate. |
@nox Well in the case of overaligned types it is |
Yeah ok, just checking that we were talking about the same thing. :) |
FWIW early versions of https://github.com/servo/tendril did use |
What can we do to get some progress about this? |
Nominating for @rust-lang/libs discussion so that we can move forward, it seems Servo wants this. |
The libs team discussed this during triage today and now that we have global allocators on the horizon such a feature is likely best implemented through a known allocator which can then be used to, for example, codify the implementation above as "correct". In light of that, I'm going to close this issue as we're unlikely to add such a method like this to the |
The implementation above is a very fragile hack. The point of this request is that it would not be needed anymore. I may be missing a step in the reasoning how global allocators help here. |
I second what @SimonSapin said, this hack is fragile and makes me wary for the future. This issue and the wish for such a function is only a preliminary step in our quest to correct memory reporting. Once it is in libstd, I would like If global allocators don't help on that, I don't see why I was pinged into that RFC at all. |
Global allocators allow you to define what the global allocator is, turning this from a "hack" into a correct implementation. |
The fragility of this hack is not only "are we using jemalloc at all", it also depends on details of how exactly std links to jemalloc. At some point the symbol name changed from |
And there is still the elephant in the room, which is that if the function isn't in the standard library, then obviously the standard library won't be able to use it for the types it defines. |
Er, ok, let me be clearer.
The point of global allocators is that this is a local problem, not a libstd problem. This code goes in Servo, not in libstd. |
How does defining our own allocator means we can inspect how much memory was allocated for a |
This is how we currently measure how much space a This cannot be done in an exact way from outside the standard library, which means that if we want this feature, we need some sort of |
@nox I fear that there's a lack of communication here. This issue, as stated, I assume is for a function like mentioned above. That function is not necessary to put in liballoc if you can have a custom global allocator. The problem you're mentioning, tracking the precise memory usage of collections in libstd, sounds unrelated to this issue itself and may want its own dedicated issue if it's required. |
So to further clarify:
Does that seem right? |
This is right. I just don't see how getting information about |
@aturon Should I file an issue for getting information about |
In Servo we use heapsize to be able to report about heap memory usage. It would be way more robust if heapsize's function
heap_size_of
were in liballoc itself.Probably that function should be parameterised by
T
instead of taking a*mut c_void
, to handle alignment without relying onHeapValidate
on Windows.The text was updated successfully, but these errors were encountered: