Ve/alloc count#125
Open
vladimir-ea wants to merge 9 commits into
Open
Conversation
vladimir-ea
commented
Jun 26, 2026
| static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; | ||
| // #[cfg(not(feature = "alloc-profile"))] | ||
| // #[global_allocator] | ||
| // static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; |
Collaborator
Author
There was a problem hiding this comment.
changed to using CountingAllocator in this PR - possibly counting allocator should be put behind a feature flag ..
b55abe3 to
c988875
Compare
alexX512
reviewed
Jun 26, 2026
| /// `init` / `init_with_base` force the map early (and let tests redirect the | ||
| /// base dir) for the calling thread only. | ||
| #[macro_export] | ||
| macro_rules! declare_thread_counters { |
Contributor
There was a problem hiding this comment.
Do we need that big macro? It feels like for our use case we can use small counter in shared memory with specific file name like in allocator file
const BYTES: usize = std::mem::size_of::<AtomicI64>();
thread_local! {
static BASE: Cell<*mut AtomicI64> = const { Cell::new(null_mut()) };
}
#[inline]
fn cell() -> &'static AtomicI64 {
let p = BASE.with(|c| {
let p = c.get();
if !p.is_null() {
return p;
}
let p = map_this_thread();
c.set(p);
p
});
unsafe { &*p }
}
#[cold]
fn map_this_thread() -> *mut AtomicI64 {
let t = std::thread::current();
let file = match t.name() {
Some(n) => format!("{n}_allocator"),
None => format!("{:?}_allocator", t.id()),
};
mmap_counters_file(local_share_dir().as_ref(), "silver", &file, BYTES)
.map(|p| p.cast::<AtomicI64>())
.expect("alloc counter mmap")
}
pub fn add(n: i64) { cell().fetch_add(n, Relaxed); }
pub fn sub(n: i64) { cell().fetch_sub(n, Relaxed); }
pub fn get() -> i64 { cell().load(Relaxed) }
alexX512
reviewed
Jun 26, 2026
| x + 1 | ||
| } | ||
|
|
||
| #[timed("timed_sampled_label", sample = 1000)] |
Contributor
There was a problem hiding this comment.
Sampled label was removed from timed macro as we never used it in prod and with it it might be hard to analyse results as in flamegraphs we track how many time a function was called
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
add a counting allocator with per thread counters exported to surfer