mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Tweak how the "system-heap-allocated" memory report is gathered.
This commit is contained in:
parent
a35360aa31
commit
77fadb7054
1 changed files with 15 additions and 8 deletions
|
@ -440,14 +440,21 @@ mod system_reporter {
|
||||||
|
|
||||||
#[cfg(target_os="linux")]
|
#[cfg(target_os="linux")]
|
||||||
fn get_system_heap_allocated() -> Option<usize> {
|
fn get_system_heap_allocated() -> Option<usize> {
|
||||||
let info: struct_mallinfo = unsafe {
|
let info: struct_mallinfo = unsafe { mallinfo() };
|
||||||
mallinfo()
|
|
||||||
};
|
// The documentation in the glibc man page makes it sound like |uordblks| would suffice,
|
||||||
// The documentation in the glibc man page makes it sound like |uordblks|
|
// but that only gets the small allocations that are put in the brk heap. We need |hblkhd|
|
||||||
// would suffice, but that only gets the small allocations that are put in
|
// as well to get the larger allocations that are mmapped.
|
||||||
// the brk heap. We need |hblkhd| as well to get the larger allocations
|
//
|
||||||
// that are mmapped.
|
// These fields are unfortunately |int| and so can overflow (becoming negative) if memory
|
||||||
Some((info.hblkhd + info.uordblks) as usize)
|
// usage gets high enough. So don't report anything in that case. In the non-overflow case
|
||||||
|
// we cast the two values to usize before adding them to make sure the sum also doesn't
|
||||||
|
// overflow.
|
||||||
|
if info.hblkhd < 0 || info.uordblks < 0 {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(info.hblkhd as usize + info.uordblks as usize)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os="linux"))]
|
#[cfg(not(target_os="linux"))]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue