aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-08-14 06:41:58 -0600
committerbors-servo <metajack+bors@gmail.com>2015-08-14 06:41:58 -0600
commit38c5fb80d3c6c0e08732f5bdb3f0e9f9bf192def (patch)
tree328815283ede70db804fc940d32b75e28d2552d8
parent85022a4c347dca3f5d28cec3010f7e9410217df4 (diff)
parent77fadb7054abd60e1caf873a13c5a29be7f353ca (diff)
downloadservo-38c5fb80d3c6c0e08732f5bdb3f0e9f9bf192def.tar.gz
servo-38c5fb80d3c6c0e08732f5bdb3f0e9f9bf192def.zip
Auto merge of #7213 - nnethercote:tweak-system-heap-allocated, r=Ms2ger
Tweak how the "system-heap-allocated" memory report is gathered. To handle potential overflow because mallinfo() is ancient. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7213) <!-- Reviewable:end -->
-rw-r--r--components/profile/mem.rs23
1 files changed, 15 insertions, 8 deletions
diff --git a/components/profile/mem.rs b/components/profile/mem.rs
index b04ced9905a..598acfb04e8 100644
--- a/components/profile/mem.rs
+++ b/components/profile/mem.rs
@@ -440,14 +440,21 @@ mod system_reporter {
#[cfg(target_os="linux")]
fn get_system_heap_allocated() -> Option<usize> {
- let info: struct_mallinfo = unsafe {
- mallinfo()
- };
- // The documentation in the glibc man page makes it sound like |uordblks|
- // would suffice, but that only gets the small allocations that are put in
- // the brk heap. We need |hblkhd| as well to get the larger allocations
- // that are mmapped.
- Some((info.hblkhd + info.uordblks) as usize)
+ let info: struct_mallinfo = unsafe { mallinfo() };
+
+ // The documentation in the glibc man page makes it sound like |uordblks| would suffice,
+ // but that only gets the small allocations that are put in 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
+ // 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"))]