-
Notifications
You must be signed in to change notification settings - Fork 754
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
[memory] session memory usage #1148
Comments
fyi, custom allocator for tracing memory usage: use std::alloc::System;
use std::alloc::{GlobalAlloc, Layout};
use std::sync::atomic::{AtomicU64, Ordering};
pub struct Trallocator(System, AtomicU64, AtomicU64);
unsafe impl GlobalAlloc for Trallocator {
unsafe fn alloc(&self, l: Layout) -> *mut u8 {
self.1.fetch_add(l.size() as u64, Ordering::SeqCst);
self.2.fetch_add(l.size() as u64, Ordering::SeqCst);
self.0.alloc(l)
}
unsafe fn dealloc(&self, ptr: *mut u8, l: Layout) {
self.0.dealloc(ptr, l);
self.1.fetch_sub(l.size() as u64, Ordering::SeqCst);
}
}
impl Trallocator {
pub const fn new(s: System) -> Self {
Trallocator(s, AtomicU64::new(0), AtomicU64::new(0))
}
pub fn reset(&self) {
self.1.store(0, Ordering::SeqCst);
self.2.store(0, Ordering::SeqCst);
}
pub fn get(&self) -> u64 {
self.1.load(Ordering::SeqCst)
}
pub fn get_sum(&self) -> u64 {
self.2.load(Ordering::SeqCst)
}
} |
/assignme |
@BohuTANG @PsiACE
let allocator = MyAllocator::new(System); // which implement `std::alloc::Allocator` trait
let session = Box::new_in(Session::try_create(...), allocator); // compile error ❌ but for now, the box So, I think now this way is not going to be okay for this issue. btw, I check it that we can use constom allocator for let allocator = MyAllocator::new(System); // which implement `std::alloc::Allocator` trait
let mut item: Vec<String, Trallocator> = Vec::new_in(allocator); // it works ok ✅ |
Thank you @Veeupup for the work. |
@Veeupup |
Thanks for guiding, I will try to learn something from it. |
@BohuTANG hi, I have figured it that servo use And now I encountered a problem that I'm not very clear about what session memory usage exactly means.
|
I guess here we only tracking the session object(malloc_size_of(&session)) is ok, but not sure it works or not, have found some useful tests: In this example, it can track a more complex struct |
Summary
Use rust custom allocator trait to track the session memory usage.
The text was updated successfully, but these errors were encountered: