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

Implement a custom allocator to provide detailed memory usage info during compilation #59571

Open
wesleywiser opened this issue Mar 30, 2019 · 4 comments
Labels
A-self-profile Area: Self-profiling feature of the compiler C-feature-request Category: A feature request, i.e: not implemented / a PR. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@wesleywiser
Copy link
Member

Idea from @eddyb:

It would be great if we could measure the memory used by the compiler during compilation in a very fine-grained way. One idea to do this would be to implement a custom allocator which could record statistics for memory allocated and deallocated. This allocator could also be integrated with rustc's arenas so that we could see exactly how much memory is used by each arena at any given instant.

@jonas-schievink jonas-schievink added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. labels Mar 30, 2019
@eddyb
Copy link
Member

eddyb commented Mar 30, 2019

The allocator doesn't need integration with arenas, but rather self-profiling can refer to either the allocator's (thread-local) counters or to arena counters (which would be even more accurate - basically you can subtract the space not actually used yet in arenas, which could be one counter in tcx, to make profiling faster).

cc @Zoxc @alexcrichton @SimonSapin (I believe there may be similar global allocators out there already, for tracking memory usage, what we need is something very lightweight and thread-local, so that we can accurately quantify how much space each individual query resulted in allocating)

@eddyb eddyb added the A-self-profile Area: Self-profiling feature of the compiler label Mar 30, 2019
@eddyb
Copy link
Member

eddyb commented Mar 31, 2019

cc @anp @Mark-Simulacrum

@sfackler
Copy link
Member

jemalloc already tracks quite a bit of information: http://jemalloc.net/jemalloc.3.html

@eddyb
Copy link
Member

eddyb commented Mar 31, 2019

Yeah, but we want a single per-thread counter, doing it on the Rust side would be cheaper (to read, especially if bare #[thread_local]), and we can make it generic over any GlobalAllocator so it still works even if we want to try out the system allocator.

We don't get to track LLVM allocations this way, but that can be seen as a good thing, since we are more likely to be interested in the rustc memory usage alone.

@Enselic Enselic added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-self-profile Area: Self-profiling feature of the compiler C-feature-request Category: A feature request, i.e: not implemented / a PR. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants